Jump to content

[HELP]Spawn a random pickup whit the coordinates


Recommended Posts

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
  • Moderators
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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...