Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Attach Vehicle Mod by Junior_Djjr - MixMods.com.br
// You need: https://forum.mixmods.com.br/f16-utilidades/t179-gta3script-while-true-return_true-e-return_false
// And also: https://www.mixmods.com.br/2020/03/CLEOPlus.html
SCRIPT_START
{
LVAR_INT scplayer hVeh hVehDest iFoundVeh bAttached p iPlayerId iButton bOnlyIfStopped bNotForEmergencyVehicles bNotForCarsAndBikes iSubclass bPlayerPressing[2] pVeh pVehDest pVehDestHandling
LVAR_FLOAT x y z x1 y1 z1 f
WAIT 500
// Check CLEO+ installed
IF NOT LOAD_DYNAMIC_LIBRARY "CLEO+.cleo" p
timera = 0
WHILE timera < 5000
WAIT 0
PRINT_STRING "~r~ERROR: 'CLEO+.cleo' isn't installed. Download it." 5000
ENDWHILE
TERMINATE_THIS_CUSTOM_SCRIPT
ENDIF
FREE_DYNAMIC_LIBRARY p
IF NOT READ_INT_FROM_INI_FILE "CLEO/Attach Vehicle.ini" "Settings" "Button" (iButton)
iButton = 19
ENDIF
IF NOT READ_INT_FROM_INI_FILE "CLEO/Attach Vehicle.ini" "Settings" "OnlyIfStopped" (bOnlyIfStopped)
bOnlyIfStopped = TRUE
ENDIF
IF NOT READ_INT_FROM_INI_FILE "CLEO/Attach Vehicle.ini" "Settings" "NotForEmergencyVehicles" (bNotForEmergencyVehicles)
bNotForEmergencyVehicles = TRUE
ENDIF
IF NOT READ_INT_FROM_INI_FILE "CLEO/Attach Vehicle.ini" "Settings" "NotForCarsAndBikes" (bNotForCarsAndBikes)
bNotForCarsAndBikes = TRUE
ENDIF
WHILE TRUE
WAIT 0
iPlayerId = 0
GOSUB Process
IF IS_2PLAYER_GAME_GOING_ON
iPlayerId = 1
GOSUB Process
ENDIF
ENDWHILE
Process:
GET_PLAYER_CHAR iPlayerId scplayer
IF IS_BUTTON_PRESSED iPlayerId iButton
IF IS_CHAR_SITTING_IN_ANY_CAR scplayer
AND bPlayerPressing[iPlayerId] = FALSE
STORE_CAR_CHAR_IS_IN_NO_SAVE scplayer hVehDest
GET_VEHICLE_POINTER hVehDest pVehDest
READ_STRUCT_OFFSET pVehDest 0x4C8 4 p // m_pTrailer
IF p > 0
GET_VEHICLE_REF p hVehDest
ENDIF
IF bOnlyIfStopped = TRUE
GET_CAR_SPEED hVehDest f
IF f > 1.0 // Better than IS_CAR_STOPPED because we can activate even if moving a bit, like collision bugs
RETURN
ENDIF
ENDIF
IF bNotForEmergencyVehicles = TRUE
IF IS_EMERGENCY_SERVICES_VEHICLE hVehDest
RETURN
ENDIF
ENDIF
IF bNotForCarsAndBikes = TRUE
GET_VEHICLE_SUBCLASS hVehDest iSubclass
IF iSubclass = VEHICLE_SUBCLASS_AUTOMOBILE
OR iSubclass = VEHICLE_SUBCLASS_BIKE
OR iSubclass = VEHICLE_SUBCLASS_BMX
OR iSubclass = VEHICLE_SUBCLASS_QUAD
READ_STRUCT_OFFSET pVehDest 0x384 4 pVehDestHandling //m_pHandlingData
READ_STRUCT_OFFSET pVehDestHandling 0xCC 4 p //modelFlags
IF NOT IS_LOCAL_VAR_BIT_SET_CONST p 3 //IS_BIG
READ_STRUCT_OFFSET pVehDestHandling 0xDE 1 p
IF NOT p = 2 //truck
RETURN
ENDIF
ENDIF
ENDIF
ENDIF
IF NOT GET_EXTENDED_CAR_VAR hVehDest AUTO 1 bAttached
INIT_EXTENDED_CAR_VARS hVehDest AUTO 1
bAttached = FALSE
ENDIF
GET_CAR_COORDINATES hVehDest x y z
iFoundVeh = 0
IF GET_RANDOM_CAR_IN_SPHERE_NO_SAVE_RECURSIVE x y z 20.0 FALSE FALSE (hVeh)
GOSUB AttachThis
WHILE GET_RANDOM_CAR_IN_SPHERE_NO_SAVE_RECURSIVE x y z 20.0 TRUE FALSE (hVeh)
GOSUB AttachThis
ENDWHILE
ENDIF
IF iFoundVeh > 0
IF bAttached = TRUE
bAttached = FALSE
IF iFoundVeh > 1
PRINT_HELP ATTVEH4
ELSE
PRINT_HELP ATTVEH3
ENDIF
ELSE
bAttached = TRUE
IF iFoundVeh > 1
PRINT_HELP ATTVEH2
ELSE
PRINT_HELP ATTVEH1
ENDIF
ENDIF
ENDIF
SET_EXTENDED_CAR_VAR hVehDest AUTO 1 bAttached
bPlayerPressing[iPlayerId] = TRUE
ENDIF
ELSE
bPlayerPressing[iPlayerId] = FALSE
ENDIF
RETURN
AttachThis:
IF hVeh = hVehDest
OR NOT DOES_VEHICLE_EXIST hVeh // because we use WAIT 0 in detach loop
OR NOT DOES_VEHICLE_EXIST hVehDest
RETURN
ENDIF
IF bAttached = FALSE
IF IS_CAR_TOUCHING_CAR hVeh hVehDest
ATTACH_CAR_TO_CAR hVeh hVehDest -1000.0 -1000.0 -1000.0 0.0 0.0 0.0
SET_CAR_COLLISION hVeh OFF
CLOSE_ALL_CAR_DOORS hVeh
SET_CAR_ENGINE_ON hVeh OFF
iFoundVeh++
ENDIF
ELSE
GET_CAR_COORDINATES hVeh x1 y1 z1
z1 += 0.2
// Fixes a collision bug
FREEZE_CAR_POSITION hVeh ON
DETACH_CAR hVeh x1 y1 z1 FALSE
WAIT 0
IF DOES_VEHICLE_EXIST hVeh
FREEZE_CAR_POSITION hVeh OFF
SET_CAR_COLLISION hVeh ON
// Force update physics; fixes FREEZE_CAR_POSITION
APPLY_FORCE_TO_CAR hVeh 0.0 0.0 0.01 0.0 0.0 0.0
// Disables ignore collision, we want to keep the car on top of the other
GET_VEHICLE_POINTER hVeh p
WRITE_STRUCT_OFFSET p 0x128 4 0 //EntityIgnoredCollision
ENDIF
iFoundVeh++
ENDIF
RETURN
}
SCRIPT_END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.