ID:2076960
 
(See the best response by Popisfizzy.)
Question description:
ok so i want to make it so if someone is already busy they cannot fire a projectile because they are either stunned or swimming. how would i go about this?

Thank you for reading my post :D.
Best response
You basically have to track when they go in an out of the state. For example, you could do something like.
mob
var
occupied_state = 0 // When this is false, they are not occupied.

IsOccupied()
return occupied_state

Occupied()
occupied_state = 1
return IsOccupied()

NotOccupied()
occupied_state = 0
return IsOccupied()

Then if you want to keep them from firing a projectile, in your fire method you'd have something like
mob/proc/Fire()
if(IsOccupied())
return 0

// Otherwise, do the fire stuff.

Whenever a mob becomes occupied, you call Occupied() which sets the occupied flag on. Whenever they're no longer occupied, you call NotOccupied() turning it off.
You're generating excess proc overhead for no real reason here, if IsOccupied() did more than return a boolean value it would be more reasonable but in this case you're going to end up generating a ton more overhead any time you call Fire() when you could just be checking occupied_state directly.
It could be excessive; it depends on exactly what you want to do on down the line, so it's just a very general purpose solution. In this situation, the overhead concerns should be quite minor given that they should be irregular in the sense of happening far less than once per tick.

If you know for sure you're not going to be going more complex than that, though, it can be cut down for sure.
it didnt work for me, maybe because my fire proc is a verb?
In response to Louisthe10
Are you actually calling the Occupied() and NotOccupied() methods to set their state when the relevant conditions are satisfied?
Another way to approach a problem like this: Many games have several different things that can interfere with casting spells or moving. They end up with all kinds of conditions, like this:

if(dead || sleeping || walking || casting || brushing_teeth || ...)
return

When you have a bunch of possible yes/no conditions like that, that's when bitflags come to the rescue.

#define DEAD 1
#define SLEEPING 2
#define WALKING 4
#define CASTING 8
#define BEGIN_STATUS(x) if(status) return; status |= (x)
#define BEGIN_STATUS_ALLOW(x,allow) if(status & ~(allow)) return; status |= (x)
#define END_STATUS(x) status &= ~(x)

// various states that may keep a mob busy
mob/var/tmp/status = 0


So in most of your verbs, you'd do something like this:

mob/verb/Fire()
BEGIN_STATUS(CASTING)
... // do the spell, and sleep however long you want
spawn(delay) END_STATUS(CASTING)

Movement would be the same way.

mob/Move(newloc,newdir)
BEGIN_STATUS(WALKING)
. = ..()
spawn(movedelay) END_STATUS(WALKING)