Jump to content

Part of name


TheIceman1

Recommended Posts

When I do / iceman give 100, but then nothing happens, then I do / give TheIceman 100 then I get a message "You sent $100...", how to do that ,when i do /give iceman(part of name) 100 then players get the money?

function givemoney(player, _, to, ...) 
     local money = table.concat({...}," ") 
     local personToReceive = getPlayerFromName(to) 
     if personToReceive then 
    givePlayerMoney ( personToRecieve, tonumber(money) ) 
    takePlayerMoney ( player, tonumber(money) ) 
    exports ["guimessages"] : outputServer ( player, "You sent $ ".. money .." to "..getPlayerName(player).."!" , 255, 255, 0 ) 
    exports ["guimessages"] : outputServer ( personToReceive, getPlayerName(player).." sent $"..money.." you!", 255, 255, 0 ) 
     end 
end 
addCommandHandler ( "give", givemoney ) 

Link to comment

Try this

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 
  
function givemoney(player, _, to, ...) 
     local money = table.concat({...}," ") 
     local personToReceive = getPlayerFromNamePart(to) 
     if personToReceive then 
    givePlayerMoney ( personToRecieve, tonumber(money) ) 
    takePlayerMoney ( player, tonumber(money) ) 
    exports ["guimessages"] : outputServer ( player, "You sent $ ".. money .." to "..getPlayerName(player).."!" , 255, 255, 0 ) 
    exports ["guimessages"] : outputServer ( personToReceive, getPlayerName(player).." sent $"..money.." you!", 255, 255, 0 ) 
     end 
end 
addCommandHandler ( "give", givemoney ) 

Link to comment
Try this
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 
  
function givemoney(player, _, to, ...) 
     local money = table.concat({...}," ") 
     local personToReceive = getPlayerFromNamePart(to) 
     if personToReceive then 
    givePlayerMoney ( personToRecieve, tonumber(money) ) 
    takePlayerMoney ( player, tonumber(money) ) 
    exports ["guimessages"] : outputServer ( player, "You sent $ ".. money .." to "..getPlayerName(player).."!" , 255, 255, 0 ) 
    exports ["guimessages"] : outputServer ( personToReceive, getPlayerName(player).." sent $"..money.." you!", 255, 255, 0 ) 
     end 
end 
addCommandHandler ( "give", givemoney ) 

Working,thanks!

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...