redditing Posted July 7, 2020 Posted July 7, 2020 The question is the following needs to get an item from the server side to the client side, how can I do it? (Elements such as markers, vehicles etc.)
Moderators Patrick Posted July 7, 2020 Moderators Posted July 7, 2020 Send to client side, with triggerClientEvent. 1 community profile | map converters | map images | pDownloader | pAttach | model encrypter
redditing Posted July 7, 2020 Author Posted July 7, 2020 (edited) Can I send it using trigger client event? e.g. the variable responsible for the vehicle? and if so how can I do it so that I can understand how it works ... Edited July 7, 2020 by redditing 1
Moderators IIYAMA Posted July 7, 2020 Moderators Posted July 7, 2020 (edited) 19 minutes ago, redditing said: Can I send it using trigger client event? e.g. the variable responsible for the vehicle? and if so how can I do it so that I can understand how it works ... All serverside elements are already available on clientside. The only problem is: "how to get the right one?" There are multi ways to get those, including triggerClientEvent as @Patrick said. Server local receiver receiver = getRandomPlayer() -- a random player receiver = root -- all players triggerClientEvent(receiver, "eventName_SEND_THING_OVER", resourceRoot, element) Client addEvent("eventName_SEND_THING_OVER", true) -- enable the event: string eventName, boolean true = able to receive events from serverside addEventHandler("eventName_SEND_THING_OVER", resourceRoot, -- add a handler, that will call the function when the event is triggered function (element) end, false) -- disable propagation There is also a method which I like to use to keep a dynamic list of my elements: Server local collectionElement = createElement("collection", "myVehicles") for i=1, 10 do local vehicle = createVehicle(432, i * 10, 0, 50) setElementParent(vehicle, collectionElement) -- (Note: setElementParent, doesn't work across resources) end Client function getMyVehicles (theType) local collectionElement = getElementByID("myVehicles") if collectionElement then return getElementChildren(collectionElement, theType) -- theType is optional, could be "vehicle" end return false end Edited July 7, 2020 by IIYAMA 2 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
redditing Posted July 7, 2020 Author Posted July 7, 2020 8 minutes ago, IIYAMA said: All serverside elements are already available on clientside. The only problem is: "how to get the right one?" There are multi ways to get those, including triggerClientEvent as @Patrick said. Server local receiver receiver = getRandomPlayer() -- a random player receiver = root -- all players triggerClientEvent(receiver, "eventName_SEND_THING_OVER", resourceRoot, element) Client addEvent("eventName_SEND_THING_OVER", true) -- enable the event: string eventName, boolean true = able to receive events from serverside addEventHandler("eventName_SEND_THING_OVER", resourceRoot, -- add a handler, that will call the function when the event is triggered function (element) end, false) -- disable propagation There is also a method which I like to use to keep a dynamic list of my elements: Server local collectionElement = createElement("collection", "myVehicles") for i=1, 10 do local vehicle = createVehicle(432, i * 10, 0, 50) setElementParent(vehicle, collectionElement) -- (Note: setElementParent, doesn't work across resources) end Client function getMyVehicles (theType) local collectionElement = getElementByID("myVehicles") if collectionElement then return getElementChildren(collectionElement, theType) -- theType is optional, could be "vehicle" end return false end I need to send the element to the client, because I want to write some text "dxDrawTextOnElement" on this element, that's why I want to know what I need to do to return the element from the server to the client
Moderators IIYAMA Posted July 7, 2020 Moderators Posted July 7, 2020 1 minute ago, redditing said: I need to send the element to the client, because I want to write some text "dxDrawTextOnElement" on this element, that's why I want to know what I need to do to return the element from the server to the client If it is a player, use Patrick his method. If it is an object/ped/vehicle created by a single resource, stick with the second method. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now