Jump to content

Wanted script [solved]


Mega9

Recommended Posts

Hello there, I hope you can help me somehow with this.

I wanted to make the script which would detect player's wanted level and show it right next to his name. I'm not really sure what functions and handlers I need but this is what I think:

Functions: 
getPlayerWantedLevel 
getPlayerNametagText "or" getPlayerName 
setPlayerNametagText 
setTimer(? so it checks and updates the WL every few seconds?) 
  
============================================================ 
Handler: 
  
onPlayerLogin 
  

 

  
root = getRootElement() 
  
addEventHandler("onPlayerLogin", root, 
function() 
       setPlayerNametagText(source, getPlayerName(source).."["..getPlayerWantedLevel(source).."]") 
end) 
  

Err something like that? :)

Consider my noobishness before posting something insultive, because I am very very willing to learn more lua things.

Thanks for reading.

Edited by Guest
Link to comment
addEventHandler("onPlayerJoin", root, 
    function ( ) 
        setPlayerNametagText ( source, getPlayerName ( source ) .."[".. getPlayerWantedLevel ( source ) .."]" ) 
    end 
) 

That script will add the wanted level when a player joins ( it'll be 0 for sure ), you can also add a timer to update it.

Link to comment

Yeah, I used 'onPlayerLogin' because there would be a save system which saves wanted levels when players quit and loads them back when they log in. Thanks for the help, but I need a help with timer :P

  
addEventHandler("onPlayerJoin", root, 
    function ( ) 
        setTimer ( setPlayerNametagText ( source, getPlayerName ( source ) .."[".. getPlayerWantedLevel ( source ) .."]", 200 ) 
    end 
) 
  

Going to test it and see if debug says anything.

Link to comment

That won't work.

addEventHandler("onPlayerJoin", root, 
    function ( ) 
        setPlayerNametagText ( source, getPlayerName ( source ) .."[".. getPlayerWantedLevel ( source ) .."]" ) 
    end 
) 
  
function updateNametagWantedLevel ( ) 
    for index, player in ipairs ( getElementsByType ( "player" ) ) do -- We loop through all online players. 
        setPlayerNametagText ( player, getPlayerName ( player ) .."[".. getPlayerWantedLevel ( player ) .."]" ) -- We set their nametag text to their current name and wanted level. 
    end 
end 
setTimer ( updateNametagWantedLevel, 3000, 0 ) -- We set a infinite timer of 3 seconds to update the nametag. 

Read the comments I've added.

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