Jump to content

[HELP]Spawn a random pickup whit the coordinates


Recommended Posts

Posted

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 ) 

Posted
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.

Posted

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. .)

Posted

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?

Posted
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.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Yeah, I put an "l" by mistake, just copy it again :P.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...