ID:264043
 
mob/Attacking_NPCs/Cactnea
icon='Hoenn Pokemon.dmi'
icon_state = "cactnea"
name = "Wild Cactnea"
New()
//As New() must return, this spawn()s off
//movement_loop(), which is an infinite loop and
//will not end until src is deleted. To work around
//this replace the condition in the while loop
//below.
spawn() movement_loop()

proc/movement_loop()
while(1)
//This checks to find a /mob within eight tiles
//of the src.
var/mob/m = locate(/mob) in oview(src, 8)

//If m is found, step towards it. If not, just
//wander randomly.
if(m) step_towards(src, m)
else step_rand(src)

//Wait five ticks before iterating again.
sleep(5)

Bump(mob/m)
//This checks to see that m is, in fact, a /mob.
if(istype(m))
//If it is, attack.
attack(m)


Problem description:

The NPCs Will attack and kill each other, how do i fix it?
Change the type of mob being located to whatever the type players are. So, locate(/mob/player), for example.
In response to Garthor
mob/Attacking_NPCs/Cactnea
icon='Hoenn Pokemon.dmi'
icon_state = "cactnea"
name = "Wild Cactnea"
New()
//As New() must return, this spawn()s off
//movement_loop(), which is an infinite loop and
//will not end until src is deleted. To work around
//this replace the condition in the while loop
//below.
spawn() movement_loop()

proc/movement_loop()
while(1)
//This checks to find a /mob within eight tiles
//of the src.
var/mob/m = locate(/mob/player) in oview(src, 8)

//If m is found, step towards it. If not, just
//wander randomly.
if(m) step_towards(src, m)
else step_rand(src)

//Wait five ticks before iterating again.
sleep(5)

Bump(mob/m)
//This checks to see that m is, in fact, a /mob.
if(istype(m))
//If it is, attack.
attack(m)

that gives me /mob/player undefined type path..i know how to make a type path, put not really like this..
In response to Reno Kujika
No, you just put whatever your player mob is. For example, if I made all my players /mob/pie, you would put /mob/pie. What Garthor said was used as an example.
In response to Jeff8500
o.o; errrr I know i should know how to do this..but i dont..how do u set like(Jeff and Garthor said)/mob/player /mob/pie, i dont get it how would u set that..?
In response to Reno Kujika
What is the type of your players? If it's /mob then you have to do something, maybe add if(M&&M.client) or something?
In response to Garthor
A simpler way is to change this line:
if(m) step_towards(src, m)

To this:
if(m && m.client) step_towards(src, m)
In response to Popisfizzy
I don't think that's good because mob/Attacking_NPCs/Cactnea may ignore a player or players if it found a mob with no client.
In response to Jemai1
A mob isn't controlled by a player if it doesn't have an attached client.
In response to Popisfizzy
Movement loop:
1. Looks for a mob
2. If the mob has a client, step towards to it. If it doesn't step randomly.
3. Sleep for 5 ticks before looping.


Here's a situation:

M - mob (npc)
P - mob with client (player)
A - mob/Attacking_NPCs/Cactnea
T - turf

TTTTTTTTTTTTTTTTT
TTTTTTTTTTTTT<font color="yellow">M</font>TTT
TTTTTTTTTTTTTTTTT
TTT<font color="orange">P</font>TTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT
TTT<font color="yellow">M</font>TTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTT<font color=red>A</font>TTTTTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTTTTT<font color="yellow">M</font>TTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTT

1. Haha! M, I found you! Hey! You're a mob!
2. You don't have a client. I guess I'll just walk randomly.
3. Let me rest for 5 ticks.

1. Hey! Another M, you're a mob too! I found you!
2. You don't have a client. I guess I'll just walk randomly.
3. Let me rest for 5 ticks.

1. Hey! P, you're a mob too!
2. Oh no! You have a client. Enemy sighted! I'll come for you!
3. Let me rest for 5 ticks.

See what I mean?
In response to Jemai1
Ah, yes. In that case, he will either have to do what Garthor said, or do the following:
var/mob/m
for(m in oview(src, 8)) if(m.client) break
In response to Popisfizzy
I think you mean..
var/mob/m
for(var/mob/M in oview(src, 8))
if(M.client)
m = M
break


You have a double definition there.
In response to Jemai1
Whoops; that I do.
In response to Popisfizzy
We don't care about mobs that are CONTROLLED by players, we care about mobs that ARE players. A system that lets a player log out at any time to escape death is not a particularly great one.
In response to Garthor
Exactly, I agree.
Pop suggested to replace the istype() check with a client check, but checking the type, client, and key all have different effects, they're not equivalent. Checking for a key would be more suitable here if you don't have player mobs under a specific subtype.