AlexWo Posted May 25, 2013 Posted May 25, 2013 Hello, I played once on a Server and there was a script called "Mistery Van". The script spawns a vehicle on Random Locations. If you enter the Van it dissapears and you get some money, armor and so on... function spawnVan () misteryvan = createVehicle (482, x,y,z ) end addEventHandler ( "onResourceStart", getRootElement(), spawnVan ) function givestuff (thePlayer) givePlayerMoney(thePlayer, 5000) setPedArmor( thePlayer, 50) setPedHealth( thePlayer, 100) end addEventHandler ( "onPlayerVehicleEnter", root, givestuff ) Thats the script I got for now. I don't know how to set 10 various locations for the van, and how to make it random. Thank you for helping me
csiguusz Posted May 25, 2013 Posted May 25, 2013 This is an example, how you can get one set of random coordinates from a table: local locations = { { 1, 4, 10 }, { 33, 45, 10 }, { 21, 4, 10 }, { 4, 11, 30 } } function spawnVan () local x, y, z = unpack ( locations [ math.random ( 1, #locations ) ] ) misteryvan = createVehicle (482, x, y, z ) end
AlexWo Posted May 25, 2013 Author Posted May 25, 2013 Ok it works.... I changed the script to local locations = { { 1876, -1377, 13 }, { 1921, -1792, 13 }, { 2000, -2041, 13 } } function spawnVan () local x, y, z = unpack ( locations [ math.random ( 1, #locations ) ] ) misteryvan = createVehicle (482, x, y, z ) blip = createBlipAttachedTo ( misteryvan, 37 ) end addEventHandler ( "onResourceStart", getRootElement(), spawnVan ) function givestuff (thePlayer) if isPedInVehicle ( thePlayer ) then destroyElement ( misteryvan ) end end addEventHandler ( "onPlayerVehicleEnter", root, givestuff ) but if I enter I don't get the money... I think the "thePlayer" is not matched correctly
csiguusz Posted May 25, 2013 Posted May 25, 2013 The first argument returned by the onPlayerVehicleEnter event is the vehicle. Source is the player. And it wont give money if there isn't a function wich gives money. function givestuff ( theVehicle ) if theVehicle == misteryvan then givePlayerMoney ( source, 100 ) destroyElement ( misteryvan ) end end addEventHandler ( "onPlayerVehicleEnter", root, givestuff )
AlexWo Posted May 25, 2013 Author Posted May 25, 2013 Yay it works now as I wanted it to work Thank you very much
Imposter Posted May 25, 2013 Posted May 25, 2013 The first argument returned by the onPlayerVehicleEnter event is the vehicle. Source is the player.And it wont give money if there isn't a function wich gives money. function givestuff ( theVehicle ) if theVehicle == misteryvan then givePlayerMoney ( source, 100 ) destroyElement ( misteryvan ) end end addEventHandler ( "onPlayerVehicleEnter", root, givestuff ) This should work, try it.
csiguusz Posted May 25, 2013 Posted May 25, 2013 Yay it works now as I wanted it to work Thank you very much You are welcome.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now