Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   NPCs sleeping (https://forums.graalonline.com/forums/showthread.php?t=72270)

cbk1994 02-18-2007 08:03 PM

NPCs sleeping
 
I need to wake up the NPCs in a certain level where noone is in (It's a gmap).
Is there any possible way to do this?

godofwarares 02-18-2007 08:05 PM

PHP Code:

if (playerscount == 0)
{
 
//...



Chompy 02-18-2007 08:06 PM

What you mean? You want a timeout to keep going when no one is in the level?
Or if you know the npc id you can do trigger( "update", "");?

Chandler 02-18-2007 08:10 PM

Quote:

Originally Posted by godofwarares (Post 1278937)
PHP Code:

if (playerscount == 0)
{
 
//...



I'd go with this^^

cbk1994 02-18-2007 08:49 PM

Quote:

Originally Posted by Chompy (Post 1278938)
You want a timeout to keep going when no one is in the level?

Exactly
[Edit: or a way to wake it up using a script]

godofwarares 02-18-2007 11:08 PM

PHP Code:

function onTimeout()
{
     if (
playerscount == 0)
     {
          
//...
     
}

     
setTimer(0.05);


Put your code where the "//..." is and it will only initiate when there are no players in the room.

cbk1994 02-18-2007 11:34 PM

I know that. When noone is in the level, the NPCs sleep. They don't do anything. The timeout stops, etc.

excaliber7388 02-18-2007 11:38 PM

Do it serverside?

cbk1994 02-19-2007 12:08 AM

Quote:

Originally Posted by excaliber7388 (Post 1279037)
Do it serverside?

Uhm ... it is serverside?

Admins 02-19-2007 12:21 AM

The npc timeout is not stopped when players leave. Eventually you have set the serveroptions so that the npcserver is sleeping when no player is online?

godofwarares 02-19-2007 12:59 AM

Quote:

Originally Posted by cbkbud (Post 1279034)
I know that. When noone is in the level, the NPCs sleep. They don't do anything. The timeout stops, etc.

Maybe you could set a variable like this:

PHP Code:

function onCreated()
{
     if (
this.initiate)
     {

          
//...

     
}
     
     
setTimer(0.05);
}

function 
onTimeout()
{
     if (
playerscount == 0)
     {
          
this.initiate false;
     } else {
          
this.initiate true;
     }

     if (
this.initiate)
     {
          
// Do whatever code you want.
     
}

     
setTimer(0.05);


( I feel as though i've made a mistake in the above code, but it looks fine ... )

xXziroXx 02-19-2007 04:41 AM

Add this to serveroptions:

PHP Code:

sleepwhennoplayers=false 


cbk1994 02-19-2007 06:32 AM

Let me try to clear this up ...
The NPC-Server has just been rebooted.
None of the levels are loaded.
I want the NPCs to be loaded before a player enters.
I have a setlevel2, but before that I want to wake the level's NPCs.

WAKENPCS();
sleep( 1 );
setlevel2( ... );

Googi 02-19-2007 07:02 AM

Quote:

Originally Posted by cbkbud (Post 1279255)
Let me try to clear this up ...
The NPC-Server has just been rebooted.
None of the levels are loaded.
I want the NPCs to be loaded before a player enters.
I have a setlevel2, but before that I want to wake the level's NPCs.

Huh? Are you saying that the NPCs are asleep by default (i.e. they're asleep even though they haven't been commanded to sleep?)

If you want to wake up an NPC from another level, getnpc (or I guess now findnpc) should do the trick.

Chandler 02-19-2007 09:29 AM

Quote:

Originally Posted by Googi (Post 1279260)
Huh? Are you saying that the NPCs are asleep by default (i.e. they're asleep even though they haven't been commanded to sleep?)

If you want to wake up an NPC from another level, getnpc (or I guess now findnpc) should do the trick.

Or you could do something like
HTML Code:

npcs[testnpc(this.x, this.y)].trigger("activateNPC", "");

Admins 02-19-2007 10:52 AM

Ok so its about local level npcs ? Levels are not loaded when there is no player, so if you want to have npcs always awake it is best to use putnpc2s.

Another way is to let some dbnpc/putnpc2 do findareanpcs() on the area that you want to have alive, but that would be more a hack than a solution.

You can also use special gmap options in your case:

LOADFULLMAP
will load the full gmap and not deactive map parts, although it will slow down the start of the server.

LOADATSTART
levelnames,...
LOADATSTARTEND
will load the specified levels at the npcserver start, then you just need to use some timeout (and eventually findareanpcs() from time to time) to prevent the level from unloading.

Googi 02-20-2007 02:18 AM

Quote:

Originally Posted by Chandler (Post 1279276)
Or you could do something like

Doesn't that only work for NPCs that are in the same level?

cbk1994 02-20-2007 02:50 AM

Quote:

Originally Posted by Stefan (Post 1279283)
it is best to use putnpc2s.

NPC Code:
/clearnpcs battleground.gmap


Chandler 02-20-2007 09:53 AM

Quote:

Originally Posted by Googi (Post 1279604)
Doesn't that only work for NPCs that are in the same level?

Only if you assign it to, I suppose. I suspect it would work on a GMap.

cbk1994 02-21-2007 03:27 AM

What is findareanpcs()?
Wiki tells me nothing.

Riot 02-21-2007 06:41 AM

Quote:

Originally Posted by cbkbud (Post 1280070)
What is findareanpcs()?
Wiki tells me nothing.

http://wiki.graal.net/index.php/Crea...evel#Functions

findareanpcs(float x, float y, float width float height) object Returns an array of all npcs within the specified area.

cbk1994 02-22-2007 02:00 AM

Quote:

Originally Posted by Riot (Post 1280149)
http://wiki.graal.net/index.php/Crea...evel#Functions

findareanpcs(float x, float y, float width float height) object Returns an array of all npcs within the specified area.

So for this to work I would have to put a DB NPC in the levels, or have 1 DB npc that warps between them all every 5 seconds or so, using this and then somehow calling the NPCs?

Chandler 02-22-2007 11:39 AM

Quote:

Originally Posted by cbkbud (Post 1280497)
So for this to work I would have to put a DB NPC in the levels, or have 1 DB npc that warps between them all every 5 seconds or so, using this and then somehow calling the NPCs?

I wouldn't say every 5 seconds. I'd make it every 5 minutes for each activate.

cbk1994 03-04-2007 09:01 PM

*bump*
What's wrong with this?
PHP Code:

function onCreated()
{
  
canwarp2();
  
canwarp();
  
this.battlegrounds =
    {
      
"syn_battleground1.gmap",
      
"syn_battleground2.gmap",
      
"syn_battleground3.gmap",
      
"syn_battleground3a.gmap",
      
"syn_battleground1_cavec1.nw",
      
"syn_battleground1_cavea1.nw"
    
};
  
setTimer);
}
function 
onTimeOut()
{
  for ( 
temp.ithis.battlegrounds )
  {
    
warptotemp.i3030 );
    for ( 
temp.anpcs )
    {
      
temp.a.trigger"update""" );
    }
    
//echo( this.level.name );
  
}
  
setTimer);



Chandler 03-04-2007 09:06 PM

HTML Code:

function onCreated()
  {
  this.canWarp();
  this.battleGrounds = {
    {"gmap", {1, 2, 3, "3a"}},
    {"nw", {"1_cavec1", "1_cavea1"}}
  };
  setTimer(5);
  }

function onTimeOut()
  {
  for (temp.levelData: this.battleGrounds)
    for (temp.curArea: temp.levelData[1])
      {
      warpto("syn_battleground"@ temp.curArea  @"."@ temp.levelData[0], 0, 0);
      temp.allNPCs = findareanpcs(this.x, this.y, 5000, 5000);
      for (temp.foundNPC: temp.allNPCs)
        temp.foundNPC.trigger("update", "");
      }
  setTimer(5);
  }

Did some alterations...

cbk1994 03-05-2007 12:52 AM

That code didn't work ... It didn't wake all of the npcs in a gmap. It woke the ones in the level it warped to, not the whole gmap ... or maybe it was the players that woke the ones in the level.

Gambet 03-05-2007 12:55 AM

On a side note, players.size() would be the GS2 version of playerscount.

Chandler 03-05-2007 09:24 AM

Quote:

Originally Posted by cbkbud (Post 1284781)
That code didn't work ... It didn't wake all of the npcs in a gmap. It woke the ones in the level it warped to, not the whole gmap ... or maybe it was the players that woke the ones in the level.

temp.allNPCs = findareanpcs(0, 0, 5000, 5000);
Also, check if it's finding any NPCs. EG echo(temp.foundNPC);, what would this produce?


All times are GMT +2. The time now is 06:21 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.