ID:149397
 
My monesters chase me around when they spawn, i dont like that. how do i make it so they can only move within a certain area unless they c a player?
Heres my code for a troll monster:
mob
NPC
Troll
name = "Troll"
icon = 'monster.dmi'
icon_state = "troll"
HP = 20
Max_HP = 20
strength = 3
exp_give = 5 //set the vars
var/mob/PC/P //set a new var, the path is /mob/PC, and we will name it for easier typing P.
New() //This is called when the atom enters the world
. = ..()
spawn(99) //Spawn here to prevent crashing. If you want it to wait a set amount of time before calling Wander(), then put a number in the middle of the spawn arguments.
Wander(2)
proc/Wander()
while(src) //While the mob is still here...
if(P in oview(5)) //If there is a PC in the area, as set with the P var above....
step_towards(src,P) //Step towards the PC
for(P in oview(1)) //If the mob is in its view of 1...
break
for(P in oview(2))
break
for(P in oview(3))
break
for(P in oview(4))
break //All these for() procs make it so when the mob is chasing you, and someone else gets closer to the mob then you are, it will stop chasing you and attack the other person. Also it makes it so you can code in that the mob will do stuff at different ranges. Its a great way to prevent types of Kiting (A.K.A. running away from the mob while another attacks it)
else //Else, in other words if the if statement or statements stated above is false...
step_rand(src) //Step randomly once.
sleep(10) //Wait one second
for(P in oview(5)) //But if a PC appears in sight of it...
break
sleep(5) //Dont do anything for 0.5 seconds
spawn(5)
Wander() //Create a loop that continues the proc over and over again untill the mob is deleted.
Bump(mob/M) //Override this to tell what it does
if(istype(M,/mob/PC))
Attack(M) //Attack it with a proc that is defined below.
proc/Attack(mob/M) //new proc called attack
flick("Stick_Attack",src) //"Stick_Attack" is an Icon state in the stick1 file, the flick proc makes it look like its actuly attacking the other mob. This is a visual only, it creats better gameplay, easier on the eyes.
sleep(2) //This give the animation time to play, and sets the attack delay for this mob. Dont put this on PCs or evil little errors will keep popping up. I can make it different though so just ask me how to make a more advanced attack verb for PCs.
var/damage = rand(1,strength)
M.HP -= damage
view(src) << "[src] attacks [M]!" //in view of the attacker, show this message...
view(src) << "[damage] damage!" //Same here
M.Death() //call the death proc to the victim

what should i do?