Jump to content

onClientPlayerQuit is not working!


tommymaster

Recommended Posts

Hi!
I want to list a client-sided table when a player disconnects. 

 

--client
items = {}
items[1] = "1"
items[2] = "2"

function saveItems()
	triggerServerEvent ("listItems", source, items)
end
addEventHandler ("onClientPlayerQuit", root, saveItems)
--server
function listItems(items)
	outputServerLog (""..items..":"..getPlayerName(source).."")
	iprint (""..items..":"..getPlayerName(source).."")
	outputDebugString (""..items..":"..getPlayerName(source).."")
end
addEvent ("listItems", true)
addEventHandler ("listItems", root, listItems)

I can't see the message at all in the server console.

Link to comment

Because this event can't use detect if the player quit and this player is himself... This event can use to detect other clients quite in client side...
With onClientResourceStop () you can do it, if you want to push the local data to serverside, in this case:
 

--- Client side

items = {1,2}


function saveItems()
	triggerServerEvent ("listItems", localPlayer, items)
end
addEventHandler ("onClientResourceStop", resourceRoot, saveItems)

Serverside should be good, but I have doubt about get the player name... Anyway, you can read all of these usefull advice in wiki, It's good to use it... You can read also great examples and I'ts always uptodate.

  • Thanks 1
Link to comment
16 hours ago, Awang said:

Because this event can't use detect if the player quit and this player is himself... This event can use to detect other clients quite in client side...
With onClientResourceStop () you can do it, if you want to push the local data to serverside, in this case:
 


--- Client side

items = {1,2}


function saveItems()
	triggerServerEvent ("listItems", localPlayer, items)
end
addEventHandler ("onClientResourceStop", resourceRoot, saveItems)

Serverside should be good, but I have doubt about get the player name... Anyway, you can read all of these usefull advice in wiki, It's good to use it... You can read also great examples and I'ts always uptodate.

Thanks. It seems to work this way. I want to see the items of the table, but it outputs like "table: 0x......." in the log instead the items of the table. How may i fix this?

Link to comment
5 hours ago, tommymaster said:

Thanks. It seems to work this way. I want to see the items of the table, but it outputs like "table: 0x......." in the log instead the items of the table. How may i fix this?

use 

for i, v in iparis(Itens) do
  outputChatBox( tostring(v), source)
end

 

  • Thanks 1
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...