Jump to content

How to make the next script:


Hilmer97

Recommended Posts

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
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 :P 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 :P

Link to comment

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
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 :P

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...