CobbTheWarriorsRPG Posted August 9, 2013 Share 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 ) Link to comment
DNL291 Posted August 10, 2013 Share 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. Link to comment
Vector Posted August 10, 2013 Share Posted August 10, 2013 one more thing, when using math.random, if first argument is 1, you can omit it. -> math.random(#M4Pickup); Link to comment
CobbTheWarriorsRPG Posted August 10, 2013 Author Share 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? Link to comment
Castillo Posted August 10, 2013 Share 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 Link to comment
CobbTheWarriorsRPG Posted August 10, 2013 Author Share 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) Link to comment
iPrestege Posted August 10, 2013 Share Posted August 10, 2013 Copy castillo code again . Link to comment
Castillo Posted August 10, 2013 Share Posted August 10, 2013 Yeah, I put an "l" by mistake, just copy it again . Link to comment
CobbTheWarriorsRPG Posted August 10, 2013 Author Share Posted August 10, 2013 Thank you a lot to all,It works for me thanks! Link to comment
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