Jump to content

Turbesz

Members
  • Posts

    245
  • Joined

  • Last visited

Everything posted by Turbesz

  1. if i use localPlayer, then the objects are visible to the local player only?
  2. Um i send now the whole table, and i get these warnings: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] Bad argument @ 'getAccountName' [Expected element at argument 1, got nil] client: function loadMapData (fileName) local menteshez = xml:xmlLoadData ( fileName, true, true) triggerServerEvent("load2",localPlayer,playerSource,menteshez) end addEvent("sbetolt",true) addEventHandler("sbetolt",root,loadMapData) server: function teszt2(thePlayer,menteshez) local account = getPlayerAccount(thePlayer) local accountName = getAccountName(account) local object=getElementsByType("object") local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) for i,v in ipairs(getElementsByType("object")) do if getElementData(v,"owner") == accname then destroyElement(v) end end setTimer(function() for k, v in ipairs(menteshez) do if v[5] == accname then id = id+1 local x, y, z = getElementPosition(thePlayer) local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) targy = createObject(v[4], v[1], v[2], v[3]) setElementData(targy, "owner", accname) setElementData(targy,"id",id) setElementInterior(targy,v[6]) setElementDimension(targy,v[7]) setElementRotation(targy,v[8],v[9],v[10]) setElementData(thePlayer,"torles",getElementData(targy,"id") or 0) outputChatBox("betöltve") end end end,500,1) end addEvent("load2",true) addEventHandler("load2",root,teszt2) why do i get those warnings?
  3. i tried make a new trigger to load from client to server, and then create the objects, but does not work server: function testLoad (thePlayer) local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) triggerClientEvent(thePlayer,"sbetolt", thePlayer, "save"..base64Encode(accname), menteshez) end addCommandHandler("load",testLoad) function teszt2(thePlayer,x,y,z,id,owner,int,dim,Rx,Ry,Rz) local object=getElementsByType("object") local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) for i,v in ipairs(getElementsByType("object")) do if getElementData(v,"owner") == owner then destroyElement(v) end end if owner == accname then id = id+1 local x, y, z = getElementPosition(thePlayer) local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) targy = createObject(id, x, y,z) setElementData(targy, "owner", accname) setElementData(targy,"id",id) setElementInterior(targy,int) setElementDimension(targy,dim) setElementRotation(targy,Rx,Ry,Rz) setElementData(thePlayer,"torles",getElementData(targy,"id") or 0) outputChatBox("betöltve") end end addEvent("load2",true) addEventHandler("load2",root,teszt2) client: function loadMapData (fileName) local menteshez = xml:xmlLoadData ( fileName, true, true) for k, v in ipairs(menteshez) do --outputChatBox(v[1]) local x = v[1] local y = v[2] local z = v[3] local id = v[4] local owner = v[5] local int = v[6] local dim = v[7] local Rx = v[8] local Ry = v[9] local Rz = v[10] triggerServerEvent("load2",localPlayer,playerSource,x,y,z,id,owner,int,dim,Rx,Ry,Rz) end end addEvent("sbetolt",true) addEventHandler("sbetolt",root,loadMapData) what wrong?
  4. okay, i replaced them with trigger events, and triggers are working fine but how can i get datas in load func? function testLoad (thePlayer) local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) triggerClientEvent(thePlayer,"sbetolt", thePlayer, "save"..base64Encode(accname), menteshez) end addCommandHandler("load",testLoad)
  5. How can this be done? Or how can i easily move the save and load funcs to client side?
  6. Thank you, save and load working fine now Btw, can't that cause some issues that it's saving the XML file on the server and not on the players PC? Because over time it can be up to more than 1000, or 2000 XML file (if we look at that my server has ~4000 registered account, and every player can register only one)
  7. Um, yes(?) This is my current code of save func: local menteshez = {} local xml = exports.xmldata function teszt(thePlayer) local object=getElementsByType("object") local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) local menteshez = xml:xmlLoadData("save" .. accname, true) if not menteshez then xml:xmlSaveData("save" .. accname, {}, false, true) return end for k, v in ipairs(object) do if getElementData(v,"owner") == accname then local x,y,z = getElementPosition(v) local id = getElementModel(v) local owner = getElementData(v,"owner") or getAccountName(theAcc) local int = getElementInterior(v) local dim = getElementDimension(v) local Rx,Ry,Rz = getElementRotation ( v ) outputChatBox("mentve") menteshez[v] = {x,y,z,id,owner,int,dim,Rx,Ry,Rz} setCustomData(thePlayer, "menteshez", menteshez, true) end end local menteshez = getCustomData(thePlayer, "menteshez", true) local account = getPlayerAccount(thePlayer) local accountName = getAccountName(account) xml:xmlSaveData("save" .. accountName, reformatToArray(menteshez), false, true) end addCommandHandler("save",teszt)
  8. that's how I added: xml:xmlSaveData("save" .. accountName, reformatToArray(menteshez), false, true) but i get the error
  9. i tried to modify 'menteshez' to 'reformatToArray(menteshez)' but then i get this error: bad argument #1 to 'pairs' (table expected got nil) the error refers to this loop in 'reformatToArray' func: for k, data in pairs(theTable) do table.insert(array, data) end
  10. uh that's true, my bad! now i don't get any errors or warnings, and the file was created, but does not insert the script any data to that file, i just get only "<root></root>" as a result in my .xml file
  11. now without double dots i got this error in save func: Error @xmlSaveData, arg 2 - table for tblData expected, got nil local menteshez = {} local xml = exports.xmldata function teszt(thePlayer) local object=getElementsByType("object") local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) if not getCustomData(thePlayer, "menteshez", true) then setCustomData(thePlayer, "menteshez", {}, true) end for k, v in ipairs(object) do if getElementData(v,"owner") == accname then local x,y,z = getElementPosition(v) local id = getElementModel(v) local owner = getElementData(v,"owner") or getAccountName(theAcc) local int = getElementInterior(v) local dim = getElementDimension(v) local Rx,Ry,Rz = getElementRotation ( v ) outputChatBox("mentve") menteshez[v] = {x,y,z,id,owner,int,dim,Rx,Ry,Rz} setCustomData(thePlayer, "menteshez", menteshez, true) end end local menteshez = getCustomData(thePlayer, "menteshez", true) xml:xmlSaveData("save" .. accname, menteshez, false, true) end addCommandHandler("save",teszt)
  12. Yes, i checked it already, so this is not the problem
  13. The xml file? Im sure, because this is a server sided script, need it should be there in the xmldata folder in the script, and give a feedback in the debugscript (it doesn't happen too). What wrong with that line?
  14. now i changed this line menteshez = {x,y,z,id,owner,int,dim,Rx,Ry,Rz} to this: menteshez[v] = {x,y,z,id,owner,int,dim,Rx,Ry,Rz} now i don't get any errors, warnings but the xml:xmlSaveData("save:" .. accountName, menteshez, false, true) line does not work, does not create the file and when i want to load with this code: function teszt2(thePlayer) local account = getPlayerAccount(thePlayer) local accname = getAccountName(account) local menteshez = xml:xmlLoadData("save:" .. accname, true) if not menteshez then xml:xmlSaveData("save:" .. accname, {}, false, true) end local object=getElementsByType("object") for i,v in ipairs(getElementsByType("object")) do if getElementData(v,"owner") == accname then destroyElement(v) end end for k, v in ipairs(menteshez) do if v[5] == accname then targy = createObject(v[4], v[1], v[2], v[3]) setElementData(targy, "owner", accname) setElementInterior(targy,v[6]) setElementDimension(targy,v[7]) setElementRotation(targy,v[8],v[9],v[10]) outputChatBox("betöltve") end end end then i got this error: bad argument #1 to ipairs (table expected got nil) >> line 17
  15. i added the code from tutorial, then i tried this: local menteshez = {} local xml = exports.xmldata function teszt(thePlayer) local object=getElementsByType("object") local theAcc = getPlayerAccount(thePlayer) local accname = getAccountName(theAcc) if not getCustomData(thePlayer, "menteshez", true) then setCustomData(thePlayer, "menteshez", {}, true) end for k, v in ipairs(object) do if getElementData(v,"owner") == accname then local x,y,z = getElementPosition(v) local id = getElementModel(v) local owner = getElementData(v,"owner") or getAccountName(theAcc) local int = getElementInterior(v) local dim = getElementDimension(v) local Rx,Ry,Rz = getElementRotation ( v ) local masikid = getElementData(v,"id") outputChatBox("mentve") menteshez = {x,y,z,id,owner,int,dim,Rx,Ry,Rz} setCustomData(thePlayer, "menteshez", menteshez, true) end end local menteshez = getCustomData(thePlayer, "menteshez", true) local account = getPlayerAccount(thePlayer) local accountName = getAccountName(account) xml:xmlSaveData("save:" .. accountName, menteshez, false, true) end addCommandHandler("save",teszt) and i got this error: Error @xmlSaveData, arg 2 - table for tblData expected, got nil
  16. i think this loop cause the problem: for element, data in pairs(menteshez) do if not isElement(element) then menteshez[element] = nil end end i tried to get inserted acc name and then remove the objects created by local player, but same problem. remove all player objects, not just local for element, data in pairs(menteshez) do if data[5] == accname then if not isElement(element) then menteshez[element] = nil end end end what wrong?
  17. um, where should i put these lines in my code? setCustomData(player, "menteshez", menteshez, true) -- localized local menteshez = getCustomData(player, "menteshez", true) -- localized
  18. thanks, now works but if another player save the data, mine data will also be deleted, how to fix this?
  19. i know buut because i use Ceeser's xmldata script to save the datas to XML, i got this warning: with this code: local xml = exports.xmldata function teszt(thePlayer) local object=getElementsByType("object") for element, data in pairs(menteshez) do if not isElement(element) then menteshez[element] = nil end end for k, v in ipairs(object) do if getElementData(v,"owner") == thePlayer then local x,y,z = getElementPosition(v) local id = getElementModel(v) local int = getElementInterior(v) local dim = getElementDimension(v) local Rx,Ry,Rz = getElementRotation ( v ) outputChatBox("saved") menteshez[v] = {x,y,z,id,owner,int,dim,Rx,Ry,Rz} end end xml:xmlSaveData("save", menteshez, false, true) end addCommandHandler("save",teszt)
  20. i tried this: table.insert(menteshez,{x,y,z,id,owner,int,dim,Rx,Ry,Rz}) reformatToArray(menteshez) but the remove in this loop: for element, data in pairs(menteshez) do if not isElement(element) then table.remove(menteshez,element) end end still not work properly
  21. now i tried change menteshez[element] to table.remove and menteshez[v] to table.insert in loops so now i don't get any warning from the xmldata script but the remove does not work properly in my script again
  22. Huh, thank you! I use Ceeser's xmldata script to save to xml, and now with the new method the xml save does not work i got this warning: warning: checkDataType for xmlSaveData - MTA elements should be stored since they have a temporary ID! Got userdata wth? this is my code: local xml = exports.xmldata function teszt(thePlayer) local object=getElementsByType("object") for element, data in pairs(menteshez) do if not isElement(element) then menteshez[element] = nil end end for k, v in ipairs(object) do if getElementData(v,"owner") == thePlayer then local x,y,z = getElementPosition(v) local id = getElementModel(v) local int = getElementInterior(v) local dim = getElementDimension(v) local Rx,Ry,Rz = getElementRotation ( v ) outputChatBox("saved") menteshez[v] = {x,y,z,id,owner,int,dim,Rx,Ry,Rz} end end xml:xmlSaveData("save", menteshez, false, true) end addCommandHandler("save",teszt)
  23. I created a table on server side, and the players can insert data to the table on server side with a command. But i want to make a function which removes the player (who typed the cmd) data from the table, not all players data. I tried table.remove in many ways but none of them worked... My current code, with the table.insert part: local menteshez = {} function teszt(thePlayer) local object=getElementsByType("object") for k, v in ipairs(object) do if getElementData(v,"owner") == thePlayer then local x,y,z = getElementPosition(v) local id = getElementModel(v) local int = getElementInterior(v) local dim = getElementDimension(v) local Rx,Ry,Rz = getElementRotation ( v ) outputChatBox("saved") table.remove(menteshez,k) -- this does not do anything... table.insert(menteshez,{x,y,z,id,int,dim,Rx,Ry,Rz}) -- but this works fine end end end addCommandHandler("save",teszt)
  24. How can i remove from table the local player's object data? Because if i save a second time, the object spawn twice when i load it i tried table.remove, but does not fix this problem local menteshez = {} function teszt(thePlayer) local object=getElementsByType("object") for k, v in ipairs(object) do if getElementData(v,"owner") == thePlayer then local x,y,z = getElementPosition(v) local id = getElementModel(v) local int = getElementInterior(v) local dim = getElementDimension(v) local Rx,Ry,Rz = getElementRotation ( v ) outputChatBox("saved") table.remove(menteshez,k) table.insert(menteshez,{x,y,z,id,int,dim,Rx,Ry,Rz}) end end end addCommandHandler("save",teszt)
  25. and can't that cause some issues that it's saving the XML file on the server and not on the players PC?
×
×
  • Create New...