Jump to content

onPlayerWasted and onPlayerSpawn


Dice

Recommended Posts

Posted
addEventHandler( "onPlayerWasted", getRootElement(), 
    function( totalammo, killer, killerWeapon, bodypart ) 
        if isElementWithinColShape ( source, arena ) then 
            local detection = isElementWithinColShape ( source, arena ) 
            local detectionKiller = isElementWithinColShape ( killer, arena ) 
            if detection then 
                if close == 1 then 
                    local dx, dy, dz = unpack(randspawn[math.random(#randspawn)]) 
                    setTimer ( setElementPosition, 5000, 1, source, dx, dy, dz ) 
                    setTimer ( setElementHealth, 5000, 1, killer, 200 ) 
                    setTimer ( setElementRotation, 5000, 1, source, 0, 0, 180 ) 
                else 
                    setTimer ( setElementPosition, 5000, 1, source, 577.92224121094, -2621.6677246094, 1378.0678710938 ) 
                    setTimer ( setElementHealth, 5000, 1, killer, 200 ) 
                    setTimer ( setElementRotation, 5000, 1, source, 0, 0, 180 ) 
                end 
            end 
        end 
    end 
) 

What happens here is, if a player get's killed then fill the killers HP to 200 because it is 200. But timer is unreliable, can I embed onPlayerSpawn ? into this? and when I do and try to use the variable killer in it it says it is a nil value. How can I do it this way instead of timers.

Posted

yes it's an arena type thing. but I think onPlayerSpawn would be better use of cpu and ram instead of setting a timer everytime a person dies.

Posted

Yes, it'll be more efficient.

local killers = { } 
  
addEventHandler ( "onPlayerWasted", getRootElement(), 
    function ( totalammo, killer, killerWeapon, bodypart ) 
        if isElementWithinColShape ( source, arena ) then 
            local detection = isElementWithinColShape ( source, arena ) 
            local detectionKiller = isElementWithinColShape ( killer, arena ) 
            if detection then 
                local x, y, z = unpack ( ( close == 1 and randspawn [ math.random ( #randspawn ) ] ) or { 577.92224121094, -2621.6677246094, 1378.0678710938 } ) 
                setTimer ( 
                    function ( thePlayer, dx, dy, dz ) 
                        if ( isElement ( thePlayer ) ) then 
                            setElementPosition ( thePlayer, dx, dy, dz ) 
                            setPedRotation ( thePlayer, 180 ) 
                        end 
                    end 
                    ,5000, source, x, y, z 
                ) 
                killers [ source ] = killer 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerSpawn", root, 
    function ( ) 
        if ( isElement ( killers [ source ] ) ) then 
            setElementHealth ( killers [ source ], 200 ) 
        end 
        killers [ source ] = nil 
    end 
) 

Not tested.

Posted

Question what if someone who has nothing to do with the arena spawns, and killer [ source ] is an element willl that effect the killers [ source ]

Posted

The player that died is inserted on the table inside the function that checks if is in the arena, so it shouldn't happen what you said.

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