ID:162296
Jan 28 2008, 7:35 am
|
|
Yes, that's wAndering not wOndering. What's the best way of making AI's wander around? I used to be able to do it but now it just creates lag for some reason. thanks
|
Jan 28 2008, 7:42 am
|
|
Best thing to do is to find an AI demo and see what the fine points are of the code, but all is basically is is "walk_rand(src,delay)"
|
In response to Jholder84
|
|
Thanks, that took a while to work into my code because i'd done something stupid with the move_allowed var, lol.
Can I make the delay a random number between, say, 5 and 600 each time? I tried walk_rand(src,rand(5,600)) but of course that sets one random number, and it never changes. Is there a way? (When I tested this example, one of my shopkeepers got stuck on something less than 10! He was rand_walking like a headless chicken! Its hilarious, try it sometime.) |
In response to Adam753
|
|
So that command doesn't re randomize apparently. I did this:
var/randmove = rand(5,60) walk_rand(src,randmove) 600 seemed WAY too long of a pause so I changed it to 60. Worked pretty good. Of course you could go crazy with this: var/pickrandmove = rand(1,100) Like I said, you can go crazy with this and have fun. |
In response to Adam753
|
|
or you just make a recursive proc
mob Notice that with this heirarchy the only mob with the wander() will be of type /mob/NPC/wanderer and anything that is a child of that type (/mob/NPC/wanderer/chicken has wander() ). Of course you'll have to figure out where you want to call wander(). You may also want to edit it so: That it is more robust--so you don't get null.wander() runtime errors. That it can be stopped because this one goes on forever. |
In response to Jholder84
|
|
Well, I don't want them to move TOO often as i'm going to be trying to fight them and talk to them! thanks, i'm sure I can do a lot with that.
|
In response to Adam753
|
|
It's easy enough to add in a test to have them stand still if you're within a certain distance from them.
stop_move() Something like that and add src.stop_move() after your walk_rand line. |
In response to Jholder84
|
|
I know that, but all my verbs set src in oview(1) so cn you imagine trying to catch and ose a verb on something moving once every 2 seconds? I can do the rest myself, thanks for your help.
|
In response to Adam753
|
|
I'd like to point out that Jholder84 has been wrong in every single one of his posts here. Moving on, this is what you want:
mob/proc/NPCwander(var/mindelay = 10, var/maxdelay = 10) |
In response to Garthor
|
|
It may not be the way that YOU do it or even the way you SHOULD do it, but that does not change the fact that the code that I gave works. But this is not the place for this so I will now leave it alone.
|
In response to Jholder84
|
|
No, none of your code works. It works in the sense that it would compile, but it doesn't work in the sense that it doesn't do what you want it to do. The first thing you posted just does precisely what he said he DOESN'T want, and the second thing you posted just does precisely nothing, except waste CPU cycles.
|