CobbTheWarriorsRPG Posted August 9, 2013 Posted August 9, 2013 Hello i want to make a script who spawn pickups in 8 minutes but random how can i make this? and when you hit the pickup its being destroyed and create a new one in 8 mins whit another coord? i make this but they code doesnt works local M4Pickup = { {4556,-5444.4333,4555}, {76789,-98766.766,8777}, } function SpawnPicks() createPickup(M4Pickup[ math.random(1, #M4Pickup)], 1),2,1239,300,0) addEventHandler ( "onResourceStart", getRootElement(), SpawnPicks ) setTimer ( SpawnPicks, 480000, 1 )
DNL291 Posted August 10, 2013 Posted August 10, 2013 local M4Pickup = { {4556,-5444.4333,4555}, {76789,-98766.766,8777}, } function SpawnPicks() if not pickup then local pickup = createPickup(M4Pickup[ math.random(1, #M4Pickup) ], 2, 31) addEventHandler( "onPickupHit", pickup, onPickupHit ) end end addEventHandler ( "onResourceStart", resourceRoot, SpawnPicks ) setTimer ( SpawnPicks, 480000, 0 ) function onPickupHit() if isElement(pickup) then destroyElement(pickup) end pickup = nil end Try it. Please do not PM me with scripting related question nor support, use the forums instead.
Vector Posted August 10, 2013 Posted August 10, 2013 one more thing, when using math.random, if first argument is 1, you can omit it. -> math.random(#M4Pickup); there are two kinds of people: those who know C++ and those who don´t. .)
CobbTheWarriorsRPG Posted August 10, 2013 Author Posted August 10, 2013 Its Doesnt work Bro :c Give to me 2 warnings and dont spawn the pickups: [2013-08-10 11:15:07] WARNING: addon_hel\server.lua:10: Bad argument @ 'createPickup' [2013-08-10 11:15:07] WARNING: addon_hel\server.lua:11: Bad argument @ 'addEventHandler' [Expected element at argument 2, got boolean] Some help please?
Castillo Posted August 10, 2013 Posted August 10, 2013 local M4Pickup = { {4556,-5444.4333,4555}, {76789,-98766.766,8777}, } function SpawnPicks ( ) if ( not pickup ) then local x, y, z = unpack ( M4Pickup [ math.random ( #M4Pickup ) ] ) pickup = createPickup ( x, y, z, 2, 31 ) addEventHandler ( "onPickupHit", pickup, onPickupHit ) end end addEventHandler ( "onResourceStart", resourceRoot, SpawnPicks ) setTimer ( SpawnPicks, 480000, 0 ) function onPickupHit ( ) if isElement ( pickup ) then destroyElement ( pickup ) end pickup = nil end San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
CobbTheWarriorsRPG Posted August 10, 2013 Author Posted August 10, 2013 Thanks Castillo! But it give to me this error and the pickups doesnt spawn [2013-08-10 11:32:22] ERROR: addon_hel\server.lua:10: attempt to call global 'unpackl' (a nil value)
Castillo Posted August 10, 2013 Posted August 10, 2013 Yeah, I put an "l" by mistake, just copy it again . San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
CobbTheWarriorsRPG Posted August 10, 2013 Author Posted August 10, 2013 Thank you a lot to all,It works for me thanks!
Castillo Posted August 10, 2013 Posted August 10, 2013 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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