ID:262853
 
Code:
mob
verb
Attack(mob/M in oview(1))
set category = "Action"
set desc = "Attack a player"
set hidden = 1
set src in oview(1)
var/random = (rand(1,4))
if(M in oview(1))
if(M.Attack==1)
usr<<"<font color = red>[M.name] is knocked you there for you can not attack him/her."
return
else
if(M.Strength>usr.Strength)
if(random==1)
usr<<"<font color=red>You attack [M.name] for [usr.Strength] damage."
M<<"<font color = red>[usr.name] attacks you for [usr.Strength] damage."
oview(3)<<"<font color = red>[usr.name] attacks [M.name] for [usr.Strength] damage."
M.Health-=usr.Strength
if(random==2)
usr<<"<font color==red>[M.name] dodge you."
if(random==3)
usr<<"<font color==red>[M.name] dodge you."
if(random==4)
usr<<"<font color==red>[M.name] dodge you."
if(M.Strength<usr.Strength)
if(random==1)
usr<<"<font color=red>You attack [M.name] for [usr.Strength] damage."
M<<"<font color = red>[usr.name] attacks you for [usr.Strength] damage."
oview(3)<<"<font color = red>[usr.name] attacks [M.name] for [usr.Strength] damage."
M.Health-=usr.Strength
if(random==2)
usr<<"<font color=red>You attack [M.name] for [usr.Strength] damage."
M<<"<font color = red>[usr.name] attacks you for [usr.Strength] damage."
oview(3)<<"<font color = red>[usr.name] attacks [M.name] for [usr.Strength] damage."
M.Health-=usr.Strength
if(random==3)
usr<<"<font color=red>You attack [M.name] for [usr.Strength] damage."
M<<"<font color = red>[usr.name] attacks you for [usr.Strength] damage."
oview(3)<<"<font color = red>[usr.name] attacks [M.name] for [usr.Strength] damage."
M.Health-=usr.Strength
if(random==4)
usr<<"<font color==red>[M.name] dodge you."
if(M.Health<=0)
M<<"<font color = red>You have been knocked out by [usr.name] for 1 minute."
usr<<"<font color = red>You knocked out [M.name]."
M.Frozen=1
M.Attack = 1
if(M.Strength<usr.Strength)
usr.Strength+=2
else
usr.Strength+=5
sleep(100)
M<<"You have awoken."
M.Attack=0
M.Frozen=0
M.Health=M.maxHealth

else
usr<<"No one is within 1 foot of you."
return


Problem description:
When ever I go and press center for attack right by a player it says No one is within 1 foot of you even if I am.

->Calus CoRPS<-

Once you've specified that the mob/M should be in oview(1), there is no reason to put another if statement.

PS; look up get_step.
In response to Mysame
Calus i looked at your tutorials and thought you were good ... :'( you dissapoint me
In response to Mysame
Mysame wrote:
Once you've specified that the mob/M should be in oview(1), there is no reason to put another if statement.

Unless you're paranoid of packet senders to trick the server that you are actually in oview(), but otherwise, no. :P

~~> Unknown Person
There are a couple of things that can be improved here.

- Why is there a <code>set src in oview(1)</code> setting when the user actually uses the verb themself? This just causes major confusion for players. Take it off.

- Why are you repeating programming if the player gets a hit? You're repeating the hitting part three time to get a 3/4 chance. Very useless. Just check if rand(1,4) == 1, and tell the user that they missed.

- The uses of return in the way you are using it is useless, since you have an else statement (and for the last one, the end of the verb) right after it.

- If you're ever going to have any other skills that will damage an enemy, you would have to go repeat the proccess of checking their health. Make a DeathCheck proc, and do the death stuff there. Otherwise, you'll end up having to repeat many things.

- Since this is a verb, you will never get an error message, because you never know what mob you would pick. It would be a better idea instead of relying on an argument to get a list of mobs around you (or even in front of) the player. You also don't get that annoying pop up if there are more than one mobs in that place.

All of that stuff can be condensed into this:

mob
verb/Attack()
set category = "Action"
set desc = "Attack a player"
set hidden = 1
var/mob/M = locate() in oview(src, 1)
if(M) // check if a mob was found
if(M.Attack)
src << "your text"
else
if(M.Strength > src.Strength)
if(rand(1,4) == 1)
// you hit
else
// you missed
else // if their strength isn't higher than yours (no need for another if statement)
if(rand(1,4) == 1)
// you miss
else
// you hit
M.DeathCheck(src)
else // no mob found
src << "Nobody is within 1 foot of you."

proc
DeathCheck(mob/M) // M is the attacker
if(src.Health <= 0)
src << "You have been knocked out by [M.name]!"
src.Frozen = 1
src.Attack = 1
src.Strength += (M.Strength < src.Strength)? 2 : 5
spawn(100)
src << "You have awoken"
src.Attack = 0
src.Frozen = 0
src.Health = src.maxHealth


~~> Unknown Person