Jump to content

[HELP] How to get data from my table?


Turbesz

Recommended Posts

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

 

  • Thanks 1
Link to comment
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 by Turbesz
Link to comment
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 :D 

but the debugscript flood this: bad argument @ 'getElementData'  [Expected element at argument 1] 
why?

Link to comment
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
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 :D

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

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