ID:139309
 
Code:
mob
Move()
for(var/mob/spawnbaby2/M in oview(5)) if(!M.woken) spawn() AI(M,src)//checks for mobs of the monster variety and if they aren't already using the AI code it calls it
..()
Login()
icon='player.dmi'
client.view=9
..()
spawnbaby2
New()
for(var/client/M in oview(5)) AI(src,M)//Checks for any players and if found calls the AI code with the NPC and said player
..()
spawnbaby2
icon='zombie.dmi'
var
woken
attacking

proc
Attack(mob/spawnbaby2/T)
for(var/mob/M in get_step(T,T.dir))//Checks for mobs infront of T
var/damage=rand(1,3)//Generates a random damage value(You can setup your damage calculation here like Strength-defense
view(6)<<"[T] attacks [M] for [damage] damage!"//Shows everyone how much T attacked M for
//here would be where you enter your health subtraction/deathcheck code

AI(mob/spawnbaby2/T,mob/M)
if(!T||T.client||!M.client) return//stop if T doesn't exist anymore or if T is a client or if M is not a client
T.woken=10
while(T&&T.woken)//while T exists and T is woken
sleep(10)//sleep 10 so theres less lag you can probably make this lower if you want NPCs to move faster
if(T.woken>0&&get_dist(T,M)>5&&T&&M)//if T's woken is higher than 0 and the distance between T and M is 5 or more and T exits and M exists
step_rand(T)//Take a Random step
T.woken-=1//Subract 1 from T's woken
else if(get_dist(T,M)<6&&T&&M)//else if the distance between T is lower than 6(meaning 5 or less) and T exists and M exists
step_towards(T,M)//take a step towards M
if(get_dist(T,M)<=1)//if the distance is 1 or less
T.dir=get_dir(T,M)//Makes it so T faces M
Attack(T)//Calls the attack proc


What I wanted this to do was to make it so that zombies only attack players and not all mobs. But right now they are attacking each other as well and I want to adjust it to where they only attack players. How do I do this? P.S: These zombies will attack me but they don't kill me. How do I make it so that they kill me and leave a corpse and respawn me to the defualt location? mob
player
var/life = 100

proc/HurtMe(D)
life = life - D
if(life < 0)
view() << "[src] dies!"
del src


I added this thinking maybe this is apart of it. Am I right?

proc
Attack(mob/spawnbaby2/T)
for(var/mob/M in get_step(T,T.dir))//Checks for mobs infront of T
var/damage=rand(1,3)//Generates a random damage value(You can setup your damage calculation here like Strength-defense
view(6)<<"[T] attacks [M] for [damage] damage!"//Shows everyone how much T attacked M for
//here would be where you enter your health subtraction/deathcheck code



Where you checks for mobs you have to make that it checks only for players.
Also: oview(5) defaults to oview(usr,5), and you should not be using usr outside verbs (even though it nonsensically is given a value that makes it work in this case). Use oview(src,5) instead (or oview(5,src)).

Oh, and when you override a procedure that has a return value (such as Move(), as you can see in the Reference), you need to preserve that return value. So, instead of just "..()", you should have either ".=..()", or "return ..()"
In response to Garthor
mob
Move()
for(var/mob/spawnbaby2/M in oview(src,5)) if(!M.woken) spawn() AI(M,src)//checks for mobs of the monster variety and if they aren't already using the AI code it calls it
.=..()
Login()
icon='player.dmi'
client.view=9
.=..()
spawnbaby2
New()
for(var/client/M in oview(src,5)) AI(src,M)//Checks for any players and if found calls the AI code with the NPC and said player
.=..()
spawnbaby2
icon='zombie.dmi'
var
woken
attacking

proc
Attack(mob/spawnbaby2/T)
for(var/mob/M in get_step(T,T.dir))//Checks for mobs infront of T
var/damage=rand(1,3)//Generates a random damage value(You can setup your damage calculation here like Strength-defense
view(6)<<"[T] attacks [M] for [damage] damage!"//Shows everyone how much T attacked M for
//here would be where you enter your health subtraction/deathcheck code

AI(mob/spawnbaby2/T,mob/M)
if(!T||T.client||!usr.client) return//stop if T doesn't exist anymore or if T is a client or if M is not a client
T.woken=10
while(T&&T.woken)//while T exists and T is woken
sleep(10)//sleep 10 so theres less lag you can probably make this lower if you want NPCs to move faster
if(T.woken>0&&get_dist(T,M)>5&&T&&M)//if T's woken is higher than 0 and the distance between T and M is 5 or more and T exits and M exists
step_rand(T)//Take a Random step
T.woken-=1//Subract 1 from T's woken
else if(get_dist(T,M)<6&&T&&M)//else if the distance between T is lower than 6(meaning 5 or less) and T exists and M exists
step_towards(T,M)//take a step towards M
if(get_dist(T,M)<=1)//if the distance is 1 or less
T.dir=get_dir(T,M)//Makes it so T faces M
Attack(T)//Calls the attack proc


Okay, is this look right so far? I know I am missing something because its still doing the same thing. You say I need to "preserve the return value". Did I already "override a procedure"? And if not how do I do so?
In response to Garthor
I also want them to kill me after I lose 100 points of my health. How do I do this? They attack me and in the chatbox it says "The zombie attacks Guest-2206884336 for 3 damage!" but it never kills me and I want them to kill me once it reaches x number (in this case 100). Also after I die I want it to show a corpse, how do I do this?