I didnt get all of what Doohl was saying, I get the checking distance and all that but i didnt get the part after that
HE wants you to make the AI check to see if a player is near if not do nothing/shut down until one is near, something along the lines of that.
How wold I do that? I think I might have npc already like that.. The NPC just walk around and when someone is near they attack. So is that what he is talking about? IF so, that is already in but in-actiavte? They always walk around so plz help me Ill try to post a code of a npc or something if you want
I have a proc for npc to check if players are around them. If they aren't then they just walk around with ai_wander()
Maybe if one of you could help with TeamViewer maybe?? If you have it message me on pager and help me out. Thanks
Just post the AI code here. That's what this forum is for.
In response to Naruto 5292
There's your problem you have it consistently walking around, it should only move when a player is on screen, if you have a lot of mobs moving at once random'y its bound to cause lag.

you could try having them move once every 8-20 secs in a random dir, that might cut the lag a lot. But best bet is to only have an active AI when a player is near them.
In response to Naruto 5292
Naruto 5292 wrote:
I have a proc for npc to check if players are around them. If they aren't then they just walk around with ai_wander()

The suggestion made is to completely inactivate NPCs, including movement, when no one is around them.

The problem is that your ai_random_wander() is also calling other procedures (or mob.Move() is calling those procedures)

Your NPCs just "wandering around" are actually still doing a lot of work (a view() check per step, perhaps? running that "ai_run_away()" proc every step? etc. etc.)

If there's is no real reason to have the NPCs moving around when no one's there to see it, then it's probably best to just not have them doing it. Sure, some games require this; the AI is designed to perform functions on its own, like gather food, or build things, or whatever, and in those games, the AI has to do its thing no matter who's there to see it. But for most games, the AI doesn't need to do anything at all unless the player can see them.

In fact, going one step further, most games don't even need the NPCs to exist unless the player is nearby. Most games could simply have the AI spawn just outside the player's view (so by the time he steps into their view, he'll never know the difference), and the delete themselves when the player moves far enough away.

But if you must have your map covered in NPCs at all times, then simply set it so they do absolutely nothing until the player moves into a certain range (just larger than his view, so that they're active just before he reaches them).

And the best way to do this is not to have the NPCs check, but to have the player "broadcast" his presence. If you design it so the NPCs check for the player, then they'll need some kind of continuous looping check (which is inefficient). It is much better to have the player's Move() proc (or similar function) search a range() around him, and activate any NPCs found (and deactivate any others that are now outside of the minimum range)
        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

ai_run_away()//used for checking to see if it should run or attack
if(src.client)
return
else
for(var/mob/M in oview(7,src))//loops over all mobs within 5 tiles of the monster
if(M.client)//if the mob is human
if(get_dist(src,M) <= 5)//if the player is close
if(src.weaknin||M.NPC)
return
else
src:random = rand(1,5)
if(src:random == 5)
src.jutsu()
src.ai_walk_to()
else
src.ai_walk_to()
else
src.jutsu()//calls the walk_to (for attacking) proc
else
return
so how do i make it so they only move when a player is close??
so how would i make it so npc dont move when no player is around them can u plz put it in code or somthing?
You need to edit your basic movement code

client
North(mob/M in view(6)) //defines mobs as M within 6 tiles of view
if(!usr.Frozen) //if the user isn't frozen
step(usr,NORTH) //walk up
if(mob/M in view(6)&&M.NPC&&!M.NpcActive) /*if there's a mob within view, they're
an npc and they're inactive*/

M.NpcActive = 1 //activate the mob


Then you can start the entire code of your npcs with
while (src.NpcActive)

or
if(src.NpcActive)


I'm not saying this is the most ideal way to edit the movement codes, but it's one of the less elaborate ways to go about doing it
Allow me to recorrect myself by the way

client
North(mob/M in view(6)) //defines mobs as M within 6 tiles of view
if(!usr.Frozen) //if the user isn't frozen
step(usr,NORTH) //walk up
for(mob/M in view(6)&&M.NPC&&!M.NpcActive) /*if there's a mob within view, they're
an npc and they're inactive*/

M.NpcActive = 1 //activate the mob
for(mob/M in view(/*either 6,8 or 6,2*/)&&M.NPC&&M.NpcActive)
M.NpcActive = 0


I prefer using for over if when the occasion shows itself

edit; about the second for line. I'm not sure if it's 6,8 or 6,2,
as I never used view scaling in DM.

6,8 could mean "starting 6 tiles away, ending 8 away"

or it could mean "starting from 6 tiles, and 8 tiles from that point on"
which would mean you'd use 6,2 instead
so add that to my movement proc?
and add mob/var/NpcActive=0
Try to actually understand what the code does. Also, personally, I wouldn't go with the client/Move() example.
right now im just confused of what to do, people tell me different things and the code is a bit confusing i tried doing that but i confused my self more and now im just stuck can someone explain this a bit??
i took out the random wander code but now they dont move at all, so how do i make them move?
Refer back to my last comment btw, I forgot the line for making the mob/npc INACTIVE again.

Keep in mind you shouldn't bluntly copy paste these codes, they're a reference, and incomplete.

This way you could make mobs that are focused on other people, but just outside your own range inactive, which isn't supposed to happen.

Examples have been given, it's up to you to toy around with them and see what works for you best. Come to understand what they actually do
i cant find my basic movement code, and so when i do i add that code u put above?
Page: 1 2 3 4 5