mob
proc
walkaround()
again
if(!src.enemy in view()||src.enemy==null)
src.enemy=null
for(var/mob/M in view(src))
if(M.client)
src.enemy=M
break
if(src.enemy!=null)
if(src.enemy in view(src))
step_towards(src,src.enemy)
else
step_to(src,src.enemy)
if(src.enemy==null)
step_rand(src)
spawn(10)
goto again
ID:145265
May 4 2006, 12:08 am
|
|
In response to Loduwijk
|
|
I made this for you, but it isn't tested. All you need to do is define an Attack proc.
mob |
In response to Y2kEric
|
|
EWWWW
Procedures to make mobs wander around aimlessly, constantly, generating lag. |
In response to Y2kEric
|
|
Why do you use the following format?
proc/MyFunction() Using a while loop does absolutely nothing there. |
In response to Loduwijk
|
|
So you're telling me it makes a big difference, if so what differences does it make, they both do the exact same thing if I use while(1) or not.
|
In response to Y2kEric
|
|
It doesn't do the exact same thing. Using while like that is similar to doing the following.
mob/verb/attack() It's similar to doing that. Using while in that ai snippet just doesn't do anything. It won't do anything because you're returning inside the loop, so it won't end up looping, and your looping is being done by having the function recall itself. |
Also, the "||src.enemy==null" part in that same if statement is redundant. If enemy is null, it won't be in view and will get caught by the first check.
Inside the second if statement's code block you are checking again to see if enemy is in view. Because of your first if and its code block, if enemy is not null it should always be in your view.
While your third outer if statement (if(enemy==null)) isn't technically wrong, you could save yourself the need for another if statement by just putting it inside the first if statement, putting step_rand(src) just after the src.enemy=null line.
All that aside, the order of operations conflict in the first if statement I mentioned first is probably what is causing the problem.