McDeKi Posted March 22, 2014 Share Posted March 22, 2014 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
WhoAmI Posted March 22, 2014 Share Posted March 22, 2014 In zapisEq function change client to source. Link to comment
McDeKi Posted March 22, 2014 Author Share Posted March 22, 2014 It doesnt matter it works with onClientResourceStop function zamienNaString() triggerServerEvent("ZapiszPrzedmioty", getLocalPlayer(), table.concat(zapiszEkwipunek(), "|")) end addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), zamienNaString) Link to comment
pa3ck Posted March 22, 2014 Share Posted March 22, 2014 Do you get any errors in /debugscript 3? Also, are you sure you need to update it? Did you insert it first? Link to comment
McDeKi Posted March 22, 2014 Author Share Posted March 22, 2014 No errors, the event is not triggered to server from client Link to comment
WhoAmI Posted March 23, 2014 Share Posted March 23, 2014 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
MIKI785 Posted March 23, 2014 Share Posted March 23, 2014 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. 1 Link to comment
McDeKi Posted March 23, 2014 Author Share Posted March 23, 2014 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
MIKI785 Posted March 23, 2014 Share Posted March 23, 2014 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. Link to comment
McDeKi Posted March 23, 2014 Author Share Posted March 23, 2014 What then? Should I send inventory to server for example when I add new item or change position of it? Link to comment
MIKI785 Posted March 23, 2014 Share Posted March 23, 2014 Yeah, that seems to be the simplest solution. Link to comment
McDeKi Posted March 23, 2014 Author Share Posted March 23, 2014 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 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now