ID:146554
 

mob/verb/attack(mob/M)
set category = "Taijutsu"
var/damage = src.Taijutsu
M << "[src] has attacked you for [damage] damage!"
if(src.client)
src << "You attacked [M] for [damage] damage!"
M.Stamina-=damage
src.death(M)
if(src.client)
src.exp+= M.stamina/2
if(src.exp >= src.maxexp)
src.Levelup()
else
return ..()
mob/proc/death(mob/M as mob)
if(M.Stamina <= 0)
M.Stamina = M.maxstamina
M.chakra = M.maxchakra
if(!src.Spawn_Point)
src.loc = locate(1,1,1) // Defualt spawn area
else
src.loc = locate(src.Spawn_Point)
world << "<h4><font color = red>[src] has killed [M]</h4></font>"


When I press attack it will attack myself o_O.

Try using:

set src in oview(1), also you can try using:
if(src == M)
//nothing happens
Well, first of all, unless you've defined atom.attack(), you're mis-using ..() here. It doesn't just mean "do nothing" -- if there's no parent proc, then you shouldn't be using it (See http://bwicki.byond.com/ByondBwicki.dmb?ParentProc).

Second, death should be a function of the dying object, while its killer should be passed through death() as an argument.

Third, if you would just use seperate type paths for players and npcs, you wouldn't have to keep checking for if(src.client) -- you could just define attack() under /mob/player instead.

Fourth, your HTML is pretty bad here. All HTML tags should be nested, and there should never be a space between an attribute and its value. Also, values should be inside double quotes, but since you already have double quotes here, single quotes are acceptable. (See http://www.w3schools.com or http://htmldog.com). Therefore, "<h4><font color = red>[src] has killed [M]</h4></font>" should be "<h4><font color='red'>[src] has killed [M].</font></h4>". I actually kind of disagree with your use of HTML for presentation -- CSS should be used for that instead: "<h4 style='color:red'>[src] has killed [M].</h4>". Of course, if you make the other changes suggested in this post, it will end up saying, "<h4 style='color:red'>[killer] has killed [src].</h4>".

Finally, your proc definitions are off:

attack() should be defined like this:

mob/verb/attack(mob/victim as mob in oview(1,src))


The as operator restricts user input, and here, it will restrict M to actually being a mob, and will restrict that mob to a list of the tiles surounding src. While the "mob/M" part guarantees that the compiler will think of M as a mob, it doesn't actually guarantee it because DM is a loose-typed language.

Knowing what I've just taught you about the as operator, you'll probably notice that something's wrong with this too:

mob/proc/death(mob/M as mob)


Since as restricts user input, and the argument of this proc will be passed through by the program, the as operator is useless here. Instead, you'll just have to use istype() or ismob() to guarantee that M is really a /mob:

mob/proc/death(mob/killer)
if(!istype(killer)) return
In response to Wizkidd0123
If he doesn't understand that then, ..., well I guess he'll be out of luck.


~C
In response to Chwgt
In addition to what Wizzkid said: We need a little bit more info. Were you in the game by yourself? ( If so, it automatically selects you. )
In response to Audeuro
He could add in:
if(!M)
return
if(usr)
return
In response to Audeuro
Audeuro wrote:
In addition to what Wizzkid said: We need a little bit more info. Were you in the game by yourself? ( If so, it automatically selects you. )

Na -- I disagree: we have enough info.

If he defines attack like this, then it will never have the opportunity to select his mob:

mob/player/attack(mob/victim as mob in oview(1,src)
In response to Chwgt
Chwgt wrote:
He could add in:
> if(!M)
> return
> if(usr)
> return
>


Chwgt, adding the second if() check there would make attacking an impossibility. In a user-initiated process, usr will always be equal to the mob of the initiator. Therefore, if the attack() verb was clicked on, usr will never be equal to null.
In response to Wizkidd0123