ID:143151
 
Code:
/////////////////////////////////////////
///////////////////ATTACK////////////////
mob
verb
attack()
att()



mob/var
party=0
mob/proc/att(M as mob)
if(M in view(1) && M:party==0 && friendly==0)
var/dmg = src.str - M:def
view()<<"[src.name] attack [M:name] and make [dmg] damage"
M:hp -= dmg
M:DeathCheck()
else
usr<<"The target is your party member or he is a friendly npc, you cant attack him!"
if(M:monster==1)
var/dmg = src.str - M:def
view()<<"[src.name] attack [M:name] and make [dmg] damage"
M:hp -= dmg
M:DeathCheck()
M:attack(src)


mob/proc/DeathCheck()
if(src.hp >=0)
del(src)


Problem description:
When i get to the mob and i press on the verb attack, nothing happens, also i would like to know how to make it that it attack the closest one, couse ussually it is that when there are more mobs in view(1) the menu will popup and usr will have to choose, and thats kinda stupid becouse the fights are supposed to be dynamics...Anyway, please help me...
http://developer.byond.com/hub/Rifthaven/A.I.Code

this demo shows you a good attack system, attacks the mob you're facing only, has alot of other good elements too, if you don't like having a graphic in the square you're attacking just go make the sword.dmi file blank

mike
In response to Kichimichi
Never seen M: done, to be honest. Everything seems right besides the fact that you use src. and M:, so I'd try changing all of the M:s to M. .

/////////////////////////////////////////
///////////////////ATTACK////////////////
mob
verb
attack()
att()



mob/var
party=0
mob/proc/att(M as mob)
if(M in view(1) && M.party==0 && friendly==0)
var/dmg = src.str - M.def
view()<<"[src.name] attack [M.name] and make [dmg] damage"
M.hp -= dmg
M.DeathCheck()
else
usr<<"The target is your party member or he is a friendly npc, you cant attack him!"
if(M.monster==1)
var/dmg = src.str - M.def
view()<<"[src.name] attack [M.name] and make [dmg] damage"
M.hp -= dmg
M.DeathCheck()
M.attack(src)


mob/proc/DeathCheck()
if(src.hp >=0)
del(src)


Although on an added note, you might want to revise that Deathcheck. Eventually you're going to need to modify it to include players and deleting a player every time they die is a very bad idea.
In response to Uyersuyer
sudden death games rock!, you die you're gone, reroll char plz.

mike-
In response to Kichimichi
Another problem :>

    verb
Attack(mob/M as mob in oview(1))
if(M.NPC==1)
return
else
M.attacked = 1
var/damage = usr.str
damage -= M.def
if(M.monster==1||M.player==1)
M << "[usr] attacks you and does [damage] damage"
usr << "You attack [M] for [damage] damage"
M.hp-=damage
M.Deathcheck()
usr.Levelup()

mob
var
attacked
expgive


mob/proc/monsterAI(mob/M)
if(M.monster==1)
return
else
if(M in view(3))
src.Attack(M)


So the prob now is A.I i dont know how to get it work i've made it so when mob get to a monster in 3 tiles the monster will use the Attack verb on the M, still i dont know how to make it work and how to make the monster walk to the M. Anyone please help?
In response to Duni
There are various ways of getting the AI to walk to and attack a player. These generally consist of a looping proc that checks for players in the area every so often, or in my games case, anytime a player moves.

It is really mostly just doing checks for a player in the monsters view(), then using walk_to(), and writing an attack proc that will loop once a target is found. Fairly simple stuff.