Mega9 Posted March 28, 2012 Share Posted March 28, 2012 (edited) 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 March 28, 2012 by Guest Link to comment
Castillo Posted March 28, 2012 Share Posted March 28, 2012 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
Mega9 Posted March 28, 2012 Author Share Posted March 28, 2012 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 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
Castillo Posted March 28, 2012 Share Posted March 28, 2012 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
X-SHADOW Posted March 28, 2012 Share Posted March 28, 2012 mega9 small edit to your script here setTimer ( function () for index,player in pairs (getElementsByType("player")) do setPlayerNametagText(player,getPlayerName(player).."["..tostring(getPlayerWantedLevel (player)).."]") end end , 5000 , 0) Link to comment
Mega9 Posted March 29, 2012 Author Share Posted March 29, 2012 Thanks for the help, but Solidsnake's works just perfect. Link to comment
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