Here is a basic Daemon I did. It just does two very simple things.
1. Tracks general NPC population. Relatively useless.
2. Stores an array of pending re-spawns and slowly goes through each element of that array and spawns the NPC based on the given info.
/* /daemon/census.c
* This daemon is desgined to recieve queries
on the estimated population of the given NPC.
*/
#include <lib.h>
#include <dirs.h>
inherit LIB_DAEMON;
private mapping Population = ([]);
private string *Deaths;
int eventUpdatePopulation();
int eventSpawn();
static void create() {
daemon::create();
Deaths = ({ });
Population = ([]);
if( unguarded((: file_exists("/save/census.o") :)) ){
RestoreObject("/save/census.o");
}
SetNoClean(1);
eventUpdatePopulation();
eventSpawn();
}
int GetPopulation(string name) {
return Population[name];
}
int AddPopulation(string name) {
if(Population[name]){
Population[name] += 1;
}
else Population += ([name : 1]);
SaveObject("/save/census.o");
return Population[name];
}
int SubtractPopulation(string name) {
Population[name] -= 1;
SaveObject("/save/census.o");
return Population[name];
}
AddDeaths(string str) {
if(Deaths){
Deaths += ({ str });
}
else Deaths = ({ str });
SaveObject("/save/census.o");
return;
}
string array GetTotalDeaths(){
return Deaths;
}
mapping GetTotalPopulation(){
return (Population + ([]));
}
int eventUpdatePopulation(){
foreach(object npc in livings()){
if(environment(npc)){
if(Population[npc->GetKeyName()]){
Population[npc->GetKeyName()] += 1;
}
else Population += ([npc->GetKeyName() : 1]);
}
}
SaveObject("/save/census.o");
call_out("eventUpdatePopulation",300);
}
int eventSpawn(){
string *temp = ({ });
if(sizeof(Deaths)){
temp = explode(Deaths[0],"#");
}
if(sizeof(temp)){
new(temp[0])->eventMove(temp[1]);
Deaths = Deaths[1..];
}
// call_out("eventSpawn",300 + random(300));
call_out("eventSpawn",10);
}
Here is a sample NPC using the re-spawn daemon.
#include <lib.h>
#include <daemons.h>
inherit LIB_SENTIENT;
string *spawnpoints = ({ "/domains/kahara/virtual/dense_forest_sq/14,103","/domains/kahara/virtual/dense_forest_sq/20,98",
"/domains/kahara/virtual/dense_forest_sq/21,107","/domains/kahara/virtual/dense_forest_sq/17,91",
"/domains/kahara/virtual/dense_forest_sq/36,129","/domains/kahara/virtual/dense_forest_sq/59,108",
"/domains/kahara/virtual/dense_forest_sq/81,109","/domains/kahara/virtual/dense_forest_sq/85,146",
"/domains/kahara/virtual/dense_forest_sq/93,141","/domains/kahara/virtual/dense_forest_sq/95,150",
"/domains/kahara/virtual/dense_forest_sq/115,140","/domains/kahara/virtual/dense_forest_sq/114,164",
"/domains/kahara/virtual/dense_forest_sq/115,176","/domains/kahara/virtual/dense_forest_sq/137,159",
"/domains/kahara/virtual/dense_forest_sq/138,141","/domains/kahara/virtual/dense_forest_sq/173,109",
"/domains/kahara/virtual/dense_forest_sq/168,103","/domains/kahara/virtual/dense_forest_sq/172,84",
"/domains/kahara/virtual/dense_forest_sq/174,80","/domains/kahara/virtual/dense_forest_sq/169,73",
"/domains/kahara/virtual/dense_forest_sq/148,41","/domains/kahara/virtual/dense_forest_sq/122,155",
"/domains/kahara/virtual/dense_forest_sq/100,22","/domains/kahara/virtual/dense_forest_sq/85,20",
"/domains/kahara/virtual/dense_forest_sq/80,32","/domains/kahara/virtual/dense_forest_sq/70,29",
"/domains/kahara/virtual/dense_forest_sq/75,68","/domains/kahara/virtual/dense_forest_sq/53,77",
"/domains/kahara/virtual/dense_forest_sq/51,84","/domains/kahara/virtual/dense_forest_sq/48,81", });
static void create() {
sentient::create();
SetKeyName("grey squirrel");
SetId( ({"squirrel", "grey squirrel"}) );
SetAdjectives(({"non player"}));
SetShort("a grey squirrel");
SetLong("This is a generally small animal with a fairly sledner body, bushy tail, and large eyes. Its fur appears fairly soft and silky. This squirrel is dark grey in color. The hindlimbs are somewhat longer than the forelimbs, with five toes on each foot.");
SetPermitLoad(1);
SetWanderSpeed(5);
SetLevel(1);
SetRace("rodent");
SetGender("male");
SetMaxHealthPoints(20);
SetHealthPoints(20);
SetSkill("melee attack", 30);
}
void init(){
::init();
}
eventDie(agent){
CENSUS_D->AddDeaths(base_name(this_object()) + "#" + spawnpoints[random(sizeof(spawnpoints))]);
::eventDie(agent);
}