Jump to content

[HELP] How to get data from my table?


Turbesz

Recommended Posts

Posted

I want get data from table, to use a object (move, etc.), but i don't know how to do this.

I tried this method:
 

local targy = {}
local cp = {}

function lerakja(thePlayer)
    local x, y, z = getElementPosition(thePlayer)
targy[thePlayer] = createObject(2167, x+1, y+1, z-1)
setElementData(targy[thePlayer], "owner", thePlayer)
end
addCommandHandler("obj",lerakja)

function  clickfunc ( button, state, player )
    if button == "left" and state == "down" then
        if getElementType ( targy[player] ) == "object" and getElementData(targy[player],"owner") == player then
            local x, y, z = getElementPosition(targy[player])

            outputChatBox("you are use now this object: ID: "..#targy[player])

            cp[player]= createMarker(x, y-0.2, z+2.5, "arrow", 0.7, 255, 181, 64, 250)
        end
    end
end
addEventHandler ( "onElementClicked", root, clickfunc ) 

The object spawn fine, and the cp spawn fine too above my object after i click. But if i spawn another object, the cp spawn above my object too again. This is fine, but i want to get data from that object which one I clicked to remove the previous cp from the previous object. 

How can i get data from my table to know how to do it this? (Sorry for my very bad english:/)

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted
11 minutes ago, Tekken said:

Just use


if targy[player] == source then

do something..

end

onElementClicked

i tried this, but if i create a new object, the old one does not respond to click

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted

Well count the id’s 

targy[player][ tonumber(#targy[player]) + 1 ] = element;

tonumber not needed normally but just to be sure

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

Posted
3 minutes ago, Tekken said:

Well count the id’s 


targy[player][ tonumber(#targy[player]) + 1 ] = element;

tonumber not needed normally but just to be sure

attempt to get length of field '?' (a nil value)

targy[player][tonumber(#targy[player]) + 1] = createObject(2167, x+1, y+1, z-1)

if i add this line without tonumber, i got the same error

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted
4 minutes ago, Tekken said:

Replace


#targy[player]

to 


#targy[player] or 0

 

I got the same error 

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted
2 minutes ago, Tekken said:

You define the table with the player first  targy[player] = {}

i got the same error with this, but if it had worked, then the table would be emptied, and if i try change "local targy = {}" to "local targy[source] = {}" out of the function, i got another error

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted

Wait just do table[player][1] = object

And create a table.count function like this 

function tablecount(table)

    if type(table) == "table" then

        local count = 0;

        for i,v in ipairs(table) do

            count = count +1;

        end

        return count;

    end

    return false;

end

and do

table[player][(tablecount(table[player]) or 0) + 1]

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

Posted
6 minutes ago, Tekken said:

Wait just do table[player][1] = object

Like this?

local targy = {}

function lerakja(thePlayer)
    local x, y, z = getElementPosition(thePlayer)
    table[thePlayer] = createObject(2167, x+1, y+1, z-1)
setElementData(table[thePlayer], "owner", thePlayer)
end
addCommandHandler("obj",lerakja)

function clickfunc ( button, state, player )
    if button == "left" and state == "down" then
        if table[player][1] == source then
            local x, y, z = getElementPosition(table[player][1])
            outputChatBox(x.." | "..y.." | "..z)
        end
    end
end
addEventHandler ( "onElementClicked", root, clickfunc ) 

 

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted
1 minute ago, Tekken said:

You should replace table with targy

uf, my bad

but i got this error now: attempt to index field '?' (a userdata value)

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted

Just realized a thing 

function lerakja(thePlayer)
    local x, y, z = getElementPosition(thePlayer)
targy = createObject(2167, x+1, y+1, z-1)
setElementData(targy, "owner", thePlayer)
  addEventHandler ( "onElementClicked", targy, clickfunc ) 
end
addCommandHandler("obj",lerakja)

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)

            outputChatBox("you are use now this object: ID: "..model)

            cp = createMarker(x, y-0.2, z+2.5, "arrow", 0.7, 255, 181, 64, 250)
        end
    end
end

This should work

May I know what you are exactly trying to archive? Didn’t quite understand yet

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

Posted
6 minutes ago, Tekken said:

Just realized a thing 


function lerakja(thePlayer)
    local x, y, z = getElementPosition(thePlayer)
targy = createObject(2167, x+1, y+1, z-1)
setElementData(targy, "owner", thePlayer)
  addEventHandler ( "onElementClicked", targy, clickfunc ) 
end
addCommandHandler("obj",lerakja)

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)

            outputChatBox("you are use now this object: ID: "..model)

            cp = createMarker(x, y-0.2, z+2.5, "arrow", 0.7, 255, 181, 64, 250)
        end
    end
end

This should work

this works, but i need the table thing, because i want that if a player create more than 1 object, then he can interact with just one of them, if he click on the object

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted
1 minute ago, Turbesz said:

this works, but i need the table thing, because i want that if a player create more than 1 object, then he can interact with just one of them, if he click on the object

Well the example I give you let’s you interact with only one object while creating many,doesn’t it?

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

Posted
10 minutes ago, Tekken said:

Well the example I give you let’s you interact with only one object while creating many,doesn’t it?

Yes

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted
13 hours ago, Tekken said:

Well the example I give you let’s you interact with only one object while creating many,doesn’t it?

Yes, but i cannot interact the old one, just with the newly created object

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted

Using the example I gave you? you sure? This one:

function lerakja(thePlayer)
	local x, y, z = getElementPosition(thePlayer);
	local targy = createObject(2167, x+1, y+1, z-1);
	setElementData(targy, "owner", thePlayer);
	addEventHandler("onElementClicked", targy, clickfunc);
end
addCommandHandler("obj", lerakja);

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);
			outputChatBox("you are use now this object: ID: "..model);
			local cp = createMarker(x, y-0.2, z+2.5, "arrow", 0.7, 255, 181, 64, 250);
		end
	end
end

 

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

Posted
14 minutes ago, Tekken said:

Using the example I gave you? you sure? This one:


function lerakja(thePlayer)
	local x, y, z = getElementPosition(thePlayer);
	local targy = createObject(2167, x+1, y+1, z-1);
	setElementData(targy, "owner", thePlayer);
	addEventHandler("onElementClicked", targy, clickfunc);
end
addCommandHandler("obj", lerakja);

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);
			outputChatBox("you are use now this object: ID: "..model);
			local cp = createMarker(x, y-0.2, z+2.5, "arrow", 0.7, 255, 181, 64, 250);
		end
	end
end

 

Yes, but i tried add the move object function:

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)
            setElementData(source,"mozgathato",true)
        end
    end
end

function mozgatas(player)
if getElementData(targy,"owner") == player and getElementData(targy,"mozgathato") == true then
    local x,y,z = getElementPosition(targy)
setElementPosition(targy,x,y-0.5,z) 
end
end

i always can move only the new one with this, no matter if i click the old one

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted

use moveObject function to move it. just add it into clickfunc function 

The "onElementClicked" event should check if source has "mozgathato" elemetData 

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

Posted
8 minutes ago, Tekken said:

use moveObject function to move it. just add it into clickfunc function 

The "onElementClicked" event should check if source has "mozgathato" elemetData 

if i add moveObject func in clickfunc then i can't move the object with my bindKey, no?

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

Posted
2 minutes ago, Tekken said:

Sorry but don't have any idea of what you trying to archive.

i just want move the object which the player clicked with the bindkey func

What if the only way not to feel bad, is to stop feeling, anything at all, forever?
- Hannah Baker

I cost a girl her life because I was afraid to love her...
- Clay Jensen

 ~ 13 Reasons Why

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