Post your ai_random_wander() proc and let us have a look at that. I'll assume that it uses some sort of loop which moves the npc, in which case you should not be calling the proc over and over again (when the player moves).

I'll be able to give better advice once I see the code for it.
        ai_random_wander()//random wander if no mobs are in range to attack
if(src.key)//if the source is human
return//don't call the rest
if(!src.edoEnemyKisame&&!src.FiveTails&&!src.TenTails&&!src.Stranger&&!src.weaknin&&!src.orochimaru&&!src.Kyuubiface&&!src.Aeishiou&&!src.EnemyTele&&!src.EnemyShield&&!src.EnemySasori&&!src.EnemyKisame&&!src.EnemyZetsu&&!src.EnemyTobi&&!src.EnemyDeidara&&!src.EnemyLeader&&!src.EnemyKonan&&!src.Tobiobito&&!src.EnemyItachi&&!src.EnemyKakuzu&&!src.EnemyHidan&&!src.EnemyKimimaro&&!src.EnemySakon&&!src.wildbeast&&!src.EnemyJiroubou&&!src.EnemyTarfex&&!src.gmman&&!src.EnemyTayuya&&!src.EnemyKido&&!src.demon&&!src.guard&&!src.EnemyItachiM&&!src.EnemyMadaraM&&!src.EnemyKakashiE&&!src.EnemyNarutoE&&!src.EnemySasukeE&&!src.EnemyJiraiyaE&&!src.EnemyHokageE&&!src.Peinbody1&&!src.Snake89)
return
else
walk_rand(src,10)//walk randomly with 5 lag
src.ai_run_away()
spawn(10)//delay for one tick
ai_random_wander()//wander some more

The if(src.key) is there cuz i have a verb which lets us control NPC
The problem is that not only does that look like it infinitely loops, but the proc is also stacking every time a player moves, which is causing the lag.

First off, you only need to call that proc if the NPC is inactive.
mob/proc/ai_check()
for(var/mob/M in hearers(6))
if(M.NPC && !M.NpcActive) //If they are an NPC and not Active
M.NpcActive = 1 //Make them Active
M.ai_random_wander() //Call the wander proc


The proc should continue while the NPC is Active. At the end of the proc, you should check to see if the NPC should remain active (Checking for players within range for example). However you decide to work it, setting NpcActive=0 will break out of the while loop and end the proc.
mob/proc/ai_random_wander()
while(NpcActive) //Loop while they are Active
var/playercheck = 0

//do your stuff

for(var/mob/M in hearers(6))//Check for players
if(M.client)
playercheck = 1
if(!playercheck) //If no players, deactivate NPC
NpcActive = 0 //Which will stop the loop and proc

sleep(world.tick_lag) //Small delay to keep things running smoothly
There we go, you are calling the proc within itself and not giving any kind of escape. This means that whenever the proc triggers it is just going to keep going and going.

We need to put some way for it to exit, so you could do something like.

ai_random_wander()//random wander if no mobs are in range to attack
if(src.key)//if the source is human
return//don't call the rest
if(!src.edoEnemyKisame&&!src.FiveTails&&!src.TenTails&&!src.Stranger&&!src.weaknin&&!src.orochimaru&&!src.Kyuubiface&&!src.Aeishiou&&!src.EnemyTele&&!src.EnemyShield&&!src.EnemySasori&&!src.EnemyKisame&&!src.EnemyZetsu&&!src.EnemyTobi&&!src.EnemyDeidara&&!src.EnemyLeader&&!src.EnemyKonan&&!src.Tobiobito&&!src.EnemyItachi&&!src.EnemyKakuzu&&!src.EnemyHidan&&!src.EnemyKimimaro&&!src.EnemySakon&&!src.wildbeast&&!src.EnemyJiroubou&&!src.EnemyTarfex&&!src.gmman&&!src.EnemyTayuya&&!src.EnemyKido&&!src.demon&&!src.guard&&!src.EnemyItachiM&&!src.EnemyMadaraM&&!src.EnemyKakashiE&&!src.EnemyNarutoE&&!src.EnemySasukeE&&!src.EnemyJiraiyaE&&!src.EnemyHokageE&&!src.Peinbody1&&!src.Snake89)
return
else
walk_rand(src,10)//walk randomly with 5 lag
src.ai_run_away()
if(NpcActive)
spawn(10)//delay for one tick
ai_random_wander()//wander some more
WOULD THIS WORK?
ai_random_wander()//random wander if no mobs are in range to attack
if(src.key)//if the source is human
return//don't call the rest
if(src.!NpcActive)
return
if(!src.edoEnemyKisame&&!src.FiveTails&&!src.TenTails&&!src.Stranger&&!src.weaknin&&!src.orochimaru&&!src.Kyuubiface&&!src.Aeishiou&&!src.EnemyTele&&!src.EnemyShield&&!src.EnemySasori&&!src.EnemyKisame&&!src.EnemyZetsu&&!src.EnemyTobi&&!src.EnemyDeidara&&!src.EnemyLeader&&!src.EnemyKonan&&!src.Tobiobito&&!src.EnemyItachi&&!src.EnemyKakuzu&&!src.EnemyHidan&&!src.EnemyKimimaro&&!src.EnemySakon&&!src.wildbeast&&!src.EnemyJiroubou&&!src.EnemyTarfex&&!src.gmman&&!src.EnemyTayuya&&!src.EnemyKido&&!src.demon&&!src.guard&&!src.EnemyItachiM&&!src.EnemyMadaraM&&!src.EnemyKakashiE&&!src.EnemyNarutoE&&!src.EnemySasukeE&&!src.EnemyJiraiyaE&&!src.EnemyHokageE&&!src.Peinbody1&&!src.Snake89)
return
else
ai_check()//checks the proc and area for players if(ai_check == TRUE)
walk_rand(src,10)//walk randomly with 5 lag
src.ai_run_away()
if(NpcActive)
spawn(10)//delay for one tick
ai_random_wander()//wander some more
also i didnt get the // do your stuff what would i do their? Add the wander() code?
(watch)
mob/proc/ai_random_wander()
while(NpcActive) //Loop while they are Active
var/playercheck = 0

//do your stuff
(//so do i put this??)
walk_rand(src,10)//walk randomly with 5 lag
else
src.ai_run_away()

for(var/mob/M in hearers(6))//Check for players
if(M.client)
playercheck = 1
if(!playercheck) //If no players, deactivate NPC
NpcActive = 0 //Which will stop the loop and proc

sleep(world.tick_lag) //Small delay to keep things running smoothly
In response to Naruto 5292
In the case of the examples that I provided, ai_check() should be called whenever a player moves. Think of it as "take a step, check for enemies, take another step, check for enemies".

If there are inactive enemies within proximity, they will activate and start the ai_random_wander() loop. This loop will continue until the enemy has been deactivated.

In the example I gave, the ai_random_wander() proc will only check to see if there is a player within hearers(6) of the enemy; if there is not, then the enemy will be deactivated. Never use return to stop this proc, always use NpcActive=0. This means that it can be activated again by players.

The space I left for you to "do your stuff" is for you to, well.. do your stuff. This is where you would make the mob move (step in a random direction I'd assume).


In the case of Akando's reply, it will not work as the line "if(!src.edoEnemyKisame..." appears to be indented wrongly and the last two lines need indented once more so that they will only be called when if(NpcActive) is true.

If you tell us in detail exactly what you want the proc to do, we could assist you further.
Well I want the proc to check if players are around the NPC so if there is a player then NpcActivate=1

BUT when the player is NOT CLOSE TO The NPC
THEN NpcActive=0

maybe something like
mob/proc/ai_check()
for(var/mob/M in hearers(6))
if(M.NPC && !M.NpcActive) //If they are an NPC and not Active
M.NpcActive = 1 //Make them Active
M.ai_random_wander() //Call the wander proc
else
if(M.NPC && M.NpcActive)
ai_check()
on that last ai_check() i want it to check if the player is still in range (whether the npc shud stay actiavted)
Also yes the //do your stuff part i added the movement
mob/proc/ai_random_wander()
while(NpcActive) //Loop while they are Active
walk_rand(src,10)//walk randomly with 5 lag
src.ai_run_away()
var/playercheck = 0

for(var/mob/M in hearers(6))//Check for players
if(M.client)
playercheck = 1
if(!playercheck) //If no players, deactivate NPC
NpcActive = 0 //Which will stop the loop and proc

sleep(world.tick_lag) //Small delay to keep things running smoothly

Is there a way so like u see how it is IF the player is in view (in hearers) then it ACTIVATES is there a way like if the player IS NOT in view hearers) then DE-ACTIVATE
Btw thanks for the help and trying to help
In response to Naruto 5292
Read what Danny posted. It has everything you need.
Wow, Thanks MDC.. i re-read what danny was saying and it made much more sense than before and also danny thank you!
Plz tel lme if this would work or not..
mob/proc/ai_check()
for(var/mob/M in hearers(6))
if(M.NPC && !M.NpcActive)
M.NpcActive = 1
M.ai_random_wander()

var/playercheck = 0
mob/proc/ai_random_wander()
while(NpcActive)
walk_rand(src,10)//walk randomly with 5 lag

for(var/mob/M in hearers(6))//Check for players
if(M.client)
playercheck = 1
if(!playercheck)
NpcActive = 0

sleep(world.tick_lag)

so it is like.. the npc walks then it checks for for(var/mob/M in hearers(6))
and if it find one, it is player check=1 (it stays active) other wise it de-activates
As the ai_random_wander() proc uses a while loop (meaning it will run over and over again until the loop is broken), you should use step_rand() instead of walk_rand().

Also, keep the playercheck variable inside the ai_random_wander() proc (after the while loop is initiated) so that it is unique to the proc.
Hmmm ok so like this? also what is sleep(world.tick_lag) being used for?

mob/proc/ai_check()
for(var/mob/M in hearers(6))
if(M.NPC && !M.NpcActive)
var/playercheck = 0
M.NpcActive = 1
M.ai_random_wander()

mob/proc/ai_random_wander()
while(NpcActive)
var/playercheck = 0
step_rand(src,10)//walk randomly with 5 lag

for(var/mob/M in hearers(6))//Check for players
if(M.client)
playercheck = 1
if(!playercheck)
NpcActive = 0

sleep(world.tick_lag)

Be careful about assuming walk_rand and step_rand have the same arguments. You are telling it to step 10 pixels there. Step only happens once, so the delay argument you were using is no longer needed.
when i use those 2 codes it says
newwalking.dm:10:error: inconsistent indentation
newwalking.dm:13:error: inconsistent indentation
newwalking.dm:15:error: inconsistent indentation
newwalking.dm:17:error: inconsistent indentation

I indented again and again properly using tabs but it didnt work plz help?

mob/proc/ai_check()
for(var/mob/M in hearers(6))
if(M.NPC && !M.NpcActive)
var/playercheck = 0
M.NpcActive = 1
M.ai_random_wander()

mob/proc/ai_random_wander()
while(NpcActive)
mob/var/playercheck = 0
walk_rand(src,10)//walk randomly with 5 lag

for(var/mob/M in hearers(6))//Check for players
if(M.client)
playercheck = 1
if(!playercheck)
NpcActive = 0

any help?? I have tried changing the code, re-writting it again but it doesn't work
Depends, when it says inconsistent indention that means somewhere in your code you indented one way, and now you are indenting it a different way. It could be:

mob/var/playercheck = 0


Try moving it being where you defined the other mob vars at.
Page: 1 2 3 4 5