Hilmer97 Posted November 23, 2011 Share Posted November 23, 2011 Hello anyone, I want to make an script in which you can transfer your own money to antoher player with an code like this: /Transferto [playername] [money] An example: /Transfer Sjon 2000 So first there must be 2000 of your money depreciated and that money goes to Sjon And i also want something in which you dont have to write the whole name with that character like #FF0000Sjon Who can help me? Link to comment
CapY Posted November 23, 2011 Share Posted November 23, 2011 You may want to use this resource : https://community.multitheftauto.com/index.php?p= ... ls&id=3224 Link to comment
unknooooown Posted November 23, 2011 Share Posted November 23, 2011 Hello anyone,I want to make an script in which you can transfer your own money to antoher player with an code like this: /Transferto [playername] [money] An example: /Transfer Sjon 2000 So first there must be 2000 of your money depreciated and that money goes to Sjon And i also want something in which you dont have to write the whole name with that character like #FF0000Sjon Who can help me? Hi. I just tried to make what you are looking for in my lua commandline. Got a pretty good solution for you. Please note, that this is not the way that you should make it, so it wont work if you just paste the code into your resource. This is to give you an idea of how you can make it yourself. -- First we get a table of all names. names = { [1] = "Baltazar", [2] = "Alojzy", [3] = "Felicia", [4] = "Isabela", [5] = "Jadwiga", [6] = "Katarzyna", [7] = "Krzysztof", [8] = "Klementyna", [9] = "Mateusz", [10] = "Regina" } local playerInput = "Kle" --This is what the user has typed in the command. Example: /transfer Kle 2000 -- It will then look for all users with "Kle" in their name, however it wouldnt be able to find "Klementyna", if all the characters where lowercase, like: "kle". for i,k in ipairs(names) do if string.find(k,playerInput) ~= nil then print(k.." is a possible candidate.") end end This example will return: >>Klementyna is a possible candidate. Tell me if this makes sense to you at all If not, then I will try to explain it a little better. Same goes for the rest of your script. Just want to get an idea of how good you are, before I try to explain it, so I know how I should explain it Link to comment
Castillo Posted November 23, 2011 Share Posted November 23, 2011 Wafamde, he want's a script to send money to another players, and the script has to detect part of player name(s). Link to comment
Hilmer97 Posted November 23, 2011 Author Share Posted November 23, 2011 You may want to use this resource : https://community.multitheftauto.com/index.php?p= ... ls&id=3224 Yes something like that but then with a code las i said in my first reply. Link to comment
Castillo Posted November 23, 2011 Share Posted November 23, 2011 This should work: addCommandHandler("transferTo", function (thePlayer, cmd, toWho, cash) if (toWho == "") then return end local playerTo = findPlayerByName(toWho) if (not isElement(playerTo)) then outputChatBox("This player is not online.",thePlayer,255,0,0) return end local cash = tonumber(cash) if getPlayerMoney(thePlayer) >= cash then outputChatBox("You have sent $".. tostring(cash) .." to ".. tostring(getPlayerName(playerTo)),thePlayer,0,255,0) outputChatBox(tostring(getPlayerName(thePlayer)) " has sent you $".. tostring(cash),playerTo,0,255,0) givePlayerMoney(playerTo, cash) takePlayerMoney(thePlayer, cash) else outputChatBox("You don't have $".. tostring(cash) ..".",thePlayer,255,0,0) end end) function findPlayerByName(playerPart) local pl = getPlayerFromName(playerPart) if isElement(pl) then return pl else for i,v in ipairs (getElementsByType ("player")) do if (string.find(getPlayerName(v),playerPart)) then return v end end end end Link to comment
Hilmer97 Posted November 23, 2011 Author Share Posted November 23, 2011 It doesnt work because if i give someone money the person dont received the money and by me there has no money been depreciated. And i have to write the whole name:P But the beginning is there and i want to thank you for that! Link to comment
Castillo Posted November 23, 2011 Share Posted November 23, 2011 That's not possible, it gives the money and takes it from you. You have it as server side, right? in the meta.xml. Link to comment
unknooooown Posted November 23, 2011 Share Posted November 23, 2011 That's not possible, it gives the money and takes it from you.You have it as server side, right? in the meta.xml. I guess the only way around that is if he/we script a money resource from scratch. Link to comment
Hilmer97 Posted November 23, 2011 Author Share Posted November 23, 2011 That's not possible, it gives the money and takes it from you.You have it as server side, right? in the meta.xml. Yes i have server side but it dont takes money and give it to antoher person Link to comment
unknooooown Posted November 23, 2011 Share Posted November 23, 2011 That's not possible, it gives the money and takes it from you.You have it as server side, right? in the meta.xml. Yes i have server side but it dont takes money and give it to antoher person Do you write: /transferTo - ? Its important that you type it in the same way that SolidSnake wrote it in the script. Correct command is: /transferTo NAME AMOUNT Link to comment
Castillo Posted November 23, 2011 Share Posted November 23, 2011 Ok, I've noticed of some typos in my script, here: addCommandHandler("transferTo", function (thePlayer, cmd, toWho, cash) if (toWho == "") then return end local playerTo = getPlayerFromPartOfName(toWho) if (not isElement(playerTo)) then outputChatBox("This player is not online.",thePlayer,255,0,0) return end local cash = tonumber(cash) if getPlayerMoney(thePlayer) >= cash then outputChatBox("You have sent $".. tostring(cash) .." to ".. tostring(getPlayerName(playerTo)),thePlayer,0,255,0) outputChatBox(tostring(getPlayerName(thePlayer)) .." has sent you $".. tostring(cash) ..".",playerTo,0,255,0) givePlayerMoney(playerTo, cash) takePlayerMoney(thePlayer, cash) else outputChatBox("You don't have $".. tostring(cash) ..".",thePlayer,255,0,0) end end) function getPlayerFromPartOfName(thePlayerName) local thePlayer = getPlayerFromName(thePlayerName) if thePlayer then return thePlayer end for _,thePlayer in ipairs(getElementsByType("player")) do if string.find(string.gsub(getPlayerName(thePlayer):lower(),"#%x%x%x%x%x%x", ""), thePlayerName:lower(), 1, true) then return thePlayer end end return false end I also changed the part of name function to get it even if is upper case. Link to comment
Hilmer97 Posted November 24, 2011 Author Share Posted November 24, 2011 Its working thanks man! ! ! 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