Turbesz Posted November 29, 2020 Author Share Posted November 29, 2020 (edited) 3 minutes ago, Tekken said: why with bindKey and ton with onElementClicked ? because i don't know can i do this in the onElementClicked func with a key Edited November 29, 2020 by Turbesz Link to comment
Tekken Posted November 29, 2020 Share Posted November 29, 2020 oh yeah you're right try this function clickfunc(button, state, player) if button == "left" and state == "down" then if getElementType(source) == "object" and getElementData(source, "owner") == player then local x, y, z = getElementPosition(source); local model = getElementModel(source); bindKey(player, "arrow_u", "down", mozgatas, source); setElementData(source, "mozgathato", true); end end end function mozgatas(player, key, state, element) if getElementData(element, "owner") == player and getElementData(element, "mozgathato") then local x,y,z = getElementPosition(element); setElementPosition(element, x, y-0.5, z); end end 1 Link to comment
Turbesz Posted November 29, 2020 Author Share Posted November 29, 2020 (edited) 10 minutes ago, Tekken said: oh yeah you're right try this function clickfunc(button, state, player) if button == "left" and state == "down" then if getElementType(source) == "object" and getElementData(source, "owner") == player then local x, y, z = getElementPosition(source); local model = getElementModel(source); bindKey(player, "arrow_u", "down", mozgatas, source); setElementData(source, "mozgathato", true); end end end function mozgatas(player, key, state, element) if getElementData(element, "owner") == player and getElementData(element, "mozgathato") then local x,y,z = getElementPosition(element); setElementPosition(element, x, y-0.5, z); end end ups, my bad. now all object moving if i press arrow_up key Edited November 29, 2020 by Turbesz Link to comment
Turbesz Posted November 29, 2020 Author Share Posted November 29, 2020 27 minutes ago, Tekken said: oh yeah you're right try this function clickfunc(button, state, player) if button == "left" and state == "down" then if getElementType(source) == "object" and getElementData(source, "owner") == player then local x, y, z = getElementPosition(source); local model = getElementModel(source); bindKey(player, "arrow_u", "down", mozgatas, source); setElementData(source, "mozgathato", true); end end end function mozgatas(player, key, state, element) if getElementData(element, "owner") == player and getElementData(element, "mozgathato") then local x,y,z = getElementPosition(element); setElementPosition(element, x, y-0.5, z); end end oh i fixed, now working fine, thank youu but the debugscript flood this: bad argument @ 'getElementData' [Expected element at argument 1] why? Link to comment
Turbesz Posted November 29, 2020 Author Share Posted November 29, 2020 2 minutes ago, Tekken said: What line ? this: if getElementData(element, "owner") == player and getElementData(element, "mozgathato") then in the bindkey func Link to comment
Tekken Posted November 29, 2020 Share Posted November 29, 2020 hmm show entire function 1 Link to comment
Turbesz Posted November 29, 2020 Author Share Posted November 29, 2020 6 hours ago, Tekken said: hmm show entire function i fixed that meanwhile, thank you the help btw how can i save the objects? because if i restart the server or the script, the objects are deleted (but if i reconnect then no) Link to comment
Tekken Posted November 29, 2020 Share Posted November 29, 2020 You have to create a database SQL or XML will work. Link to comment
Turbesz Posted November 29, 2020 Author Share Posted November 29, 2020 41 minutes ago, Tekken said: You have to create a database SQL or XML will work. hmm, i tried save the data to XML, but does not create the xml file: function teszt(player) local loadFile = xmlLoadFile("objektek.xml", "root") if not (loadFile) then loadFile = xmlCreateFile("objektek.xml", "root") end local object = getElementsByType("object") for k, v in ipairs(object) do local createChild = xmlCreateChild(loadFile, "object") if getElementData(v,"owner") == player then local x,y,z = getElementPosition(v) local model = getElementModel(v) outputChatBox("saved") xmlNodeSetAttribute(createChild, "x", x) xmlNodeSetAttribute(createChild, "y", y) xmlNodeSetAttribute(createChild, "z", z) xmlNodeSetAttribute(createChild, "id", model) end end end addCommandHandler("teszt",teszt) Link to comment
Tekken Posted November 30, 2020 Share Posted November 30, 2020 You forgot xml save and unload file Link to comment
Turbesz Posted November 30, 2020 Author Share Posted November 30, 2020 3 hours ago, Tekken said: You forgot xml save and unload file and how can i get that object is there? because if i save objects and load it, then spawn objects again the same position Link to comment
Turbesz Posted November 30, 2020 Author Share Posted November 30, 2020 2 hours ago, Tekken said: What do you mean? i create object and save it, and if i load from xml more than 1x then create many object at same pos, so i want can be loaded only 1x Link to comment
Tekken Posted November 30, 2020 Share Posted November 30, 2020 Well you’d have to delete them just before loading them like for i,v in ipairs(getElementsByType("object")) do destroyElement(v) end You may want to check if the object has an element data to be sure you’re destroying the right ones. 1 Link to comment
Turbesz Posted November 30, 2020 Author Share Posted November 30, 2020 2 hours ago, Tekken said: Well you’d have to delete them just before loading them like for i,v in ipairs(getElementsByType("object")) do destroyElement(v) end You may want to check if the object has an element data to be sure you’re destroying the right ones. Thank you Btw, how can i save several objects to XML file? I tried this way, working, but only with 1 object datas: client: function saveObjects(x, y, z, int, dim, owner) local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") if not xml_save_log_File then xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "objekt") end if (x ~= "") then local XNode = xmlFindChild (xml_save_log_File, "X", 0) if not XNode then XNode = xmlCreateChild(xml_save_log_File, "X") end xmlNodeSetValue (XNode, tostring(x)) end if (y ~= "") then local YNode = xmlFindChild (xml_save_log_File, "y", 0) if not YNode then YNode = xmlCreateChild(xml_save_log_File, "y") end xmlNodeSetValue (YNode, tostring(y)) end if (z ~= "") then local ZNode = xmlFindChild (xml_save_log_File, "z", 0) if not ZNode then ZNode = xmlCreateChild(xml_save_log_File, "z") end xmlNodeSetValue (ZNode, tostring(z)) end if (int ~= "") then local IntNode = xmlFindChild (xml_save_log_File, "int", 0) if not IntNode then IntNode = xmlCreateChild(xml_save_log_File, "int") end xmlNodeSetValue (IntNode, tostring(int)) end if (dim ~= "") then local DimNode = xmlFindChild (xml_save_log_File, "dim", 0) if not DimNode then DimNode = xmlCreateChild(xml_save_log_File, "dim") end xmlNodeSetValue (DimNode, tostring(dim)) end if (owner ~= "") then local OwnerNode = xmlFindChild (xml_save_log_File, "owner", 0) if not OwnerNode then OwnerNode = xmlCreateChild(xml_save_log_File, "owner") end xmlNodeSetValue (OwnerNode, tostring(owner)) end xmlSaveFile(xml_save_log_File) xmlUnloadFile (xml_save_log_File) end addEvent("saveObjects", true) addEventHandler("saveObjects", getRootElement(), saveObjects) server: 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 owner = getElementData(v,"owner") or getAccountName(theAcc) local int = getElementInterior(v) local dim = getElementDimension(v) outputChatBox(x.." | "..y.." | ".. z .. " | "..id.." | "..owner.. " | "..int.." | "..dim) triggerClientEvent(thePlayer,"saveObjects",thePlayer,x,y,z,int,dim,owner) end end end addCommandHandler("save",teszt) Link to comment
Tekken Posted November 30, 2020 Share Posted November 30, 2020 This should only be mande serverside Nothing client side Link to comment
Turbesz Posted November 30, 2020 Author Share Posted November 30, 2020 5 minutes ago, Tekken said: This should only be mande serverside Nothing client side I'd like to save only the objects created by the local player, not all of them, that's why i want use client side 8 minutes ago, Turbesz said: I'd like to save only the objects created by the local player, not all of them, that's why i want use client side or i can do this on server side? Link to comment
Tekken Posted November 30, 2020 Share Posted November 30, 2020 Well you can do it serverside, you can name the xml node using player account name 1 Link to comment
Turbesz Posted November 30, 2020 Author Share Posted November 30, 2020 5 minutes ago, Tekken said: Well you can do it serverside, you can name the xml node using player account name thank youuuu working fine, many-many thanks Link to comment
Tekken Posted November 30, 2020 Share Posted November 30, 2020 You’re welcome Note, if you create an object clientside only the local player will see it, that’s good to know, this rule applies to many other functions 1 Link to comment
Turbesz Posted November 30, 2020 Author Share Posted November 30, 2020 1 hour ago, Tekken said: You’re welcome Note, if you create an object clientside only the local player will see it, that’s good to know, this rule applies to many other functions and can't that cause some issues that it's saving the XML file on the server and not on the players PC? Link to comment
Turbesz Posted December 1, 2020 Author Share Posted December 1, 2020 (edited) 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) Edited December 1, 2020 by Turbesz Link to comment
Tekken Posted December 1, 2020 Share Posted December 1, 2020 I don’t get it, what do you mean? 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