ID:241592
 
(See the best response by Hashir.)
my NPCS move, but run away. i just recycled a code from my other game temporarly. but i need to make them attack me so i have a chance of dieing.
heres my enemy code
var/mob/PC

mob
NPC

Brolly

name = "{NPC} Brolly"
icon = 'Enemy.dmi'
density = 1

Health=25
Defence=1
Strength=2




New()
. = ..()
spawn()
Wander()

proc/Wander()
while(src)
var/Found = FALSE
for(var/mob/PC in oview(6)).
step_away(src,PC)
Found = TRUE
break
if(Found != TRUE)
sleep(8)
sleep(8)
Best response
step_away(Ref, Trg) moves Ref away from Trg while step_to(Ref, Trg) moves Ref towards Trg.

If you want your NPCs to attack you when they are a certain number of tiles away from you, you can use the get_dist() proc.

Also, your Wander() proc isn't usr safe because oview() has usr set as it's default Center argument.

For more information, read the reference on these procs.

Here is an example too:

mob/NPC

icon = 'npc.dmi'
var/mob/target // A variable that is expected to hold a reference to a mob anytime in future.

New()
..()
spawn() AI_Start()

proc/AI_Start()
while(src)
if(!target) Find_Target()
else
if(get_dist(src, target))
src.Attack(target)
else step_to(src, target)
sleep(15)

proc/Find_Target()
for(var/mob/M in oview(6, src)) // We are now usr safe.
if(!src.target) src.target = M // Our NPC's target variable now holds a reference to a mob.
else return
talk about spam





Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: AI Start (/mob/NPC/Brolly/proc/AI_Start)
usr: {NPC} Brolly (/mob/NPC/Brolly)
src: {NPC} Brolly (/mob/NPC/Brolly)
call stack:
{NPC} Brolly (/mob/NPC/Brolly): AI Start()
{NPC} Brolly (/mob/NPC/Brolly): New(the grass (49,8,1) (/turf/grass))
{NPC} Brolly died in the hands of {NPC} Brolly
{NPC} Brolly died in the hands of {NPC} Brolly
{NPC} Brolly died in the hands of {NPC} Brolly
Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: AI Start (/mob/NPC/Brolly/proc/AI_Start)
usr: {NPC} Brolly (/mob/NPC/Brolly)
src: {NPC} Brolly (/mob/NPC/Brolly)
call stack:
{NPC} Brolly (/mob/NPC/Brolly): AI Start()
{NPC} Brolly (/mob/NPC/Brolly): New(the grass (39,11,1) (/turf/grass))
{NPC} Brolly died in the hands of {NPC} Brolly
{NPC} Brolly died in the hands of {NPC} Brolly
Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: AI Start (/mob/NPC/Brolly/proc/AI_Start)
usr: {NPC} Brolly (/mob/NPC/Brolly)
src: {NPC} Brolly (/mob/NPC/Brolly)
call stack:
{NPC} Brolly (/mob/NPC/Brolly): AI Start()
{NPC} Brolly (/mob/NPC/Brolly): New(the grass (49,13,1) (/turf/grass))
{NPC} Brolly died in the hands of {NPC} Brolly
Konat: Here you go!
Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: AI Start (/mob/NPC/Brolly/proc/AI_Start)
usr: {NPC} Brolly (/mob/NPC/Brolly)
src: {NPC} Brolly (/mob/NPC/Brolly)
call stack:
{NPC} Brolly (/mob/NPC/Brolly): AI Start()
{NPC} Brolly (/mob/NPC/Brolly): New(the grass (40,6,1) (/turf/grass))
Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: AI Start (/mob/NPC/Brolly/proc/AI_Start)
usr: {NPC} Brolly (/mob/NPC/Brolly)
src: {NPC} Brolly (/mob/NPC/Brolly)
call stack:
{NPC} Brolly (/mob/NPC/Brolly): AI Start()
{NPC} Brolly (/mob/NPC/Brolly): New(the grass (46,8,1) (/turf/grass))
Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: AI Start (/mob/NPC/Brolly/proc/AI_Start)
usr: {NPC} Brolly (/mob/NPC/Brolly)
src: {NPC} Brolly (/mob/NPC/Brolly)
call stack:
{NPC} Brolly (/mob/NPC/Brolly): AI Start()
{NPC} Brolly (/mob/NPC/Brolly): New(the grass (47,12,1) (/turf/grass))





wow. lol