BialyDran Posted November 17, 2017 Share Posted November 17, 2017 Hey, im having a problem with destroyElement. Script is meant to: 1) Give player a box IF pressed E in the appropriate marker ( works. ) 2) Using a random function choose a marker where he needs to give it back ( works.) 3) Destroy only element that this player who enters a marker is "holding" What is wrong? Its server-side. So it destroy each box element that exists in the server and I want to destroy it only for the person that enters the marker. Any ideas how to do this? I was thinking about either using setElementData or tables, but have no idea how to start with this. Here's the code for server- side: addEvent("GiveThing", true) addEventHandler("GiveThing", getRootElement(), function(localPlayer) object = createObject(1518, 0, 0, 0) attachElements(object, source, 0, 0.5, 0.4) setObjectScale(object, 0.9) end) addEvent("RemoveThing", true) addEventHandler("RemoveThing", getRootElement(), function(localPlayer) destroyElement(object) end) Link to comment
Moderators IIYAMA Posted November 17, 2017 Moderators Share Posted November 17, 2017 Create and destroy it clientside. I recommend you to create a flowchart if you have no idea how to build it. Which is actually very close to the code you are going to build, but at a more understand able level. You can later use that to inform yourself or your helper to build the components of the code. Link to comment
BialyDran Posted November 17, 2017 Author Share Posted November 17, 2017 1 minute ago, IIYAMA said: Create and destroy it clientside. I recommend you to create a flowchart if you have no idea how to build it. Which is actually very close to the code you are going to build, but at a more understand able level. You can later use that to inform yourself or your helper to build the components of the code. Well, I was thinking about making this client side, but I want all players to be able to see that someone is actually caring a box and then that this box dissapears when they walk into a marker. Link to comment
Moderators IIYAMA Posted November 17, 2017 Moderators Share Posted November 17, 2017 If you every player to see the same objects, then serverside is the right thing to do. If you do not know how to work with tables then you can also work with elementdata, but it is a little bit dirtier. And can actually make it very dirty if it isn't removed. Use a flowchart to make the decision how you want to build it. Ask yourself this question: Which parts do I want to do serverside and which ones clientside? Link to comment
BialyDran Posted November 17, 2017 Author Share Posted November 17, 2017 Eghh, to be honest it doesnt help at all. I have full script ready with client & server scripts which works fully when you're making this on your own. Problem begins when there are 2 people working on this job at the same time. If 2 players have a box, then if 1 player enters a marker it destroys a box for all players in the server who has this box. Im looking for a way to destroy only element for a player that entered this marker. Link to comment
Saml1er Posted November 17, 2017 Share Posted November 17, 2017 (edited) Just like IIYAMMA said, you can use tables: local PlayersWithBoxes = {} -- create a table addEvent("GiveThing", true) addEventHandler("GiveThing", getRootElement(), function(localPlayer) local ObjectToAttach = createObject(1518, 0, 0, 0 ) attachElements ( ObjectToAttach, source, 0, 0.5, 0.4 ) setObjectScale ( ObjectToAttach, 0.9 ) PlayersWithBoxes [ source ] = ObjectToAttach -- 'key' is the player and 'value' is the object attached to player end ) addEvent("RemoveThing", true) addEventHandler("RemoveThing", getRootElement(), function(localPlayer) -- I'm guessing that you want to destroy the object attached to "localPlayer" local ObjectAttachedToPlayer = PlayersWithBoxes [ localPlayer ] -- access the object like this if isElement ( ObjectAttachedToPlayer ) then -- check if the object exists destroyElement ( ObjectAttachedToPlayer ) end end ) Edited November 17, 2017 by Saml1er fixed indentation Link to comment
BialyDran Posted November 17, 2017 Author Share Posted November 17, 2017 (edited) Thanks mate, I'll try this Edited November 17, 2017 by BialyDran 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