Jump to content

How can I add unique element data for object from table?


Recommended Posts

6 minutes ago, stPatrick said:

This part of the code isn't wrong, more info is needed about the script.

function func1()
    outputChatBox(tostring(getElementData(picint, "unique_id")))
end

addEventHandler("onMarkerHit", marker, func1, false)

in the database, each new marker has an id greater by 1 it displays the largest record in the database instead of displaying the correct id connected to the marker

Link to comment
  • Moderators
1 minute ago, NoviceWithManyProblems said:

function func1()
    outputChatBox(tostring(getElementData(picint, "unique_id")))
end

addEventHandler("onMarkerHit", marker, func1, false)

in the database, each new marker has an id greater by 1 it displays the largest record in the database instead of displaying the correct id connected to the marker

I think the problem is similar to a previous one

 

Link to comment
  • Moderators

Okay, i see ?

In the for loop you define a global marker variable what you overwrite every time until the for loop is running.

So, when the loop ends, the marker variable is still alive, whats the last marker's element.

In the onMarkerHit event you print the unique_id of this element. You need to replace it to source.

 

function func1()
    outputChatBox(tostring(getElementData(source, "unique_id")))
end
addEventHandler("onMarkerHit", marker, func1, false)

 

btw, nice drawing xd

Edited by stPatrick
Link to comment
2 minutes ago, stPatrick said:

Okay, i see ?

In the for loop you define a global marker variable what you overwrite every time until the for loop is running.

So, when the loop ends, the marker variable is still alive, whats the last marker's element.

In the onMarkerHit event you print the unique_id of this element. You need to replace it to source.

 


function func1()
    outputChatBox(tostring(getElementData(source, "unique_id")))
end
addEventHandler("onMarkerHit", marker, func1, false)

 

btw, nice drawing xd

Thanks. It's possible to do this with pickup?

Link to comment
  • Moderators
1 minute ago, NoviceWithManyProblems said:

Thanks. It's possible to do this with pickup?

 

Maybe, but you need to cancel the event.

 

-- SERVER

local pickup = createPickup(...)
setElementData(pickup, "unique_id", 1)

addEventHandler("onPlayerPickupHit", pickup, function()
    cancelEvent() -- cancel the event ==> the player can't pickup this "pickup" :D
    outputChatBox(getElementData(source, "unique_id"))
end)

 

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