Ihnify Posted October 27, 2020 Share Posted October 27, 2020 (edited) Hi how to send information about the created element to the server from the client example : vehicleBlip = createElement('vehicleBlip', 'vehicleBlip') I need to send vehicleBlip to the server I want the blip to be deleted when the player gets in the car how?) Edited October 27, 2020 by Ihnify Link to comment
Rakashy Posted October 27, 2020 Share Posted October 27, 2020 57 minutes ago, Ihnify said: Hi how to send information about the created element to the server from the client example : vehicleBlip = createElement('vehicleBlip', 'vehicleBlip') I need to send vehicleBlip to the server I want the blip to be deleted when the player gets in the car how?) use destroyElement type destroyElement (element) example: let's assume that the created blip is called BlipCarro, then insert the function to execute when the player enters the car destroyElement (BlipCarro) Link to comment
Ihnify Posted October 27, 2020 Author Share Posted October 27, 2020 1 minute ago, Rakashy said: use destroyElement type destroyElement (element) example: let's assume that the created blip is called BlipCarro, then insert the function to execute when the player enters the car destroyElement (BlipCarro) but blip is created only when a player gets into the transport stream zone, then blip is created, and I want to make sure that blip is not created if the player is in the car, and if the transport is already in the player's stream zone and another player got into the car, blip was deleted Link to comment
Rakashy Posted October 27, 2020 Share Posted October 27, 2020 Just now, Ihnify said: mas o blip é criado apenas quando um jogador entra na zona de fluxo de transporte, então o blip é criado, e eu quero ter certeza de que o blip não seja criado se o jogador estiver no carro e se o transporte já estiver na zona de fluxo do jogador e outro jogador entrou no carro, o blip foi excluído post your script for more help... Link to comment
Moderators IIYAMA Posted October 27, 2020 Moderators Share Posted October 27, 2020 (edited) 1 hour ago, Ihnify said: I need to send vehicleBlip to the server Server created elements are available clientside. Client created elements are NOT available on serverside. But there is 1 trick you can use to delete clientside elements by serverside. Start the following example when you are not downloading other resources, clientside must have been started before 10 seconds. Server local serverSideElement = createElement("exampleElement", "id:3563454hasduy3685dsfs") setTimer(function () -- destroy the element over 10 seconds destroyElement(serverSideElement) end, 10000, 1) Client local clientSideElement = createElement("exampleExample") -- get the serverside element local serverSideElement = getElementByID("id:3563454hasduy3685dsfs") if isElement(serverSideElement) then setElementParent(clientSideElement, serverSideElement) -- set the clientside element as child of the serverside element end addEventHandler("onClientElementDestroy", clientSideElement, function () iprint("onClientElementDestroy") end, false) *** Fixed the wrong ID value. Edited October 27, 2020 by IIYAMA 1 Link to comment
Ihnify Posted October 27, 2020 Author Share Posted October 27, 2020 (edited) this client side local vehicleBlipRoot = createElement("vehicleBlipRoot", "vehicleBlipRoot") local function streamIn() if getElementType(source) ~= "vehicle" then return end for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do if getElementAttachedTo(blip) == source then return end end if source == getPedOccupiedVehicle(localPlayer) then return end local blip = createBlipAttachedTo(source, 0, 1, 150, 150, 150, 255, 1) setElementParent(blip, vehicleBlipRoot) end addEventHandler("onClientElementStreamIn", root, streamIn) local function streamOut() if getElementType(source) ~= "vehicle" then return end for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do if getElementAttachedTo(blip) == source then destroyElement(blip) break end end end addEventHandler("onClientElementStreamOut", root, streamOut) I need to delete blip on the server 14 minutes ago, IIYAMA said: Server created elements are available clientside. Client created elements are NOT available on serverside. But there is 1 trick you can use to delete clientside elements by serverside. Start the following example when you are not downloading other resources, clientside must have been started before 10 seconds. Server local serverSideElement = createElement("exampleElement", "id:3563454hasduy3685dsfs") setTimer(function () -- destroy the element over 10 seconds destroyElement(serverSideElement) end, 10000, 1) Client local clientSideElement = createElement("exampleExample") -- get the serverside element local serverSideElement = getElementByID("id:3563454hasduy3685dsfs") if isElement(serverSideElement) then setElementParent(clientSideElement, serverSideElement) -- set the clientside element as child of the serverside element end addEventHandler("onClientElementDestroy", clientSideElement, function () iprint("onClientElementDestroy") end, false) *** Fixed the wrong ID value. but I need to delete the blip created on the client Edited October 27, 2020 by Ihnify Link to comment
Moderators IIYAMA Posted October 27, 2020 Moderators Share Posted October 27, 2020 (edited) 5 hours ago, Ihnify said: but I need to delete the blip created on the client Exactly, that is why I gave you an example of how to do that, don't waste it. Since you still do not understand it, this is my last attempt to show you how you can delete clientside elements by also using a serverside element. If you still don't understand it, then that is unfortunately. Serverside local playerBlipElementContainerElement = createElement("playerBlipElementContainer", "playerBlipElementContainer:24436dg45632Ddfg") addEventHandler("onPlayerJoin", root, function () local serverSideElement = createElement("playerBlipElement_serverSide") setElementData(serverSideElement, "owner", source) setElementParent(serverSideElement, playerBlipElementContainerElement) end) --[[ -- Players already ingame addEventHandler("onClientResourceStart"... getElementsByType("player") ... ]] Clientside local playerBlipElementContainerElement = getElementByID("playerBlipElementContainer:24436dg45632Ddfg") ------------------- -- MODIFY THIS, for players already ingame (add a little delay) and for new players (onClientPlayerJoin + add a little delay) local serverSideElements = getElementChildren(playerBlipElementContainerElement) for i=1, #serverSideElements do local serverSideElement = serverSideElements[i] local owner = getElementData(serverSideElement, "owner") local blip = createBlipAttachedTo(owner, 0, 1, 150, 150, 150, 255, 1) setElementParent(blip, serverSideElement) end Edited October 27, 2020 by IIYAMA 1 Link to comment
Ihnify Posted October 27, 2020 Author Share Posted October 27, 2020 (edited) 1 hour ago, IIYAMA said: Exactly, that is why I gave you an example of how to do that, don't waste it. Since you still do not understand it, this is my last attempt to show you how you can delete clientside elements by also using a serverside element. If you still don't understand it, then that unfortunately. Serverside local playerBlipElementContainerElement = createElement("playerBlipElementContainer", "playerBlipElementContainer:24436dg45632Ddfg") addEventHandler("onPlayerJoin", root, function () local serverSideElement = createElement("playerBlipElement_serverSide") setElementData(serverSideElement, "owner", source) setElementParent(serverSideElement, playerBlipElementContainerElement) end) --[[ -- Players already ingame addEventHandler("onClientResourceStart"... getElementsByType("player") ... ]] Clientside local playerBlipElementContainerElement = getElementByID("playerBlipElementContainer:24436dg45632Ddfg") ------------------- -- MODIFY THIS, for players already ingame (add a little delay) and for new players (onClientPlayerJoin + add a little delay) local serverSideElements = getElementChildren(playerBlipElementContainerElement) for i=1, #serverSideElements do local serverSideElement = serverSideElements[i] local owner = getElementData(serverSideElement, "owner") local blip = createBlipAttachedTo(owner, 0, 1, 150, 150, 150, 255, 1) setElementParent(blip, serverSideElement) end Sorry, but I didn't understand I'm really stupid, you can use an example with creating a blip for an vehicle, and deleting it on the server, please, if it's not difficult Edited October 27, 2020 by Ihnify Link to comment
Moderators IIYAMA Posted October 27, 2020 Moderators Share Posted October 27, 2020 (edited) 3 hours ago, Ihnify said: Sorry, but I didn't understand I'm really stupid, you can use an example with creating a blip for an vehicle, and deleting it on the server, please, if it's not difficult You are not stupid, it might be too complex to begin with. This is called the element tree: https://wiki.multitheftauto.com/wiki/Element_tree And as you know, tree's do start with the root element. (With this tree, there is a single root, yea I know that is strange...) Under this (inverted) tree you can see it is branching in to different other elements. This is how MTA organize it's elements. resourceRoot is the start of a single resource. Under the resourceRoot, you can see 1 resourceDynamicElementRoot. (This is where all your elements created by script are childs of) There are also resourceMapRootElement(s). Each element represents a map element, created by a .map file. Knowing all this and look at this representation of your resource (based on the code above): Serverside <resource id="your-resource"> <!-- resourceRoot --> <map id="dynamic"> <!-- resourceDynamicElementRoot --> </map> </resource> Clientside <resource id="your-resource"> <!-- (serverside) resourceRoot --> <map id="dynamic"> <!-- (serverside) resourceDynamicElementRoot --> <!-- START clientside --> <vehicleBlipRoot> <blip/> <blip/> <blip/> </vehicleBlipRoot> <!-- END clientside --> </map> <!-- (serverside) --> </resource> <!-- (serverside) --> As I said before, clientside has access to all serverside elements. But serverside has no access/isn't ware of clientside elements. You want to destroy client elements with serverside, but serverside is not ware that they exist. With the following element structure you can solve that: <resource id="your-resource"> <map id="dynamic"> <vehicleBlipRoot> <blipServerSide> <!-- START clientside --> <blip/> <!-- END clientside --> </blipServerSide> <blipServerSide> <!-- START clientside --> <blip/> <!-- END clientside --> </blipServerSide> <blipServerSide> <!-- START clientside --> <blip/> <!-- END clientside --> </blipServerSide> </vehicleBlipRoot> </map> </resource> If you delete blipServerSide, with the function destroyElement, then the blip clientside will also be deleted. This is happening because when you call the destroyElement function on serverside, the same function will be called on clientside on the same element (behind the scenes). And thx to propagation (already enabled) the function will also be called for all the children of the element that is about to be destroyed, which is in this case the client element blip. I can't explain it better than this. Edited October 27, 2020 by IIYAMA 2 1 Link to comment
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