scienziato-pazzo Posted January 12, 2013 Share 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? Link to comment
Vision Posted January 12, 2013 Share 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) Link to comment
TAPL Posted January 12, 2013 Share Posted January 12, 2013 Also, this: function DaiSoldi(player,quantita) Should be: function DaiSoldi(player,cmd,quantita) Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share 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'" Link to comment
TAPL Posted January 12, 2013 Share 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) Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share Posted January 12, 2013 It says: "|Uso:| /givemoney [giocatore] [soldi]" when I do /givemoney [playerid or name] [amount] Link to comment
Anderl Posted January 12, 2013 Share Posted January 12, 2013 That code will only look for the player element with the exact name you write. Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share 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. Link to comment
MR.S3D Posted January 12, 2013 Share 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 Link to comment
Anderl Posted January 12, 2013 Share 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? Link to comment
MR.S3D Posted January 12, 2013 Share 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 Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share 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. Link to comment
MR.S3D Posted January 12, 2013 Share Posted January 12, 2013 The name must be fully with color codes Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share Posted January 12, 2013 There's a way to use playerid/partofname? Link to comment
Anderl Posted January 12, 2013 Share Posted January 12, 2013 Yes, getPlayerFromNamePart. Link to comment
MR.S3D Posted January 12, 2013 Share 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 ) Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share Posted January 12, 2013 (edited) EDIT: Works now Edited January 12, 2013 by Guest Link to comment
MR.S3D Posted January 12, 2013 Share 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 Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share Posted January 12, 2013 And how to do the "playerid" or "part of name"? Not only part of name? Link to comment
Anderl Posted January 12, 2013 Share 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. Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share 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? Link to comment
Anderl Posted January 12, 2013 Share Posted January 12, 2013 About the player ID, how do you get it/store it? Would be faster if you read everything people say. Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share 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? Link to comment
Anderl Posted January 12, 2013 Share 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. Link to comment
scienziato-pazzo Posted January 12, 2013 Author Share 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 ) 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