Mahlukat

[Help] onClientResourceStop

Recommended Posts

Hey

i want to save table in client-side when localPlayer disconnected

--client
addEventHandler( "onClientResourceStop", resourceRoot,function()

	triggerServerEvent("Freeroam:SureKaydet", localPlayer, sureVerileri, true)
	
    if sureVerileri[localPlayer] and isTimer(sureVerileri[localPlayer].timer) then 
		killTimer(sureVerileri[localPlayer].timer) 
	end
end)
--server
addEvent("Freeroam:SureKaydet", true)
addEventHandler("Freeroam:SureKaydet", root, function(sureVerileri,bosmu)
	outputServerLog("triggered server") -- i can't see this message in console
	local hesap = getPlayerAccount(source)
	if not isGuestAccount(hesap) then
		outputServerLog("not guest")
		local sure = 60*10
		if sureVerileri[source] and sureVerileri[source].sure then
			sure = sureVerileri[source].sure
		end	
		exports.Hesaplar:SAD(hesap, "KiralikSure", sure)
		
		outputServerLog("saved.")
		outputServerLog(sure)
		
		if bosmu then
			exports.Hesaplar:SAD(hesap, "KiralikSureBos", true)
		end	
	end
end)

but event isn't triggered :(( how can ido it?

-
 

Share this post


Link to post

did you tried to use onClientPlayerQuit ?

 

https://wiki.multitheftauto.com/wiki/OnClientPlayerQuit

 

Edited by _Evo_

Share this post


Link to post

try this

-- Client
function SureKaydet ()
	triggerServerEvent("Freeroam:SureKaydet", localPlayer, sureVerileri, true)
	 if sureVerileri[localPlayer] and isTimer(sureVerileri[localPlayer].timer) then 
		killTimer(sureVerileri[localPlayer].timer) 
		end
	end
addEventHandler( "onClientPlayerQuit", getRootElement(), SureKaydet )
-- server
function SureKaydet (sureVerileri,bosmu)
outputServerLog("triggered server")
local hesap = getPlayerAccount(source)
if isGuestAccount(hesap) then return false end
outputServerLog("not guest")
		local sure = 60*10
		if sureVerileri[source] and sureVerileri[source].sure then
			sure = sureVerileri[source].sure
			end
			exports.Hesaplar:SAD(hesap, "KiralikSure", sure)
		
		outputServerLog("saved.")
		outputServerLog(sure)
		
		if bosmu then
			exports.Hesaplar:SAD(hesap, "KiralikSureBos", true)
			end
		end
		addEvent("Freeroam:SureKaydet", true)
		addEventHandler("Freeroam:SureKaydet", getRootElement(), SureKaydet)
			

 

Share this post


Link to post
4 hours ago, _Evo_ said:

did you tried to use onClientPlayerQuit ?

 


https://wiki.multitheftauto.com/wiki/OnClientPlayerQuit

 

Yea, i tried but wiki said;
This event is triggered when a remote player quits the game or leaves the server. It will not get triggered on the source player's client. (Use onClientResourceStop to save client side data when the local player quits.)

 

19 minutes ago, xMKHx said:

try this


-- Client
function SureKaydet ()
	triggerServerEvent("Freeroam:SureKaydet", localPlayer, sureVerileri, true)
	 if sureVerileri[localPlayer] and isTimer(sureVerileri[localPlayer].timer) then 
		killTimer(sureVerileri[localPlayer].timer) 
		end
	end
addEventHandler( "onClientPlayerQuit", getRootElement(), SureKaydet )

-- server
function SureKaydet (sureVerileri,bosmu)
outputServerLog("triggered server")
local hesap = getPlayerAccount(source)
if isGuestAccount(hesap) then return false end
outputServerLog("not guest")
		local sure = 60*10
		if sureVerileri[source] and sureVerileri[source].sure then
			sure = sureVerileri[source].sure
			end
			exports.Hesaplar:SAD(hesap, "KiralikSure", sure)
		
		outputServerLog("saved.")
		outputServerLog(sure)
		
		if bosmu then
			exports.Hesaplar:SAD(hesap, "KiralikSureBos", true)
			end
		end
		addEvent("Freeroam:SureKaydet", true)
		addEventHandler("Freeroam:SureKaydet", getRootElement(), SureKaydet)
			

 

thanks for help but it's still not triggered :((

Share this post


Link to post

Probably because the custom event you try to trigger is too late. The player has already left the game.

 

Streaming data might be your only option.

Share this post


Link to post

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.