[Solved] This script for transfert money

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)

Please, help guys ! :slight_smile:

1 Like

Yes this script can be useful !

1 Like

Can i say in tchat : /pay 2 20000
Don’t have anything :confused:

I m trying to make a money transaction script too so i m also pretty interested

If you succes your script, can you share ? :slight_smile:

For sure i ll share it

1 Like

I am interested in the design of this script, if a charitable soul would have a solution to propose

Sorry for my bad English

If someone find the solution we would love him to release it

Very rare are the people who share their code, he thinks to make money on codes while multiple free gamemode will see the day

RegisterEvent('CheckMoney')

Change this line to

RegisterServerEvent('CheckMoney')

It works fine after that.

1 Like

is this working? its a much needed script

With the changes I posted the script works.

Can this be marked solved now?

I have a money transfert that work with proximity player i’ll probably release it :slight_smile:

2 Likes

@TrinnityRE Please release it. Or if you have show me where. I need this so badly.

what version are you using of es_extended? if 1.1.0 and in any ESX framework you dont need to use user you have to use ESX.setMoney you can look up in the esx documentation and you might need to define the xPlayer usualy the its local xPlayer = ESX.GetPlayerFromId(source), you don’t need to define the source its already defined in the ESX by default it will understand that the source is you but i recommend you just change the source to the players argument because you want to set other players money not yourself and somehow get its source. Hope its helpfull

Can you post a working version for people to download, as long as OP is ok with that