Jump to content

Problem with onPlayerQuit


McDeKi

Recommended Posts

Posted

Hello again!

I'm doing save system for my inventory, almost everything works perfect, but I must trigger client event to get player inventory to save it in MySQL base.

  
--//Serverside 
function ZapiszEQ(StringEQ) 
    local mysqlId = getElementData(client, "mysqlNick") 
    local EQ = exports.SQL:zapytanie("UPDATE dane SET EKWIPUNEK=? WHERE IMIE=?", StringEQ, mysqlId) 
    outputServerLog("Gracz o nicku: "..getPlayerName( source ).." zapisal swoj ekwipunek na konto: "..getElementData(source, "mysqlNick")) 
end 
addEvent("ZapiszPrzedmioty", true) 
addEventHandler("ZapiszPrzedmioty", root, ZapiszEQ) 
  
function GraczWyszedl() 
    triggerClientEvent(source, "GraczWyszedl", root ) 
end 
addEventHandler("onPlayerQuit", root, GraczWyszedl)  
--//This event is in the another resource than inventory. 
  

  
--//Clientside 
function SaveEQ() 
    triggerServerEvent("ZapiszPrzedmioty", getLocalPlayer(), table.concat(zapiszEkwipunek(), "|")) 
end 
addEvent("GraczWyszedl", true) 
addEventHandler("GraczWyszedl", root, SaveEQ) 
  

It doesnt work. I think the event is not triggered because the element of player got removed, any advice to fix it, I have tried doing it with "onPlayerClientQuit" but this event doesnt work like "onPlayerQuit".

Posted

It doesnt matter it works with onClientResourceStop

  
function zamienNaString() 
    triggerServerEvent("ZapiszPrzedmioty", getLocalPlayer(), table.concat(zapiszEkwipunek(), "|")) 
end 
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), zamienNaString) 
  

Posted

Server

function ZapiszEQ ( StringEQ ) 
    local mysqlId = getElementData ( source, "mysqlNick" ) 
    local EQ = exports.SQL:zapytanie ( "UPDATE dane SET EKWIPUNEK=? WHERE IMIE=?", StringEQ, mysqlId ) 
    outputServerLog( "Gracz o nicku: ".. getPlayerName ( source ) .." zapisal swoj ekwipunek na konto: " .. mysqlId ) 
end 
addEvent ( "ZapiszPrzedmioty", true ) 
addEventHandler ( "ZapiszPrzedmioty", root, ZapiszEQ ) 
  
function GraczWyszedl ( ) 
    triggerClientEvent ( source, "GraczWyszedl", root ) 
end 
addEventHandler ( "onPlayerQuit", root, GraczWyszedl )   

Client

function SaveEQ ( )  
    triggerServerEvent ( "ZapiszPrzedmioty", localPlayer, table.concat ( zapiszEkwipunek ( ), "|" ) ) 
end 
addEvent ( "GraczWyszedl", true ) 
addEventHandler ( "GraczWyszedl", root, SaveEQ ) 

If it doesn't work show me 'zapiszEkwipunek' funciton.

Posted

That's probably because when the GraczWyszedl is called the client might have been already disconnected so it doesn't call back the server event. I'm not too sure about this but it might be the cause.

  • Thanks 1
Posted

It isnt working

  
--//Zapis przedmiotow\\-- 
function zapiszEkwipunek() 
 local PrzedmiotyDoZapisania = {} 
    for k,v in pairs( Plecak )do 
        for i=1, wysokoscY do 
          if not (Plecak[k][i] == false) then 
             table.insert(PrzedmiotyDoZapisania, k..","..i..","..Plecak[k][i].id) 
            end 
        end 
    end 
    return PrzedmiotyDoZapisania 
end 
  

As I said it works when the resource stop

  
function zamienNaString() 
    triggerServerEvent("ZapiszPrzedmioty", getLocalPlayer(), table.concat(zapiszEkwipunek(), "|")) 
end 
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), zamienNaString) 
  

Posted

If what i posted before is the cause then it doesn't matter if onClientResourceStop works or not, it's obvious that it will work as the client is connected.

Posted

Well, my inventory has 40 slots (max) and the string can be long for 159 chars, due to inventory is in format: X,Y,ID|X,Y,ID

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...