Basically I want to damage a mob within view of 1 from an object, and continue to damage them until they leave.
I created a loop that is spawned when the object is created but it is eating up way too much cpu. Is there a more efficient way to do this?
Apr 11 2016, 1:18 pm
|
|
It's also likely that your view() check is an issue. You should post your code.
|
Can you show the actual code?
Without understanding your current approach, it'd be difficult to give you pointers. |
obj/Steam |
A few things here:
- Using src.thevar instead of just thevar is just a waste of typing, unless you have a local or global var with the same name. Clarify your code by nixing the src.xxxx cases. - Checking if src is valid is pointless in a proc. If the src object is deleted, the proc will end. - The value of the damage var that you're calculating isn't being used anywhere. - The call to Wound() should not be using the : operator. If you've defined that proc for all mobs, then the . operator is fine. And if you haven't defined it for all mobs, that's a runtime error waiting to happen. |
Question: Does this thing ever move?
A cleaner approach would be to create a hitbox that keeps track of the mobs that are currently standing inside of it and iterates over that list every tick. obj/Steam Now there are a few gotchas in here. 1) If you are ever setting the loc explicitly of any mobs, this can bug out. You should *always* ensure that Crossed() and Uncrossed() are reliable by never manually setting the location of anything that ever interacts with a Crossed()/Uncrossed() tracker. 2) If you ever manually delete your mobs, this will bug out too. You should never manually delete any mobs that are tracked by Crossed()/Uncrossed() trackers without first finding all objects that are beneath them and calling Uncrossed()/Crossed(). 3) BYOND by default has no reciprocal to Crossed()/Uncrossed(). So if you ever move this steam object into position, it will not be informed of any potential targets already standing there. I strongly advise implementing Crossed()/Uncrossed() reciprocals under /atom/movable because it allows you to write cleaner, smarter, better to contain code. Reference tracking is important, and ensuring that built-in functions are reliable by avoiding bad practices like manually setting locations and manually deleting objects while they are still on the map allows you to use BYOND's built-in function hooks to your advantage in much more elegant ways than simply checking oview() every few frames. |