Jump to content

Problem with onPlayerQuit


McDeKi

Recommended Posts

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

Link to comment

It doesnt matter it works with onClientResourceStop

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

Link to comment

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.

Link to comment

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) 
  

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