New()
..()
while(src)
spawn(50)
ai_check()
sleep(world.tick_lag)
To help keep from causing a huge cpu spike.
You may want to use a spawn loop like:
New() To help keep from causing a huge cpu spike. |
That would be better written as:
New() |
Was my explanation and examples really that hard to follow?
ai_check() should not be called by the NPC (enemy, monster etc.) and it should definitely not be a constant loop. It should be called by the player whenever they move, this way as you are walking around, it checks for enemies. var/playercheck is not a mob variable, it is local to the ai_random_wander() proc and should be created like so: proc/ai_random_wander() Placing this variable elsewhere will have undesirable effects. |
ya thats what I did, i added it to the movement code for players. They told me to add it to npc so i was just about to do it..thanks anyways i added it again to the movement
|
But wont that cause lag when the player is around lots of NPC..for example when they go into a forest with lots of npc in it won that make them lag?
|
In the game, there is a forest where you have to kill lots of npc (there are many npc in that forest) and I was wondering if that could affect the player's movement (lag,crashes, etc)
|
There are other ways of activating and deactivating enemy AI.
|
YA i LIKE THIS WAY THOUGH, IT IS EASY And SIMPLE... (EASY TO UNDERSTAND AND SIMPLE TO CODE)... SO i WAS WONDERING IF IT WOULD CAUSE LAG? WOULD IT?
|
Naruto 5292 wrote:
YA i LIKE THIS WAY THOUGH, IT IS EASY And SIMPLE... (EASY TO UNDERSTAND AND SIMPLE TO CODE)... SO i WAS WONDERING IF IT WOULD CAUSE LAG? WOULD IT? Read the post he linked you. "causing lag" is really just a concern of bad design. |
well i tried adding the code, it works but the problem is that when one person goes to a npc....the server crashes.. I have tried lots of things to prevent it but it just wouldn't work so i came back here asking for help....
|
mob |
He's just going to copy and paste what ever you show him.
That's why he's having the instant crash cause he copy and pasted what Danny Roe showed him as if it was plug and play and probably smashed his keyboard until compile errors were no longer there. |
And it's even worse when people post bad examples.
In reference to the latest code snippet given, var/playercheck has once again been left out of the ai_random_wander() proc. You have also advised using walk_rand() instead of step_rand(). To the OP, I suggest you set your goals a little smaller until you understand the language better. Read through the Guide and check out some of the beginner tutorials. |
That was copy and pasted from previous post. Was just giving an example as to how he should be using sleep in the while loop.
|
mob Wouldn't this be better so when there is NO player the NPC just deletes... |
You need to put a while loop for the New() proc otherwise it will call it once, if no player is in view then the mob will just sit there.
We need the loop to continually check while the mob exists so that it keeps looking to see if any players are within it's area.