ID:262690
 
Code:
            proc/Wander()
while(src)
if(P in oview(5)) //if a Player comes in 5 steps pf him
step_towards(src,P) //Chase him!
for(P in oview(1)) //here you can define some stuff
break //if you want your NPC to shoot make it so
for(P in oview(2)) //these are saying if the Player is within 1,2,3,4 blocks do nothing
break
for(P in oview(3))
break
for(P in oview(4))
break
else
step_rand(src) //if no NPC is 5 blocks or less away walk around
sleep(10) //stop for 1 second
for(P in oview(5)) //.......
break
sleep(5)
spawn(5)
Wander()//Wonder again...
Bump(mob/M)
if(M.player == 1) //If the NPC bumps you
Fight(M)//Fight You!
else
return

proc/Fight(mob/M)
var/damage = rand(1,10)
M.Health -= damage
M << "[src] attacks you for [damage] damage!!"//This tells "M" they have been attacked
src<<"You attack [M] for [damage] damage!!" //This tells you that you atttack M for how many damage
Dcheck(M) // Run Death Check


Problem description:k for some reason my monsters are runing from me what am i doing wrong here

That is the most awful code for 'wandering monsters' I have ever seen. I have no idea who originally wrote that, but he should die a horrible, HORRIBLE death. Oh, and no put usr in proc. Ungh.

mob/Monster
var/mob/Target
var/SightRange=5
var/AttackRange=1
var/WanderDelay=5
proc/Wander()
for(var/mob/m in oview(src,SightRange)
if(!target) target=m
if(get_dist(target,src)<get_dist(target,m)) target=m
if(target)
if(target in oview(src,AttackRange))
Attack(m) //Assumes there is a mob/prob/Attack() defined. Change as needed
spawn(WanderDelay) Wander()
return
else
step_to(src,target)
spawn(WanderDelay) Wander()
return
else
step_rand(src)
spawn(WanderDelay) Wander()
return


That is untested, but should work to some extent. The monster should attack the nearest player in view, focusing on his first target if there are a few 'closest' players, and walks randomly otherwise. It will step towards its target if it is out of range. Of course, monsters can be made far more intelligent. Focus on the fighters/mages/archers, decide based on level, etc.
In response to Jp
mob/Monster
var/mob/target
var/SightRange=5
var/AttackRange=1
var/WanderDelay=5
proc/Wander()
for(var/mob/m in oview(src,SightRange))
if(!target) target=m
if(get_dist(target,src)<get_dist(target,m)) target=m
if(target)
if(target in oview(src,AttackRange))
Attack() //Assumes there is a mob/proc/Attack() defined. Change as needed
spawn(WanderDelay) Wander()
return
else
step_to(src,target)
spawn(WanderDelay) Wander()
return
else
step_rand(src)
spawn(WanderDelay) Wander()
return


Fixed it for ya..
National Guardsmen wrote:
k for some reason my monsters are runing from me what am i doing wrong here

Well, the main thing is you're using that same crap demo everyone else seems to be using when they run into problems. Which demo is that Wander() proc from?

Lummox JR
In response to Mysame
No, No NO! Attack() needs to take an argument. That's the only change I can see that you've made.

It is far, FAR safer to give Attack() an argument then to assume it will be src.target.
In response to Jp
Jp wrote:
No, No NO! Attack() needs to take an argument. That's the only change I can see that you've made.

It is far, FAR safer to give Attack() an argument then to assume it will be src.target.

Nope, I can't agree on this one. Attack() already knows the target because it's a var belonging to the mob. You don't need to send it extra information, so long as Attack() should always go after the current target.

This is rather unlike when you want the current value of usr to pass from a verb to a proc and want to do it cleanly, because usr is passed silently from proc to proc as a local var and once it leaves the verb you can't trust it unless you've paid very close attention to which procs call each other and know they'll continue to work the same way in the future.

Your heart's in the right place, but your logic isn't. It's not a bit safer to use an argument here since a mob var is already on the job.

Lummox JR
In response to Mysame
Mysame wrote:
mob/Monster
> var/mob/target
> var/SightRange=5
> var/AttackRange=1
> var/WanderDelay=5
> proc/Wander()
> for(var/mob/m in oview(src,SightRange))
> if(!target) target=m
> if(get_dist(target,src)<get_dist(target,m)) target=m
> if(target)
> if(target in oview(src,AttackRange))
> Attack() //Assumes there is a mob/proc/Attack() defined. Change as needed
> spawn(WanderDelay) Wander()
> return
> else
> step_to(src,target)
> spawn(WanderDelay) Wander()
> return
> else
> step_rand(src)
> spawn(WanderDelay) Wander()
> return

Fixed it for ya..

so for the /'s i would put tabs?