~DarkRacer~ Posted March 21, 2013 Share Posted March 21, 2013 Hey Guys, this script shows in chat the money of the player who write in chat !cash or !money. i want to make the players can check other players money like: !cash [playerName]. i don't want to use the command handler. How can i do that? Server: addEventHandler("onPlayerChat", getRootElement(), function(msg) if (msg == "!money" or msg == "!cash") then cash = getPlayerMoney(source) outputChatBox("#0188ff"..getPlayerName(source).." Has #ff8801$"..cash, getRootElement(), 255,255,255,true) end end ) Link to comment
golanu21 Posted March 21, 2013 Share Posted March 21, 2013 you can do this addCommandHandler("money", getRootElement(), function(playerName) if playername then playername = getPlayerName () money = getPlayerMoney () outputChatBox ("The player"..playername.."have:"..money.."$", source, 255, 0, 255 ) else outputChatBox("Syntax : /money Playername", source, 255, 0, 255) end end) I do not know if it works but try Link to comment
iPrestege Posted March 21, 2013 Share Posted March 21, 2013 you can do this addCommandHandler("money", getRootElement(), function(playerName) if playername then playername = getPlayerName () money = getPlayerMoney () outputChatBox ("The player"..playername.."have:"..money.."$", source, 255, 0, 255 ) else outputChatBox("Syntax : /money Playername", source, 255, 0, 255) end end) I do not know if it works but try This is wrong . Link to comment
~DarkRacer~ Posted March 21, 2013 Author Share Posted March 21, 2013 This is totally wrong and missed up! i said : "i don't want to use the command handler." and i want to view other player's money like this: !cash [the player name that i want to show his money in chat] Link to comment
gokalpfirat Posted March 21, 2013 Share Posted March 21, 2013 You should use this to get player from name. function getPlayerFromName( partialName ) if partialName then local matches = {} for i, player in ipairs ( getElementsByType ( "player" ) ) do if getPlayerName ( player ) == partialName then return player end if getPlayerName ( player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( partialName : lower ( ) ) then table.insert ( matches , player ) end end if #matches == 1 then return matches [ 1 ] end end return false end Link to comment
Tete omar Posted March 21, 2013 Share Posted March 21, 2013 addEventHandler("onPlayerChat", getRootElement(), function(msg) if msg:find("!money ") or msg:find("!cash ") then for i,v in ipairs(getElementsByType("player")) do if msg:find(getPlayerName(v)) and getPlayerName(v) ~= false then local player = getPlayerFromName(v) local cash = getPlayerMoney(player) outputChatBox("#0188ff"..getPlayerName(player).." Has #ff8801$"..cash, root, 255,255,255,true) else outputChatBox("Wrong player-name/syntax", source) end end end end ) I'm not sure of this, but it should work. Link to comment
Castillo Posted March 21, 2013 Share Posted March 21, 2013 addEventHandler ( "onPlayerChat", getRootElement(), function ( msg ) local splittedMsg = split ( msg, " " ) if ( type ( splittedMsg ) == "table" ) then if ( splittedMsg [ 1 ] == "!money" or splittedMsg [ 1 ] == "!cash" ) then local player = getPlayerFromName ( splittedMsg [ 2 ] ) if ( player ) then local cash = getPlayerMoney ( player ) outputChatBox ( "#0188ff".. getPlayerName ( player ) .." Has #ff8801$".. cash, root, 255, 255, 255, true ) else outputChatBox ( "Player not found!", source, 255, 0, 0 ) end end end end ) function getPlayerFromName ( partialName ) if partialName then local matches = {} for i, player in ipairs ( getElementsByType ( "player" ) ) do if getPlayerName ( player ) == partialName then return player end if getPlayerName ( player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( partialName : lower ( ) ) then table.insert ( matches , player ) end end if #matches == 1 then return matches [ 1 ] end end return false end Link to comment
~DarkRacer~ Posted March 22, 2013 Author Share Posted March 22, 2013 addEventHandler ( "onPlayerChat", getRootElement(), function ( msg ) local splittedMsg = split ( msg, " " ) if ( type ( splittedMsg ) == "table" ) then if ( splittedMsg [ 1 ] == "!money" or splittedMsg [ 1 ] == "!cash" ) then local player = getPlayerFromName ( splittedMsg [ 2 ] ) if ( player ) then local cash = getPlayerMoney ( player ) outputChatBox ( "#0188ff".. getPlayerName ( player ) .." Has #ff8801$".. cash, root, 255, 255, 255, true ) else outputChatBox ( "Player not found!", source, 255, 0, 0 ) end end end end ) function getPlayerFromName ( partialName ) if partialName then local matches = {} for i, player in ipairs ( getElementsByType ( "player" ) ) do if getPlayerName ( player ) == partialName then return player end if getPlayerName ( player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( partialName : lower ( ) ) then table.insert ( matches , player ) end end if #matches == 1 then return matches [ 1 ] end end return false end Thanks it's working, but can i make that if the player not found do not display "!cash" on chat. Link to comment
~DarkRacer~ Posted March 22, 2013 Author Share Posted March 22, 2013 Use cancelEvent(). Thanks 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