Jump to content

help me for onPlayerWasted


emuk

Recommended Posts

I want to create a script to do so when a player dies are created pieces where he died.

The objects are id 2908-2907-2906-2905.

I tried to do it this way but does not work.

function morte () 
    local myPosition = getLocalPlayer() 
    local x, y, z = getElementPosition ( myPosition ) 
    creaPezzi ( x, y, z ) 
end 
     
addEventHandler ( "onPlayerWasted", resourceRoot, onClientResourceStart ) 
  
setTimer ( morte, 1000, 1) 
     
function creaPezzi(x, y, z) 
    createObject ( 2905, x, y, z ) 
    createObject ( 2906, x, y, z ) 
    createObject ( 2907, x, y, z ) 
    createObject ( 2908, x, y, z ) 
end 

and I would also set a timer to delete those pieces after 2-3 seconds.

how can I do? Thank you.

Link to comment

You're using getLocalPlayer in a server sided script.

onClientResourceStart function doesn't exist.

Also onPlayerWasted second argument should be 'root' variable or 'getRootElement' function.

function morte () 
    local x, y, z = getElementPosition ( source) 
    creaPezzi ( x, y, z ) 
end 
    
addEventHandler ( "onPlayerWasted", root,morte ) 
    
function creaPezzi(x, y, z) 
    createObject ( 2905, x, y, z ) 
    createObject ( 2906, x, y, z ) 
    createObject ( 2907, x, y, z ) 
    createObject ( 2908, x, y, z ) 
end 

One more thing, why setTimer?

Link to comment

Right, I had forgotten that in a server sided script onClientResourceStart function doesn't exist :D

I had put the timer because I in another script without it did not work.

however, now works but I'd like to put a timer to delete the objects after 3 seconds.

I tried with DestroyElement but it does not work :mrgreen:

Link to comment

onClientResourceStart is an event, it's not a function, even in a client sided script.

function morte () 
    local x, y, z = getElementPosition ( source) 
    creaPezzi ( x, y, z ) 
end 
    
addEventHandler ( "onPlayerWasted", root,morte ) 
    
function creaPezzi(x, y, z) 
    local obj = { } 
    obj[1]=createObject ( 2905, x, y, z ) 
    obj[2]=createObject ( 2906, x, y, z ) 
    obj[3]=createObject ( 2907, x, y, z ) 
    obj[4]=createObject ( 2908, x, y, z ) 
   setTimer(function(objects) for index,object in ipairs(objects) do destroyElement ( object ) end end, 3000 , 1 , obj ) 
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...