Jump to content

Help with event Handler


xXMADEXx

Recommended Posts

Posted

Hey all, i made this simple code, but i am not sure what event handler to put in to make the wanted star create.

function lvl(player) 
    local wanted = getPlayerWantedLevel(player) 
    local x,y,z = getElementPosition(player) 
    if wanted >= 0 then 
        obj = createObject(2147,x,y,z) 
        attachElements(obj,player,0,0,1.2) 
    elseif wanted <= 0 then 
        destroyElement(obj) 
    end 
end 
addEventHandler("?????",lvl) 
  

Posted

Well, there's no event for when wanted level changes, so you maybe should make a timer to loop all players, or make a custom event.

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 (edited)
Well, there's no event for when wanted level changes, so you maybe should make a timer to loop all players, or make a custom event.

I tried this, but error on line 5, and im not sure what it is.

setTimer( 
function (player) 
    local wanted = getPlayerWantedLevel(player) 
    local x,y,z = getElementPosition(player) 
    if (wanted <= 0) then 
        destroyElement(obj) 
    elseif (wanted >= 0) then 
        obj = createObject(1247,x,y,z) 
        attachElements(obj,player,0,0,1.5) 
    end 
end,1000,1) 
  

Edited by Guest
Posted
setTimer ( 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            local wanted = getPlayerWantedLevel ( player ) 
            local x, y, z = getElementPosition ( player ) 
            if ( wanted <= 0 ) then 
                destroyElement ( obj ) 
            elseif ( wanted >= 0 ) then 
                obj = createObject ( 1247, x, y, z ) 
                attachElements ( obj, player, 0, 0, 1.5 ) 
            end 
        end 
    end 
    ,1000, 0 
) 

This is not efficient though.

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
setTimer ( 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            local wanted = getPlayerWantedLevel ( player ) 
            local x, y, z = getElementPosition ( player ) 
            if ( wanted <= 0 ) then 
                destroyElement ( obj ) 
            elseif ( wanted >= 0 ) then 
                obj = createObject ( 1247, x, y, z ) 
                attachElements ( obj, player, 0, 0, 1.5 ) 
            end 
        end 
    end 
    ,1000, 0 
) 

I had to switch it to this:

    setTimer ( 
        function ( ) 
            for _, player in ipairs ( getElementsByType ( "player" ) ) do 
                local wanted = getPlayerWantedLevel ( player ) 
                local x, y, z = getElementPosition ( player ) 
                if ( wanted >= 0 ) then 
                    obj = createObject ( 1247, x, y, z ) 
                    attachElements ( obj, player, 0, 0, 1.5 ) 
                elseif ( wanted <= 0 ) then 
                    destroyElement(obj) 
                end 
            end 
        end 
        ,1000, 0 
    ) 

but, when the player is no long wanted, the star will not delete :S

This is not efficient though.

Posted
stars = { } 
  
setTimer ( 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            local wanted = getPlayerWantedLevel ( player ) 
            local x, y, z = getElementPosition ( player ) 
            if ( wanted == 0 ) then 
                if ( isElement ( stars [ player ] ) ) then 
                    destroyElement ( stars [ player ] ) 
                end 
            else 
                stars [ player ] = createObject ( 1247, x, y, z ) 
                attachElements ( stars [ player ], player, 0, 0, 1.5 ) 
            end 
        end 
    end 
    ,1000, 0 
) 

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

Just add a triggerEvent when you setPlayerWantedLevel.... And use that event :S.

"The total IQ of the world is a constant.

The more people, the more idiots."

- Anonymous.

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