function findPlayer(name)
local matches = {}
for i,v in ipairs(getElementsByType("player")) do
if getPlayerName(v) == name then
return v
end
local playerName = getPlayerName(v):gsub("#%x%x%x%x%x%x", "")
playerName = playerName:lower()
if playerName:find(name:lower(), 0) then
table.insert(matches, v)
end
end
if #matches == 1 then
return matches[1]
end
return false
end
addCommandHandler("give",
function(player, cmd, name, amount)
local amount = tonumber(amount)
if name and amount and amount > 0 and math.floor(amount) == amount then -- bugfix
local targetid = findPlayer(name)
local money = getPlayerMoney(player)
if targetid ~= false then
if money >= amount then
takePlayerMoney(player, amount)
givePlayerMoney(target, amount)
outputChatBox("You gave " .. getPlayerName(target) .. " $" .. amount .. ".", player, 0, 255, 0, false)
outputChatBox(getPlayerName(player) .. " gave you $" .. amount .. ".", target, 0, 255, 0, false)
else
outputChatBox("You do not have enough money.", player, 255, 0, 0, false)
end
end
end
end
)