ID:265530
 
I wipped up this system, and it works, but it doesn't exactly give a realstic approach to it, monsters just walk around randomly.

How would I go about improving this system, so where they walk a little bit (moreover, they can't leave a certain radius from where they were created)

I want it more... friendly, where the mob only moves whenever a player (or client) is around, but where it does not persue the player, it just moves only when it's around to save CPU space.

(I wouldn't mind a "Aggressive" function, but that would be easy, just adding in walk_to() correct?)

mob/proc/Walk_Rand()
spawn()
sleep(rand(15,20))
walk_rand(src)


(Didn't think this would go under CODE PROBLEMS, mainly because it's not really a problem.)
More Developers How-To, anyways, I think not so long ago someone (Be it Lummox, Unknown Person or O-matic) wrote a little script where the mob couldn't leave a desired area.. Might want to search.
In response to Mysame
Didn't find anything when I did a hub search.
Let me try the forums real quick.
The only way to improve a system is to think of what features you would like to include. It's not enough to simply think "I want this to be more realistic, could someone give me a hand?"

Of course random movement isn't very realistic. I know I don't move around randomly in real life. ;-)

You've gotten a brief start in terms of what you would like the NPCs to do, but you need to define it better. One of my preferred systems is to select a random coordinate in range (e.g., within 20 tiles) and then walk there at a leisurely pace. Once there, wait a random length of time, then analyse the AI's priorities, and choose another coordinate to go to (assuming the task didn't change from "wander").
Flame Sage wrote:
> mob/proc/Walk_Rand()
> spawn()
> sleep(rand(15,20))
> walk_rand(src)
>


Well, when you say realistic, it all depends on how realistic you want it to be! I know you probably didn't want a code to come from someone, but I was bored and had a few ideas, so check this one out.

mob
var
Health=40
MaxHealth=25
Level=1
Strength=15
mob/monster
var
mob/M//M is the monsters target
agression=3
speed=2
thirst=0
Intelligence=50
Health=25
MaxHealth=25
New()
src.walkattack()
proc/walkattack()
spawn while(speed*10)
if(!src.M)
var/mob/O=null
for(var/client/C in orange(src.agression,src))
var/mob/Mob=C.mob
if(Mob)
if(Mob.Level-src.agression<=src.Level&&src.Strength+agression>=Mob.Strength&&Mob.Level>O.Level)
O=Mob
if(O)
src.M=O
walk_to(src,O,src.speed)
else
var/HPPercent=round((src.Health/src.MaxHealth)*100)
if(HPPercent<=round(src.Intelligence/7)&&prob(src.Intelligence))
walk_away(src,M)
view(src) <<"[src] runs away in panic!"
else//the monster is fit for fighting!
src.M.Attack()
Attack()
if(!src.M)//strike back(if agression is 0) 0 agression means completly friendly
src.M=usr
walk_to(src,usr,src.speed)
if(src.M)
if(usr.Level>=src.M.Level)//check if a stronger player is in view!
src.M=usr
walk_to(src,usr,src.speed)
mob/verb/Attack()//attack is called when the usr attacks the src, so the verb is on the src
set src in oview(1)
view(src) <<"[usr] strikes at [src]!"