mob/hidden/verb/Snipe(mob/M as mob in oview(6)) //attack a mob within 1 tile of you
if(istype(M,/mob/Return)) return 0
else
usr << "You attack [M]!" //send this message to the usr
oview() << "[usr] attacks [M]!" //send this message to everybody else
var/damage = rand(1,10) //assign a random # to a new variable
world << "[damage] damage by [usr] to [M]!" //tell the damage to the world
M.HP -= damage //take away the damage from M
missile(/obj/projectile/arrow, usr, M)
M.DeathCheck()
sleep(10)
ID:148991
Aug 1 2002, 4:40 am
|
|
Would this code make SURE that the target is not /mob/Return, and, if it is, prevents the verb from executing?
|
In response to Lummox JR
|
|
Lummox JR wrote:
Drafonis wrote: mob/hidden/verb/Snipe(mob/M as mob in oview(6)) //attack a mob within 1 tile of you Yep, that's enough to do the trick. So I can remove the else statement, or is that optional? I don't get any warnings. Or is it merely more efficient without the else? |
In response to Drafonis
|
|
Drafonis wrote:
So I can remove the else statement, or is that optional? I don't get any warnings. Or is it merely more efficient without the else? The else would be optional; it has no effect in your proc, because that section won't run anyway if the if() works. It's not so much that it's more efficient, because I think it boils down to exactly the same code. (DM might compile it to different bytecode, but in C, for example, you'd see no difference in the result.) The real reason to remove the else is that your code will be marginally more compact and readable without the extra line and the extra indent. Lummox JR |
Yep, that's enough to do the trick.
Incidentally, since you're returning if this is true (you don't need to return 0, either; just plain "return" is good enough), you don't have to put the rest of the proc in an else block.
Lummox JR