Hi, I have a question because this script doesn’t work and I don’t know why. Can you help me with? It’s a script to transfer money between 2 players with this command: /pay [ID] [AMOUNT]
--commande joueur
TriggerEvent("es:addCommand", "pay", function(source, args, user)
if (args[2] ~= nil and tonumber(args[3]) > 0) then
local sourceID = tonumber(source)
local receptionID = tonumber(args[2])
local demande = tonumber(args[3])
TriggerEvent('CheckMoney', sourceID, receptionID, demande)
else
TriggerEvent("chatMessage", "", { 0, 0, 0 }, "Utilisation : /pay id montant")
end
end)
RegisterEvent('CheckMoney')
--verifie et fait le transfert joueur
AddEventHandler('CheckMoney', function(sourceID, receptionID, demande)
TriggerEvent('es:getPlayerFromId', sourceID, function(user)
--regarde si il a assez d'argent
if (tonumber(user.money) >= tonumber(demande)) then
-- si oui fait le virement
local player = user.identifier
user:removeMoney((demande))
TriggerEvent('es:getPlayerFromId', receptionID, function(user2)
local player2 = user2.identifier
user2:addMoney((demande))
TriggerClientEvent("chatMessage", receptionID , "MAZE BANK", { 0, 0, 0 }, "Vous avez recu "..demande.."€")
TriggerClientEvent("chatMessage", sourceID, "MAZE BANK", { 0, 0, 0 }, "Vous avez payé "..demande.."€")
end)
else
-- sinon informe le joueur
if (tonumber(user.money) < tonumber(demande)) then
TriggerClientEvent("chatMessage", player, "", { 0, 0, 0 }, "Tu n'as pas assez d'argent")
end
end
end)
end)
-- commande admin
TriggerEvent('es:addGroupCommand', 'setmoney', "admin", function(source, args, user)
if #args ~= 2 then
TriggerClientEvent('chatMessage', source, "CONSOLE", {0, 0, 0}, "Utilisation: /setmoney [user-id] [money]\n")
CancelEvent()
return
end
if(GetPlayerName(tonumber(args[1])) == nil)then
TriggerClientEvent('chatMessage', source, "CONSOLE", {0, 0, 0}, "Joueur non connecté")
RconPrint("Player not ingame\n")
CancelEvent()
return
end
TriggerEvent("es:getPlayerFromId", tonumber(args[1]), function(user)
if(user)then
user:setMoney((args[2] + 0.0))
TriggerClientEvent('chatMessage', tonumber(args[1]), "CONSOLE", {0, 0, 0}, "Your money has been set to: $" .. tonumber(args[2]))
end
end)
end, function(source, args, user)
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficienct permissions!")
end)