scienziato-pazzo Posted January 12, 2013 Posted January 12, 2013 I did this function: function DaiSoldi(player,quantita) quantita=tonumber(quantita) givePlayerMoney(player, quantita) outputChatBox("|Uso:| /givemoney [giocatore]",player) end end addCommandHandler("givemoney", DaiSoldi) but doesn't happen anything. Why?
Vision Posted January 12, 2013 Posted January 12, 2013 You have an extra 'end' function DaiSoldi(player,quantita) quantita=tonumber(quantita) givePlayerMoney(player, quantita) outputChatBox("|Uso:| /givemoney [giocatore]",player) end addCommandHandler("givemoney", DaiSoldi)
TAPL Posted January 12, 2013 Posted January 12, 2013 Also, this: function DaiSoldi(player,quantita) Should be: function DaiSoldi(player,cmd,quantita)
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 I changed to this: function DaiSoldi(player,cmd,source,quantita) quantita=tonumber(quantita) if(quantita) then givePlayerMoney(source, quantita) else outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) end end addCommandHandler("givemoney", DaiSoldi) but it says: "Bad argument @ 'givePlayerMoney'"
TAPL Posted January 12, 2013 Posted January 12, 2013 function DaiSoldi(player, cmd, quantita, soldi) local soldi = tonumber(soldi) local quantita = getPlayerFromName(quantita) if (soldi) and (isElement(quantita) then givePlayerMoney(quantita, soldi) else outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) end end addCommandHandler("givemoney", DaiSoldi)
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 It says: "|Uso:| /givemoney [giocatore] [soldi]" when I do /givemoney [playerid or name] [amount]
Anderl Posted January 12, 2013 Posted January 12, 2013 That code will only look for the player element with the exact name you write.
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 That code will only look for the player element with the exact name you write. I written the exact name but it doesn't work.
MR.S3D Posted January 12, 2013 Posted January 12, 2013 try with this Server addCommandHandler("givemoney", function(player, cmd, quantita, soldi) local soldi = tonumber(soldi) local quantita = findPlayerByName(tostring(quantita)) if soldi and quantita then givePlayerMoney(quantita, soldi) else outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) end end ) function findPlayerByName (playerPart ) local players = getPlayerFromName(playerPart) if ( players ) then return players end local matches = {} for id, players in ipairs ( getElementsByType ( "player" ) ) do if ( string.find ( string.upper ( getPlayerName ( players ) ), string.upper ( playerPart ), 1, true ) ) then table.insert(matches,players) end end if #matches == 0 then return false elseif #matches == 1 then return matches[1] else return false end end
Anderl Posted January 12, 2013 Posted January 12, 2013 That code will only look for the player element with the exact name you write. I written the exact name but it doesn't work. With color codes?
MR.S3D Posted January 12, 2013 Posted January 12, 2013 That code will only look for the player element with the exact name you write. I written the exact name but it doesn't work. With color codes? Maybe he used without color code
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 That code will only look for the player element with the exact name you write. I written the exact name but it doesn't work. With color codes? No, without color codes.
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 There's a way to use playerid/partofname?
MR.S3D Posted January 12, 2013 Posted January 12, 2013 function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end addCommandHandler("givemoney", function(player, cmd, quantita, soldi) local soldi = tonumber(soldi) local quantita = getPlayerFromNamePart(tostring(quantita)) if soldi and quantita then givePlayerMoney(quantita, soldi) else outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) end end )
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 (edited) EDIT: Works now Edited January 12, 2013 by Guest
MR.S3D Posted January 12, 2013 Posted January 12, 2013 function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end addCommandHandler("givemoney", function(player, cmd, quantita, soldi) local soldi = tonumber(soldi) local accountname = getAccountName(getPlayerAccount(player)) local quantita = getPlayerFromNamePart(tostring(quantita)) if soldi and quantita then if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" )) then givePlayerMoney(quantita, soldi) end else outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) end end ) try with this
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 And how to do the "playerid" or "part of name"? Not only part of name?
Anderl Posted January 12, 2013 Posted January 12, 2013 @scienziato-pazzo, your script was a complete mess. About the player ID, how do you get it/store it? There's no magical way to get a player ID because simply there's no such thing in MTA, player ID should be scripted by the programmers.
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 @scienziato-pazzo, your script was a complete mess.About the player ID, how do you get it/store it? There's no magical way to get a player ID because simply there's no such thing in MTA, player ID should be scripted by the programmers. Yes, but how to do what I want? It's possible?
Anderl Posted January 12, 2013 Posted January 12, 2013 About the player ID, how do you get it/store it? Would be faster if you read everything people say.
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 About the player ID, how do you get it/store it? Would be faster if you read everything people say. And what people say?
Anderl Posted January 12, 2013 Posted January 12, 2013 About the player ID, how do you get it/store it? Would be faster if you read everything people say. And what people say? Are you kidding? I already quoted what I said two times.
scienziato-pazzo Posted January 12, 2013 Author Posted January 12, 2013 Sorry but I'm not english and I don't understand good. I read this in another resource: local player, name = exports.players:getFromName( thePlayer, victim )
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