Skip to content

Instantly share code, notes, and snippets.

@JuniorDjjr
Created November 2, 2022 06:12
Show Gist options
  • Save JuniorDjjr/6e7a1427d4dd4685b2b9e0603296da4d to your computer and use it in GitHub Desktop.
Save JuniorDjjr/6e7a1427d4dd4685b2b9e0603296da4d to your computer and use it in GitHub Desktop.
// by Junior_Djjr - MixMods.com.br
// You need: https://forum.mixmods.com.br/f141-gta3script-cleo/t5206-como-criar-scripts-com-cleoplus
SCRIPT_START
{
LVAR_INT lList iPlayerId scplayer pLaddersArray i iFrontInput bWaitForInput bLastIsUp bLadderBotToTop iCurLadder pCurLadder iSizeEachLadder iTotalLadders
LVAR_FLOAT fAnimTime fAnimSpeed fAddAnimSpeed fMoveSpeed f x y z
LVAR_FLOAT fCfgBotX fCfgBotY fCfgBotZ fCfgBotMargin fCfgTopX fCfgTopY fCfgTopZ fCfgTopMargin fCfgAngle fCfgMoveSpeed
CONST_INT LADDER_PARAM_BOTTOM_X 0
CONST_INT LADDER_PARAM_BOTTOM_Y 1
CONST_INT LADDER_PARAM_BOTTOM_Z 2
CONST_INT LADDER_PARAM_BOTTOM_MARGIN 3
CONST_INT LADDER_PARAM_TOP_X 4
CONST_INT LADDER_PARAM_TOP_Y 5
CONST_INT LADDER_PARAM_TOP_Z 6
CONST_INT LADDER_PARAM_TOP_MARGIN 7
CONST_INT LADDER_PARAM_ANGLE 8
CONST_INT LADDER_PARAM_MOVE_SPEED 9
CONST_INT LADDER_PARAM_TOTAL 10
SCRIPT_NAME LADDERS
CREATE_LIST DATATYPE_INT (lList)
WAIT 0
WAIT 0 // give time to other scripts add ladders
WAIT 500
IF iPlayerId = 0
STREAM_CUSTOM_SCRIPT_FROM_LABEL Start lList iPlayerId
CLEO_CALL LoadIni 0 (lList)(pLaddersArray)
ENDIF
Start:
//SET_CHAR_COORDINATES scplayer -1361.1139 -699.0563 1.9609
//SET_CHAR_COORDINATES scplayer -2327.7239 1525.9205 0.1038
//SET_CHAR_COORDINATES scplayer -1357.1019 -2377.5803 33.9159
//SET_CHAR_HEADING scplayer 0.0
WHILE TRUE
WAIT 0
IF iPlayerId = 1
AND NOT IS_2PLAYER_GAME_GOING_ON
CONTINUE
ENDIF
GET_PLAYER_CHAR iPlayerId (scplayer)
IF iPlayerId = 0
IF TEST_CHEAT LADDERSRELOAD
FREE_MEMORY pLaddersArray
RESET_LIST lList
CLEO_CALL LoadIni 0 (lList)(pLaddersArray)
PRINT_STRING_NOW "~y~Ladders Mod: .ini reloaded." 1000
ENDIF
ENDIF
/*IF IS_KEY_JUST_PRESSED VK_KEY_R
SET_CHAR_COORDINATES_SIMPLE scplayer -1361.0435 -696.9363 1.9609
SET_CHAR_HEADING scplayer 0.0
ENDIF*/
IF GOSUB IsOkToStart
GET_LIST_SIZE lList (iTotalLadders)
//PRINT_FORMATTED_NOW "total ladders %i" 100 iTotalLadders
iCurLadder = 0
WHILE iCurLadder < iTotalLadders
GET_LIST_VALUE_BY_INDEX lList iCurLadder (pCurLadder)
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_BOTTOM_X fCfgBotX
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_BOTTOM_Y fCfgBotY
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_BOTTOM_Z fCfgBotZ
IF LOCATE_CHAR_DISTANCE_TO_COORDINATES scplayer fCfgBotX fCfgBotY fCfgBotZ 400.0
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_TOP_X fCfgTopX
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_TOP_Y fCfgTopY
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_TOP_Z fCfgTopZ
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_ANGLE fCfgAngle
IF LOCATE_CHAR_DISTANCE_TO_COORDINATES scplayer fCfgBotX fCfgBotY fCfgBotZ 1.2
IF CLEO_CALL CheckCharAngleSimilar 0 (scplayer fCfgAngle 0)
bLadderBotToTop = TRUE
GOSUB ProcessLadder
ENDIF
ELSE
IF LOCATE_CHAR_DISTANCE_TO_COORDINATES scplayer fCfgTopX fCfgTopY fCfgTopZ 1.2
IF CLEO_CALL CheckCharAngleSimilar 0 (scplayer fCfgAngle 1)
bLadderBotToTop = FALSE
GOSUB ProcessLadder
ENDIF
ENDIF
IF LOCATE_CHAR_DISTANCE_TO_COORDINATES scplayer fCfgBotX fCfgBotY fCfgTopZ 1.2
IF CLEO_CALL CheckCharAngleSimilar 0 (scplayer fCfgAngle 1)
bLadderBotToTop = FALSE
GOSUB ProcessLadder
ENDIF
ENDIF
ENDIF
ENDIF
++iCurLadder
ENDWHILE
ENDIF
ENDWHILE
IsOkToStart:
IF IS_PLAYER_CONTROL_ON scplayer
GET_CHAR_SPEED scplayer f
IF f > 7.0
RETURN_FALSE
RETURN
ENDIF
IF IS_CHAR_DOING_ANY_IMPORTANT_TASK scplayer INCLUDE_ANIMS_NONE
// important task exceptions
IF IS_CHAR_DOING_TASK_ID scplayer TASK_SIMPLE_JUMP
RETURN_TRUE
RETURN
ENDIF
ENDIF
RETURN_TRUE
RETURN
ENDIF
RETURN_FALSE
RETURN
ProcessLadder:
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_BOTTOM_MARGIN fCfgBotMargin
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_TOP_MARGIN fCfgTopMargin
READ_STRUCT_PARAM pCurLadder LADDER_PARAM_MOVE_SPEED fCfgMoveSpeed
SET_PLAYER_CONTROL_PAD_MOVEMENT iPlayerId OFF
FREEZE_CHAR_POSITION scplayer ON
REQUEST_ANIMATION ladders_djjr
WHILE NOT HAS_ANIMATION_LOADED ladders_djjr
WAIT 0
ENDWHILE
IF IS_CHAR_DEAD scplayer
GOTO Release
ENDIF
IF bLadderBotToTop = TRUE
CLEO_CALL SlideToCoord 0 (scplayer 0.04 fCfgBotX fCfgBotY fCfgBotZ fCfgAngle)
ELSE
CLEO_CALL SlideToCoord 0 (scplayer 0.04 fCfgTopX fCfgTopY fCfgTopZ fCfgAngle)
ENDIF
IF IS_CHAR_DEAD scplayer
GOTO Release
ENDIF
IF bLadderBotToTop = TRUE
CLEO_CALL SlideToCoordBottom 0 (scplayer fCfgBotX fCfgBotY fCfgBotZ fCfgAngle fCfgBotMargin 1)
bLastIsUp = TRUE
ELSE
CLEO_CALL SlideToCoordTop 0 (scplayer fCfgBotX fCfgBotY fCfgTopX fCfgTopY fCfgTopZ fCfgAngle fCfgTopMargin 0)
bLastIsUp = FALSE
ENDIF
IF IS_CHAR_DEAD scplayer
GOTO Release
ENDIF
TASK_PLAY_ANIM_NON_INTERRUPTABLE scplayer "djjr_ladder_loop" "ladders_djjr" 2.0 FALSE FALSE FALSE TRUE 0
GET_CHAR_COORDINATES scplayer x y z
bWaitForInput = TRUE
fAnimTime = 0.0
WHILE NOT IS_BUTTON_JUST_PRESSED iPlayerId TRIANGLE
WAIT 0
IF IS_CHAR_DEAD scplayer
BREAK
ENDIF
SET_CHAR_ANIM_PLAYING_FLAG scplayer "djjr_ladder_loop" OFF
SET_CHAR_ANIM_CURRENT_TIME scplayer "djjr_ladder_loop" fAnimTime
GET_POSITION_OF_ANALOGUE_STICKS iPlayerId i iFrontInput i i
IF NOT iFrontInput = 0
IF bWaitForInput = TRUE
bWaitForInput = FALSE
ENDIF
iFrontInput *= -1
f = z - fCfgBotZ
IF f < fCfgBotMargin
//DRAW_STRING "Bottom" DRAW_EVENT_AFTER_FADE 100.0 300.0 0.3 0.6 TRUE FONT_SUBTITLES
IF iFrontInput < 0
CLEO_CALL SlideToCoordBottom 0 (scplayer fCfgBotX fCfgBotY fCfgBotZ fCfgAngle fCfgBotMargin 0)
BREAK
ENDIF
ENDIF
f = fCfgTopZ - z
IF f < fCfgTopMargin
//DRAW_STRING "Top" DRAW_EVENT_AFTER_FADE 100.0 300.0 0.3 0.6 TRUE FONT_SUBTITLES
IF iFrontInput > 0
CLEO_CALL SlideToCoordTop 0 (scplayer fCfgBotX fCfgBotY fCfgTopX fCfgTopY fCfgTopZ fCfgAngle fCfgTopMargin 1)
BREAK
ENDIF
ENDIF
ENDIF
IF bWaitForInput = FALSE
fAddAnimSpeed =# iFrontInput
fAddAnimSpeed *= 0.00001
IF NOT iFrontInput = 0
IF iFrontInput > 0
bLastIsUp = TRUE
ELSE
bLastIsUp = FALSE
ENDIF
ENDIF
fAnimSpeed +=@ fAddAnimSpeed
IF bLastIsUp = TRUE
IF fAnimSpeed > 0.03
fAnimSpeed = 0.03
ENDIF
ELSE
fAnimSpeed +=@ fAddAnimSpeed
IF fAnimSpeed < -0.03
fAnimSpeed = -0.03
ENDIF
ENDIF
ENDIF
IF iFrontInput = 0
IF bLastIsUp = TRUE
fAnimSpeed -=@ 0.0015
IF bWaitForInput = TRUE
IF fAnimSpeed < 0.0
fAnimSpeed = 0.0
ENDIF
ELSE
IF fAnimSpeed < 0.015
fAnimSpeed = 0.015
ENDIF
ENDIF
ELSE
fAnimSpeed +=@ 0.0015
IF bWaitForInput = TRUE
IF fAnimSpeed > 0.0
fAnimSpeed = 0.0
ENDIF
ELSE
IF fAnimSpeed > -0.015
fAnimSpeed = -0.015
ENDIF
ENDIF
ENDIF
ENDIF
fMoveSpeed = fAnimSpeed
fMoveSpeed *= fCfgMoveSpeed
z += fMoveSpeed
SET_CHAR_COORDINATES_SIMPLE scplayer x y z
fAnimTime +=@ fAnimSpeed
IF fAnimTime >= 1.0
fAnimTime -= 1.0
IF iFrontInput = 0
bWaitForInput = TRUE
fAnimSpeed = 0.0
ENDIF
ENDIF
IF fAnimTime < 0.0
fAnimTime += 1.0
IF iFrontInput = 0
bWaitForInput = TRUE
fAnimSpeed = 0.0
ENDIF
ENDIF
//PRINT_FORMATTED_NOW "input %i speed %.5f time %.2f wait %i" 1000 iFrontInput fAnimSpeed fAnimTime bWaitForInput
ENDWHILE
WAIT 100
Release:
SET_PLAYER_CONTROL_PAD_MOVEMENT iPlayerId ON
IF NOT IS_CHAR_DEAD scplayer
CLEAR_CHAR_TASKS_IMMEDIATELY scplayer
FREEZE_CHAR_POSITION scplayer OFF
WHILE LOCATE_CHAR_DISTANCE_TO_COORDINATES scplayer fCfgBotX fCfgBotY fCfgBotZ 1.3
WAIT 0
IF IS_CHAR_DEAD scplayer
BREAK
ENDIF
ENDWHILE
ENDIF
REMOVE_ANIMATION ladders_djjr
RETURN
}
SCRIPT_END
{
LVAR_INT lList //In
LVAR_INT i iTotalLadders iSizeEachLadder pLaddersArray pBuffer
LVAR_FLOAT fCfgBotX fCfgBotY fCfgBotZ fCfgBotMargin fCfgTopX fCfgTopY fCfgTopZ fCfgTopMargin fCfgAngle fCfgMoveSpeed
LoadIni:
GET_LABEL_POINTER Buffer (pBuffer)
i = 1
WHILE i <= 999
STRING_FORMAT pBuffer "Ladder%i" i
IF READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "BottomX" (fCfgBotX)
++iTotalLadders
ENDIF
++i
ENDWHILE
iSizeEachLadder = 4 //size of each param
iSizeEachLadder *= LADDER_PARAM_TOTAL
i = iSizeEachLadder * iTotalLadders
ALLOCATE_MEMORY i (pLaddersArray)
i = 1
WHILE i <= iTotalLadders
STRING_FORMAT pBuffer "Ladder%i" i
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "BottomX" (fCfgBotX)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "BottomY" (fCfgBotY)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "BottomZ" (fCfgBotZ)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "BottomMargin" (fCfgBotMargin)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "TopX" (fCfgTopX)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "TopY" (fCfgTopY)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "TopZ" (fCfgTopZ)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "TopMargin" (fCfgTopMargin)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "Angle" (fCfgAngle)
READ_FLOAT_FROM_INI_FILE "CLEO\Ladders.ini" $pBuffer "MoveSpeed" (fCfgMoveSpeed)
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_BOTTOM_X fCfgBotX
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_BOTTOM_Y fCfgBotY
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_BOTTOM_Z fCfgBotZ
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_BOTTOM_MARGIN fCfgBotMargin
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_TOP_X fCfgTopX
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_TOP_Y fCfgTopY
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_TOP_Z fCfgTopZ
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_TOP_MARGIN fCfgTopMargin
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_ANGLE fCfgAngle
WRITE_STRUCT_PARAM pLaddersArray LADDER_PARAM_MOVE_SPEED fCfgMoveSpeed
LIST_ADD lList pLaddersArray
pLaddersArray += iSizeEachLadder
++i
ENDWHILE
CLEO_RETURN 0 (pLaddersArray)
}
{
LVAR_INT hChar //In
LVAR_FLOAT fSpeed fDestX fDestY fDestZ fDestAngle //In
LVAR_FLOAT fOriginX fOriginY fOriginZ fOriginAngle fNewX fNewY fNewZ fNewAngle fProgress fProgressEased
SlideToCoord:
GET_CHAR_COORDINATES hChar (fOriginX fOriginY fOriginZ)
GET_CHAR_HEADING hChar (fOriginAngle)
WHILE fDestAngle < 0.0
fDestAngle += 360.0
ENDWHILE
IF fOriginAngle >= 180.0
fOriginAngle -= 360.0
ENDIF
IF fDestAngle >= 180.0
fDestAngle -= 360.0
ENDIF
fProgress = 0.0
WHILE fProgress < 1.0
WAIT 0
IF IS_CHAR_DEAD hChar
BREAK
ENDIF
EASE fProgress EASE_MODE_QUADRATIC EASE_WAY_INOUT (fProgressEased)
LERP fOriginX fDestX fProgressEased (fNewX)
LERP fOriginY fDestY fProgressEased (fNewY)
LERP fOriginZ fDestZ fProgressEased (fNewZ)
LERP fOriginAngle fDestAngle fProgressEased (fNewAngle)
SET_CHAR_COORDINATES_SIMPLE hChar fNewX fNewY fNewZ
SET_CHAR_HEADING hChar fNewAngle
fProgress +=@ fSpeed
ENDWHILE
CLEO_RETURN 0 ()
}
{
LVAR_INT hChar //In
LVAR_FLOAT fBotX fBotY fBotZ fDestAngle fMargin //In
LVAR_INT bUp //In
LVAR_FLOAT fOriginX fOriginY fOriginZ fOriginAngle fDestX fDestY fDestZ fNewX fNewY fNewZ fNewAngle fProgress fProgressEased fSpeed
SlideToCoordBottom:
fSpeed = 0.016
TASK_PLAY_ANIM_NON_INTERRUPTABLE hChar "djjr_ladder_bot" "ladders_djjr" 2.0 FALSE FALSE FALSE TRUE 0
SET_CHAR_COLLISION hChar OFF
GET_CHAR_COORDINATES hChar (fOriginX fOriginY fOriginZ)
GET_CHAR_HEADING hChar (fOriginAngle)
WHILE fDestAngle < 0.0
fDestAngle += 360.0
ENDWHILE
IF fOriginAngle >= 180.0
fOriginAngle -= 360.0
ENDIF
IF fDestAngle >= 180.0
fDestAngle -= 360.0
ENDIF
IF bUp = TRUE
fProgress = 0.0
fDestX = fBotX
fDestY = fBotY
fDestZ = fBotZ + fMargin
ELSE
fProgress = 1.0
fDestX = fOriginX
fDestY = fOriginY
fDestZ = fOriginZ
fOriginX = fBotX
fOriginY = fBotY
fOriginZ = fBotZ
ENDIF
WHILE TRUE
WAIT 0
IF IS_CHAR_DEAD hChar
BREAK
ENDIF
EASE fProgress EASE_MODE_QUADRATIC EASE_WAY_INOUT (fProgressEased)
LERP fOriginX fDestX fProgressEased (fNewX)
LERP fOriginY fDestY fProgressEased (fNewY)
LERP fOriginZ fDestZ fProgressEased (fNewZ)
LERP fOriginAngle fDestAngle fProgressEased (fNewAngle)
SET_CHAR_COORDINATES_SIMPLE hChar fNewX fNewY fNewZ
SET_CHAR_HEADING hChar fNewAngle
SET_CHAR_ANIM_PLAYING_FLAG hChar "djjr_ladder_bot" OFF
SET_CHAR_ANIM_CURRENT_TIME hChar "djjr_ladder_bot" fProgressEased
IF bUp = TRUE
fProgress +=@ fSpeed
IF fProgress >= 1.0
BREAK
ENDIF
ELSE
fProgress -=@ fSpeed
IF fProgress <= 0.0
BREAK
ENDIF
ENDIF
ENDWHILE
IF DOES_CHAR_EXIST hChar
IF bUp = FALSE
TASK_STAND_STILL hChar 50
ENDIF
SET_CHAR_COLLISION hChar ON
ENDIF
CLEO_RETURN 0 ()
}
{
LVAR_INT hChar //In
LVAR_FLOAT fBotX fBotY fTopX fTopY fTopZ fDestAngle fMargin //In
LVAR_INT bUp //In
LVAR_FLOAT fOriginX fOriginY fOriginZ fOriginAngle fDestX fDestY fDestZ fNewX fNewY fNewZ fNewAngle fProgress fProgressEased fSpeed
SlideToCoordTop:
fSpeed = 0.007
TASK_PLAY_ANIM_NON_INTERRUPTABLE hChar "djjr_ladder_top" "ladders_djjr" 2.0 FALSE FALSE FALSE TRUE 0
SET_CHAR_COLLISION hChar OFF
GET_CHAR_COORDINATES hChar (fOriginX fOriginY fOriginZ)
GET_CHAR_HEADING hChar (fOriginAngle)
WHILE fDestAngle < 0.0
fDestAngle += 360.0
ENDWHILE
IF fOriginAngle >= 180.0
fOriginAngle -= 360.0
ENDIF
IF fDestAngle >= 180.0
fDestAngle -= 360.0
ENDIF
IF bUp = TRUE
fProgress = 0.0
fDestX = fTopX
fDestY = fTopY
fDestZ = fTopZ
ELSE
fProgress = 1.0
fDestX = fTopX
fDestY = fTopY
fDestZ = fTopZ
fOriginX = fBotX
fOriginY = fBotY
fOriginZ = fTopZ - fMargin
ENDIF
WHILE TRUE
WAIT 0
IF IS_CHAR_DEAD hChar
BREAK
ENDIF
EASE fProgress EASE_MODE_QUADRATIC EASE_WAY_INOUT (fProgressEased)
LERP fOriginX fDestX fProgressEased (fNewX)
LERP fOriginY fDestY fProgressEased (fNewY)
LERP fOriginZ fDestZ fProgressEased (fNewZ)
LERP fOriginAngle fDestAngle fProgressEased (fNewAngle)
SET_CHAR_COORDINATES_SIMPLE hChar fNewX fNewY fNewZ
SET_CHAR_HEADING hChar fNewAngle
SET_CHAR_ANIM_PLAYING_FLAG hChar "djjr_ladder_top" OFF
SET_CHAR_ANIM_CURRENT_TIME hChar "djjr_ladder_top" fProgressEased
IF bUp = TRUE
fProgress +=@ fSpeed
IF fProgress >= 1.0
BREAK
ENDIF
ELSE
fProgress -=@ fSpeed
IF fProgress <= 0.0
BREAK
ENDIF
ENDIF
ENDWHILE
IF DOES_CHAR_EXIST hChar
IF bUp = TRUE
TASK_STAND_STILL hChar 50
ENDIF
SET_CHAR_COLLISION hChar ON
ENDIF
CLEO_RETURN 0 ()
}
{
LVAR_INT hChar //In
LVAR_FLOAT fAngle //In
LVAR_INT bIsTop //In
LVAR_FLOAT fCharAngle f
CheckCharAngleSimilar:
GET_CHAR_HEADING hChar (fCharAngle)
IF bIsTop = TRUE
fCharAngle += 180.0
ENDIF
WHILE fAngle < 0.0
fAngle += 360.0
ENDWHILE
IF fCharAngle >= 180.0
fCharAngle -= 360.0
ENDIF
IF fAngle >= 180.0
fAngle -= 360.0
ENDIF
f = fCharAngle - fAngle
//PRINT_FORMATTED_NOW "check angle %f %f = %f" 1000 fCharAngle fAngle f
ABS_LVAR_FLOAT f
IF f < 50.0
RETURN_TRUE
CLEO_RETURN 0 ()
ENDIF
RETURN_FALSE
CLEO_RETURN 0 ()
}
Buffer:
DUMP
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ENDDUMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment