[Request][Help] Player disconnects need script to save money


#1

Hello, using essentialsmode(mysql) and es_freeroam1.3? so i can use police job.

But having and issue whenever i disconnect it sets my money (on Hand) in db to 0. No matter if +100 or -3000 it goes to 0.

So looking for a script that would save when a player disconnects.

Thanks allot of any help.


#2

essentialmode/server/main.lua

AddEventHandler(‘playerDropped’, function()
if(Users[source])then
TriggerEvent(“es:playerDropped”, Users[source])

  db.updateUser(Users[source].identifier, {money = Users[source].money, Users[source].bank}, function()
  	Users[source] = nil
  end)

end
end)

By default it’s supposed to be there.


#3

Thanks allot, it was changed. not sure if old version or what but it wasn’t what you posted. Been trying to figure out the cause for hours apon hours now.


#4

i narrowed down to line 54, but wasn’t sure what to do to fix it, so thanks allot.


#5

Thats for mysql right? just to confirm.

just checked new version, and it same :frowning:

need fix for mysql not sure what going on.


#6

is in mysql version.

AddEventHandler('playerDropped', function()
	if(Users[source])then
		TriggerEvent("es:playerDropped", Users[source])

		MySQL:executeQuery("UPDATE users SET `money`='@value' WHERE identifier = '@identifier'",
		{['@value'] = 0, ['@identifier'] = Users[source].identifier})

		Users[source] = nil
	end
end)

is

{['@value'] = 0

setting db to 0?


#8

My files for MySQL version with bonus to put any car in garage when player disconnect.

AddEventHandler(‘playerDropped’, function()
if(Users[source])then
TriggerEvent(“es:playerDropped”, Users[source])

MySQL:executeQuery("UPDATE users SET `money`='@value' WHERE identifier = '@identifier'",
{['@value'] = Users[source].money, ['@identifier'] = Users[source].identifier})

MySQL:executeQuery("UPDATE user_vehicle SET vehicle_state='Rentré' WHERE identifier = '@identifier'",
{['@identifier'] = Users[source].identifier})
Users[source] = nil

end
end)


#9

Thanks much, i’m literally just testing out

MySQL:executeQuery("UPDATE users SET `money`='@value' WHERE identifier = '@identifier'",
		{['@value'] = Users[source].money, ['@identifier'] = Users[source].identifier})

		Users[source] = nil

that i found,


#10

and it worked, thanks allot.


#11

hi, i follow your code but it seem to not working. Where do i place the code exactly? do i need to require mysql inorder for this code to work? I am trying to spawn back the car after user disconnected. Thank you!