I’m currently working on a project where you can destroy certain parts, present in different spawn areas of the map. The user has a tool to damage and destroy a part using a .touched event client-side on the tool (with remote validation on the server).
I quite like the ‘lua OOP structure’ to organise my project, allowing me to easily add more varied destructable parts. I thought about making the destructable part a class, but I’m not sure how I would handle touched events that way. I would need to find the part object (instantiated class) based on the given part (given through the touched event) in some way. This is probably possible by collecting all instantiated objects in some script (EDIT: and looping over them, finding the right part) but I already have spawner objects holding the parts for a specific area.
Is there a way to do this without big overhead? Otherwise I’ll just keep my functional structure using instance values for the part properties and a general module for processing the attack on a given workspace part.
I already tag the parts for being destructable, but I don’t quite see how I could use this system to quickly bridge between parts and the instantiated part objects in a script?
I see what you mean now. OOP would intend you to connect the event from the destructible part itself, which would result in too many connections I would assume. In true OOP languages this wouldnt be an issue which is why I don’t think you can find a satisfying solution here.
Is there a data structure that I can use for this that doesn’t introduce a significant overhead? The only thing I can think of right now is a collection of all “destructableClass” objects and looking over them for the right part.
Thanks for your answer.
I also currently think this as there’s no existing connection between the event and the made up abstraction of the parts. But still curious as to what others have to say.
You want one signal. To find the part? And then this part will have data used in your code?
If so you’d use a table, and when the signal is fired for .touched. youd loop though that table, to find that part.
Each object inside of that table, will be a table that has the object, the object name. A guid etc. Youd find the target part from the object, if TocuhedObject == IndexedExample.Object …
For things like this, I like to just add an integer “ID” to the object and store the same value inside of the object as a NumberValue. Then simply store it in a dictionary like DestructableParts[UniqueIntegerID] = Constructor.new(basePart, UniqueIntegerID). When a client touches a part, the server can easily look up the object and it’s methods using the dictionary and ID found inside of the part.
My systems take advantage of shared and _G, using these tables to store data such as custom classes and geberall data. Maybe you can do the same. Manipulate shared or _G to house those classes. So when you do fire .Touched. you can get a hold of the class.
Either that or you could bind a custom .Touched event to the class itself.
If your talking about a network call, then I’d advice not too. A hacker could easily spood/manipulate that. Try to handle all .touched events in the Sever.
How can an exploiter still manipulate a remote call with spam protection and sanity checks?
I handle collision client-side because I prefer playability above perfect security.