Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SCRIPT_START
{
LVAR_INT scplayer hChar pChar hObj hLastObject i hTasks iObjectModel bIsVend
LVAR_FLOAT x y z charX charY charZ objX objY objZ offset radius
GET_PLAYER_CHAR 0 scplayer
WHILE TRUE
WAIT 100
GET_ACTIVE_CAMERA_COORDINATES x y z
IF GET_RANDOM_CHAR_IN_SPHERE_NO_SAVE_RECURSIVE x y z 300.0 FALSE TRUE hChar
WAIT 0 // THIS ISN'T RECOMMENDED, but in this case we don't need to be accurated, so it's ok for a little performance
IF GOSUB GetObject
GOSUB Process
CONTINUE
ENDIF
WHILE GET_RANDOM_CHAR_IN_SPHERE_NO_SAVE_RECURSIVE x y z 300.0 TRUE TRUE hChar
WAIT 0
IF GOSUB GetObject
GOSUB Process
BREAK
ENDIF
ENDWHILE
ENDIF
ENDWHILE
Process:
IF GET_EXTENDED_CHAR_VAR hChar AUTO 1 hLastObject
IF hLastObject = hObj
RETURN
ENDIF
ELSE
INIT_EXTENDED_CHAR_VARS hChar AUTO 1
ENDIF
SET_EXTENDED_CHAR_VAR hChar AUTO 1 hObj
IF IS_CHAR_DEAD hChar
RETURN
ENDIF
//GET_OBJECT_COORDINATES hObj objX objY objZ
GET_OFFSET_FROM_OBJECT_IN_WORLD_COORDS hObj offset 0.0 0.0 (objX objY objZ)
TASK_GO_TO_COORD_ANY_MEANS hChar objX objY objZ 4 -1
REQUEST_ANIMATION VENDING
timera = 0
WHILE TRUE
WAIT 0
IF IS_CHAR_DEAD hChar
OR timera > 10000
RETURN
ENDIF
IF LOCATE_CHAR_ANY_MEANS_3D hChar objX objY objZ radius radius 1.5 FALSE
BREAK
ENDIF
ENDWHILE
WHILE NOT HAS_ANIMATION_LOADED VENDING
WAIT 0
ENDWHILE
IF IS_CHAR_DEAD hChar
RETURN
ENDIF
timera = 0
WHILE timera < 1000
WAIT 100
IF IS_CHAR_DEAD hChar
RETURN
ENDIF
TASK_TURN_CHAR_TO_FACE_COORD hChar objX objY objZ
ENDWHILE
IF LOCATE_CHAR_ANY_MEANS_3D hChar objX objY objZ 2.0 2.0 1.5 FALSE
IF bIsVend = TRUE
OPEN_SEQUENCE_TASK hTasks
TASK_PLAY_ANIM -1 "VEND_Use" "VENDING" 4.0 FALSE FALSE FALSE FALSE -1
TASK_PLAY_ANIM -1 "VEND_Use_pt2" "VENDING" 4.0 FALSE FALSE FALSE FALSE -1
TASK_PLAY_ANIM -1 "VEND_Drink_P" "VENDING" 4.0 FALSE FALSE FALSE FALSE -1
CLOSE_SEQUENCE_TASK hTasks
PERFORM_SEQUENCE_TASK hChar hTasks
CLEAR_SEQUENCE_TASK hTasks
WAIT 3000
ELSE
TASK_PLAY_ANIM hChar "vend_eat1_P" "VENDING" 4.0 FALSE FALSE FALSE FALSE -1
ENDIF
ENDIF
WAIT 2000
REMOVE_ANIMATION VENDING
RETURN
GetObject:
IF DOES_CHAR_EXIST hChar
IF NOT IS_CHAR_SCRIPT_CONTROLLED hChar
AND NOT IS_CHAR_IN_ANY_CAR hChar
GET_PED_POINTER hChar pChar
READ_STRUCT_OFFSET pChar 0x59C 4 i //pPedstats
READ_MEMORY i 4 FALSE i
IF i > 3
IF IS_CURRENT_CHAR_WEAPON hChar WEAPONTYPE_UNARMED
// any better way? tried with tasks
IF NOT IS_CHAR_PLAYING_ANIM hChar "sprint_panic"
AND NOT IS_CHAR_PLAYING_ANIM hChar "woman_runpanic"
READ_STRUCT_OFFSET pChar 0x764 4 i //m_nLastWeaponDamage (need more)
IF NOT i > 0
GET_CHAR_COORDINATES hChar charX charY charZ
IF GET_RANDOM_OBJECT_IN_SPHERE_NO_SAVE_RECURSIVE charX charY charZ 8.0 FALSE hObj
IF GOSUB CheckObject
RETURN_TRUE
RETURN
ENDIF
WHILE GET_RANDOM_OBJECT_IN_SPHERE_NO_SAVE_RECURSIVE charX charY charZ 8.0 TRUE hObj
IF GOSUB CheckObject
RETURN_TRUE
RETURN
ENDIF
ENDWHILE
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
RETURN_FALSE
RETURN
CheckObject:
bIsVend = FALSE
GET_OBJECT_MODEL hObj iObjectModel
IF iObjectModel = 1340 //chillidogcart
offset = 0.5
radius = 1.0
RETURN_TRUE
RETURN
ENDIF
IF iObjectModel = 1341 //icescart_prop
offset = 0.5
radius = 1.0
RETURN_TRUE
RETURN
ENDIF
IF iObjectModel = 1342 //noodlecart_prop
offset = 0.5
radius = 1.0
RETURN_TRUE
RETURN
ENDIF
IF iObjectModel = 1776 //CJ_CANDYVENDOR
offset = 0.5
radius = 1.5
bIsVend = TRUE
RETURN_TRUE
RETURN
ENDIF
IF iObjectModel = 1209 //vendmach
offset = 0.0
radius = 1.5
bIsVend = TRUE
RETURN_TRUE
RETURN
ENDIF
IF iObjectModel = 955 //CJ_EXT_SPRUNK
offset = 0.0
radius = 1.5
bIsVend = TRUE
RETURN_TRUE
RETURN
ENDIF
IF iObjectModel = 1775 //CJ_SPRUNK1
offset = 0.0
radius = 1.5
bIsVend = TRUE
RETURN_TRUE
RETURN
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.