xXMADEXx Posted February 2, 2013 Posted February 2, 2013 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)
Castillo Posted February 2, 2013 Posted February 2, 2013 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.
xXMADEXx Posted February 2, 2013 Author Posted February 2, 2013 (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 February 2, 2013 by Guest
TAPL Posted February 2, 2013 Posted February 2, 2013 Use element data with event onElementDataChange.
Castillo Posted February 2, 2013 Posted February 2, 2013 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.
xXMADEXx Posted February 2, 2013 Author Posted February 2, 2013 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 This is not efficient though.
Castillo Posted February 2, 2013 Posted February 2, 2013 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 )
Puma Posted February 2, 2013 Posted February 2, 2013 Just add a triggerEvent when you setPlayerWantedLevel.... And use that event .
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now