Jump to content

object from client to server


redditing

Recommended Posts

I have one question about client objects, if I use the "TriggerClientEvent" function on the server side script, whether the object that was saved on the client side and will be set with the triggerClientEvent function on the server side, will every player see it and will work in the same way as normally I would call it in the server side script "createObject (object, x, y, z)"? For example, such

-- client

addEvent("createObject", true)

addEventHandler("createObject", root, function(object, x, y, z)
	  createObject(x, y, z)
  end
)

-- server

triggerClientEvent(root, "createObject", root, 1372, 0, 0, 5)

-- Would that be the same as this?

-- server

createObject(1372, 0, 0, 5)

 

Link to comment
  • Moderators
2 hours ago, redditing said:

I have one question about client objects, if I use the "TriggerClientEvent" function on the server side script

 

The big difference is that the object created on clientside, is not added to the element tree of serverside. (so unavailable/invisible)

<!-- serverside / clientside -->
<resource id="resource-id">
	<map id="dynamic">

		<!-- START clientside ONLY for redditing  -->
		<object/><!-- invisible/unavailable for serverside and other players -->
		<!-- END clientside -->

		<!-- START clientside ONLY for IIYAMA  -->
		<object/><!-- invisible/unavailable for serverside and other players -->
		<!-- END clientside -->

		<!-- START clientside ONLY for Tekken  -->
		<object/><!-- invisible/unavailable for serverside and other players -->
		<!-- END clientside -->

	</map>
</resource>

 

 

 

Edited by IIYAMA
Link to comment
3 hours ago, IIYAMA said:

 

The big difference is that the object created on clientside, is not added to the element tree of serverside. (so unavailable/invisible)


<!-- serverside / clientside -->
<resource id="resource-id">
	<map id="dynamic">

		<!-- START clientside ONLY for redditing  -->
		<object/><!-- invisible/unavailable for serverside and other players -->
		<!-- END clientside -->

		<!-- START clientside ONLY for IIYAMA  -->
		<object/><!-- invisible/unavailable for serverside and other players -->
		<!-- END clientside -->

		<!-- START clientside ONLY for Tekken  -->
		<object/><!-- invisible/unavailable for serverside and other players -->
		<!-- END clientside -->

	</map>
</resource>

 

 

 

Ok thx. Do you know how you can send elementData from the server to the client?

Link to comment
2 hours ago, redditing said:

Ok thx. Do you know how you can send elementData from the server to the client?

Once you've set the element data on the server you can use getElementData on the client to receive the set data.
Or triggerClientEvent , whatever you decide

Link to comment

I sugest element data for things you are going to request frequently and trigger event for things you request less frequently.

after that you can also create tables and sync them using trigger event but that’s a little harder. 

Edited by Tekken
Link to comment
  • Moderators
9 hours ago, redditing said:

Ok thx. Do you know how you can send elementData from the server to the client?

 

Too all clients:

-- server
local theElement = createElement("<element-type>", "<element-id>")
setElementData(theElement, "<key>", "<data>")

setTimer(function () 
	setElementData(theElement, "<key>", getTickCount())
end, 4000, 0)

 

-- client
addEventHandler("onClientResourceStart", resourceRoot, 
function () 
  local theElement = getElementByID("<element-id>")
  iprint("start value:", getElementData(theElement, "<key>"))

  addEventHandler("onClientElementDataChange", theElement, 
  function (theKey, oldValue, newValue)
        iprint(theKey, oldValue, newValue)
  end, false)
end, false)

 

 

 

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