ID:141085
 
Code:
mob/proc
enemyturn(mob/player/P,mob/enemy/E)
WeakAttack(E,P)

WeakAttack(mob/A,mob/D)
if(D in view(A.RANGE))
usr << "[A] uses Weak Attack on [D]!!!"
usr << "[A] deals 10 damage to [D]!!!"
D.HP = D.HP - 10
deathcheck(D)


Problem description:
Here's a portion of my code of my grid based game. So when was I was coding, I intended to let my WeakAttack() verb to be shared by both mob/player and mob/enemy, but i realized that there was a problem with this. The view() in the code would always be the mob/player's view() and not the mob/enemy's, even if the mob/enemy is the one using WeakAttack() as depicted. I tried using A.view() but that doesn't work. Any suggestions?

If you just put view() it defaults to usr as the mob to use, but you can put a mob inside of it to force it to something else; such as src.

view(src)


This should solve it.
In response to T3h P3ngu1n
WRONG.

While how you explained it is correct, view() is the wrong choice as once a player becomes blind, they immediately cannot use the attack. Attack-wise, it is much safer to use range() or orange(), as they cannot be modified during runtime unless you program it to do that.
You too. With attacks, view() = WRONG. Instead, use range(). In your case:

if(D in range(A))


Using this, it SHOULD return A's range.
In response to Demon_F0rce
Demon_F0rce wrote:
With attacks, view() = WRONG. Instead, use range().

In this case, that depends on what is desired, actually. You may want the player not to be able to attack invisible enemies, or to be able to attack them but with a lower chance of hitting.
In response to Kaioken
Another point to make, however, is that if blind and the programmer wants to be able to allow a prob() chance to allow contact, instead it would be wise to use range() and instead check for invisibility.
In response to Demon_F0rce
Actually, it would be wiser to check both view() and range() in that order instead, since then you account for all cases of visibility automatically (you don't need to manually check invisibility and see_invisible as well as sight, and more) efficiently.
In response to Kaioken
So, what do I do with the RANGE var? Let's say mob/player has RANGE = 3 and mob/enemy has a RANGE = 2. when mob/player is 3 distances away, it can attack mob/enemy and not be attacked.

Also, I think I should include that the battle takes place on a big field or no invisibility and there is full light
In response to Sandlight
Nevermind, I fixed the problem, Thanks for all your help guys.
Also, having two arguments for WeakAttack() is not necessary. You should instead be using src for A. When calling it, you would do:

attacker.WeakAttack(defender)


With attacker and defender being filled in with the appropriate variables, of course.