Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-18-2007, 08:03 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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?
__________________
Reply With Quote
  #2  
Old 02-18-2007, 08:05 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
PHP Code:
if (playerscount == 0)
{
 
//...

__________________
What signature? I see no signature?
Reply With Quote
  #3  
Old 02-18-2007, 08:06 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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", "");?
__________________
Reply With Quote
  #4  
Old 02-18-2007, 08:10 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by godofwarares View Post
PHP Code:
if (playerscount == 0)
{
 
//...

I'd go with this
Reply With Quote
  #5  
Old 02-18-2007, 08:49 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Chompy View Post
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]
__________________
Reply With Quote
  #6  
Old 02-18-2007, 11:08 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
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.
__________________
What signature? I see no signature?
Reply With Quote
  #7  
Old 02-18-2007, 11:34 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
I know that. When noone is in the level, the NPCs sleep. They don't do anything. The timeout stops, etc.
__________________
Reply With Quote
  #8  
Old 02-18-2007, 11:38 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
Do it serverside?
Reply With Quote
  #9  
Old 02-19-2007, 12:08 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by excaliber7388 View Post
Do it serverside?
Uhm ... it is serverside?
__________________
Reply With Quote
  #10  
Old 02-19-2007, 12:21 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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?
Reply With Quote
  #11  
Old 02-19-2007, 12:59 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
Quote:
Originally Posted by cbkbud View Post
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 ... )
__________________
What signature? I see no signature?
Reply With Quote
  #12  
Old 02-19-2007, 04:41 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Add this to serveroptions:

PHP Code:
sleepwhennoplayers=false 
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #13  
Old 02-19-2007, 06:32 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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( ... );
__________________
Reply With Quote
  #14  
Old 02-19-2007, 07:02 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
Quote:
Originally Posted by cbkbud View Post
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.
__________________
Reply With Quote
  #15  
Old 02-19-2007, 09:29 AM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by Googi View Post
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", "");
Reply With Quote
  #16  
Old 02-19-2007, 10:52 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #17  
Old 02-20-2007, 02:18 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
Quote:
Originally Posted by Chandler View Post
Or you could do something like
Doesn't that only work for NPCs that are in the same level?
__________________
Reply With Quote
  #18  
Old 02-20-2007, 02:50 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Stefan View Post
it is best to use putnpc2s.
NPC Code:
/clearnpcs battleground.gmap

__________________
Reply With Quote
  #19  
Old 02-20-2007, 09:53 AM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by Googi View Post
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.
Reply With Quote
  #20  
Old 02-21-2007, 03:27 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
What is findareanpcs()?
Wiki tells me nothing.
__________________
Reply With Quote
  #21  
Old 02-21-2007, 06:41 AM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
Quote:
Originally Posted by cbkbud View Post
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.
Reply With Quote
  #22  
Old 02-22-2007, 02:00 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Riot View Post
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?
__________________
Reply With Quote
  #23  
Old 02-22-2007, 11:39 AM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by cbkbud View Post
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.
Reply With Quote
  #24  
Old 03-04-2007, 09:01 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
*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);

__________________
Reply With Quote
  #25  
Old 03-04-2007, 09:06 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
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...
Reply With Quote
  #26  
Old 03-05-2007, 12:52 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #27  
Old 03-05-2007, 12:55 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
On a side note, players.size() would be the GS2 version of playerscount.
Reply With Quote
  #28  
Old 03-05-2007, 09:24 AM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by cbkbud View Post
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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:57 PM.


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