Oct 14 2013, 12:19 pm
|
|
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
|
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 |
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 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 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 |
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 |