TroyBoy Posted February 14, 2012 Share Posted February 14, 2012 how can i do a command to send to a player that i will choose i mean like /givemoney [playername] ammount how can i do this? Link to comment
Kenix Posted February 14, 2012 Share Posted February 14, 2012 Server. function findPlayer( namepart ) local player = getPlayerFromName( namepart ) if player then return player end for _,player in pairs( getElementsByType 'player' ) do if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then return player end end return false end addCommandHandler( 'givemoney', function( source,_,player,amount ) local find = findPlayer( player ) if find then if amount then givePlayerMoney( find,tonumber( amount ) ) outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),source,255,0,0 ) else outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) end else outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) end end ) Updated. Link to comment
TroyBoy Posted February 14, 2012 Author Share Posted February 14, 2012 can you explain me from the script what is give the find the player that i typed in the game? Link to comment
Kenix Posted February 14, 2012 Share Posted February 14, 2012 (edited) So it command give money player. You type command /givemoney [ nickname ][ amount ] Example:/givemoney Kenix 1000 Or i not understand you, Edited February 14, 2012 by Guest Link to comment
TroyBoy Posted February 14, 2012 Author Share Posted February 14, 2012 no i ment the line that check the name of the player i typed in the game Link to comment
Kenix Posted February 14, 2012 Share Posted February 14, 2012 function findPlayer( namepart ) -- 1 argument is string local player = getPlayerFromName( namepart ) if player then -- if player found return player -- return player element end -- So if not found with getPlayerFromName then find player with loop. for _,player in pairs( getElementsByType 'player' ) do -- loop table players if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then -- find player by pattern return player -- return player element end end return false -- return false if not found end addCommandHandler( 'givemoney', -- add command handler function( source,_,player,amount ) -- 1 argument is source ( element player ) ( who use type this command ) , 2 argument is command name but we not need use this and we create 'upvalue' ( frozen variable that will not be used ) , 3 argument is player nick name ( string ) , 4 argument is amount local find = findPlayer( player ) -- So call function findPlayer in argument use nick name ( string ) if find then -- If player founded then if amount then -- If player type amount ( full command /givemoney [nickname][amount] ) givePlayerMoney( find,tonumber( amount ) ) -- give money for player outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),source,255,0,0 ) -- write in chat box else -- player not type full command ( /givemoney [nickname][amount] ) outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) -- write in chat box end else -- player not found outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) -- write in chat box end end ) Updated again. Link to comment
TroyBoy Posted February 14, 2012 Author Share Posted February 14, 2012 my question is what line in the script that you gave me check the name of the player that i wrote in the game to give him the money if it will be TroyBoy and i will write TroyBoy in the playername what will check this Link to comment
Kenix Posted February 14, 2012 Share Posted February 14, 2012 16 line is handler function parameters. 17 line call function and it function return player element or false 18 line check. You mean this? I made comments in the code Read please. 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