Jump to content

Element Data


Recommended Posts

Hello! My question is that how can I get a server side element data in client side? So, for example there's a marker in server side, I set an element data to it in server side. How can I get this element data in client side? I want to check if a house is locked or not, but I want to do it in client side because of the gui changes according to the lock. So if the house is locked the gui image is different. Can anyone help me please? Thanks in advance!

Link to comment
Yeah get the marker in which the player is currently in, then try to get that data from it.

But the markers are in server side. Or how can I get the "name" of the server side marker in client side? For example, in server side the marker is being created like:

  
exampleMarker = createMarker( ... ) 
  

So how can I get the name exampleMarker in client side to get the element data of it?

Link to comment
  • Moderators
But the markers are in server side.

Not really, you created them in the server side okay but they also exists (and accessible) from the client side.

Put this wherever you want in the client side:

local inHouseMarker = nil 
  
addEventHandler("onClientMarkerHit", root, function ( player ) 
    if getElementType(player) ~= "player" then return end 
    if getElementData(source, "isHouseMarker") then 
        inHouseMarker = source 
    end 
end) 
  
addEventHandler("onClientMarkerLeave", root, function ( player ) 
    if getElementType(player) ~= "player" then return end 
    if getElementData(source, "isHouseMarker") then 
        inHouseMarker = nil 
    end 
end) 
  
--[[ 
    Desc: Get house marker in which the player is. 
    return: The marker element if the player is currently in one of them, nil otherwise. 
]] 
function getCurrentHouseMarker() 
    return inHouseMarker 
end 

Set the element data "isHouseMarker" to true on the server side for all the house markers you create:

setElementData(theMarker, "isHouseMarker", true) 

And then use this function on the client side:

local houseMarker = getCurrentHouseMarker() 

It will return the house marker in which the player is currently in. But please check if houseMarker is not equal to nil (it will return nil if you called that function while the player is not in any house marker).

Once you got it and you checked it's not equal to nil, you can call your getElementData on that returned marker to get the element data you set on the server side.

Link to comment

You can use element IDs to get the marker element client side:

-- server side 
local exampleMarker = createMarker ( ... ) 
setElementID ( exampleMarker, "MyExampleMarker" ) 
  
-- client side 
local exampleMarker = getElementByID ( "MyExampleMarker" ) 

Link to comment
  • Moderators
You can use element IDs to get the marker element client side:
-- server side 
local exampleMarker = createMarker ( ... ) 
setElementID ( exampleMarker, "MyExampleMarker" ) 
  
-- client side 
local exampleMarker = getElementByID ( "MyExampleMarker" ) 

It's a good idea only for specific markers.

But here it's obviously for an undefined amount of generic markers.

You won't set a unique id to each marker you will create for each house. That's why I did it this way.

And mostly because he wanted to know in wich marker the player was in to then get its element data(s).

My system prevent you to loop into all makers or all ids to check if the localPlayer is in the marker.

Link to comment
  • Moderators

It was obviously implicit because of the context:

I want to check if a house is locked or not, but I want to do it in client side because of the gui changes according to the lock. So if the house is locked the gui image is different.

So it means that the gui is probably poping up when the player is in the marker of a house (automatically, or using a key or even a command).

He didn't mention anything about the cursor (that could have been used to click on the marker and so we would be able to get the marker using the event parameters).

We could also find the closest house marker using the player position, but I doubt it was what he wants.

That's why I assumed he wanted to get the a house marker which have been created on the server-side and in which the player should stand in to show the gui.

That being said, we can also send the marker in the triggerClientEvent that opens the gui.

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