mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
206 lines
3.5 KiB
Plaintext
206 lines
3.5 KiB
Plaintext
include library.ai_lib;
|
|
include library.create;
|
|
include library.utils;
|
|
|
|
trigger OnInitialize() {
|
|
|
|
messageTo (self, "beginSpawning", null, 30, false);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnDestroy() {
|
|
|
|
obj_id[] spawnList = getObjIdArrayObjVar(self, "spawnList");
|
|
|
|
if(spawnList == null || spawnList.length == 0)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
for(int i = 0; i < spawnList.length; i++) {
|
|
|
|
if(isIdValid(spawnList[i]))
|
|
destroyObject(spawnList[i]);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler beginSpawning() {
|
|
|
|
string strNumToSpawn = getStringObjVar(self, "pop");
|
|
int numToSpawn = utils.stringToInt(strNumToSpawn);
|
|
|
|
if (numToSpawn < 1) {
|
|
|
|
setObjVar(self, "pop", 1);
|
|
numToSpawn = 1;
|
|
}
|
|
|
|
if (numToSpawn > 5) {
|
|
|
|
setObjVar(self, "pop", 5);
|
|
numToSpawn = 5;
|
|
}
|
|
|
|
string npcType = getStringObjVar(self, "type");
|
|
|
|
if (npcType == null) {
|
|
|
|
npcType = "none";
|
|
}
|
|
|
|
if (npcType == "none") {
|
|
|
|
setObjVar (self, "type", "thug");
|
|
npcType = "thug";
|
|
}
|
|
|
|
string name = getStringObjVar(self, "name");
|
|
|
|
if(name == null) {
|
|
|
|
name = "default";
|
|
}
|
|
|
|
string behavior = getStringObjVar(self, "behavior");
|
|
|
|
if(behavior == null) {
|
|
|
|
behavior = "default";
|
|
}
|
|
|
|
string objVarName = getStringObjVar(self, "objvarname");
|
|
string objVarType = getStringObjVar(self, "objvartype");
|
|
string objVarValue = getStringObjVar(self, "objvarvalue");
|
|
|
|
if(objVarName == null) {
|
|
|
|
objVarName = "none";
|
|
|
|
} else {
|
|
|
|
if(objVarValue == null) {
|
|
|
|
objVarName = "none";
|
|
}
|
|
}
|
|
|
|
int x = 0;
|
|
|
|
obj_id[] spawnList = new obj_id[numToSpawn];
|
|
|
|
while (x < numToSpawn) {
|
|
|
|
obj_id npc = create.object(npcType, pickLoc(self, x));
|
|
|
|
if(!name.equals("default")) {
|
|
|
|
setName(npc, name);
|
|
}
|
|
|
|
string script = getStringObjVar(self, "script");
|
|
|
|
if(script == null || script == "") {
|
|
|
|
script = "none";
|
|
}
|
|
|
|
if(script != "none") {
|
|
|
|
attachScript (npc, script);
|
|
}
|
|
|
|
if(objVarName != "none") {
|
|
|
|
if(objVarType.equalsIgnoreCase("int")) {
|
|
|
|
int intObjVarValue = utils.stringToInt(objVarValue);
|
|
setObjVar(npc, objVarName, intObjVarValue);
|
|
|
|
} else if(objVarType.equalsIgnoreCase("float")) {
|
|
|
|
float floatObjVarValue = utils.stringToFloat(objVarValue);
|
|
setObjVar(npc, objVarName, floatObjVarValue);
|
|
|
|
} else {
|
|
|
|
setObjVar(npc, objVarName, objVarValue);
|
|
}
|
|
}
|
|
|
|
if(behavior.equalsIgnoreCase("sentinel")) {
|
|
|
|
setObjVar (npc, "SENTINEL", 1);
|
|
ai_lib.setDefaultCalmBehavior(npc, ai_lib.BEHAVIOR_SENTINEL);
|
|
|
|
} else if(behavior.equalsIgnoreCase("loiter")) {
|
|
|
|
setObjVar (npc, "LOITER", 1);
|
|
ai_lib.setDefaultCalmBehavior(npc, ai_lib.BEHAVIOR_LOITER);
|
|
|
|
} else if(behavior.equalsIgnoreCase("wander")) {
|
|
|
|
setObjVar (npc, "WANDER", 1);
|
|
ai_lib.setDefaultCalmBehavior(npc, ai_lib.BEHAVIOR_WANDER);
|
|
}
|
|
|
|
spawnList[x] = npc;
|
|
|
|
x = x + 1;
|
|
}
|
|
|
|
setObjVar(self, "spawnList", spawnList); // Suppress linting - we know the length of this array will be at least 1
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
location pickLoc (obj_id self, int x)
|
|
{
|
|
location here = getLocation(self);
|
|
setObjVar (self, "location", here);
|
|
|
|
location zero = here;
|
|
|
|
here.x = here.x - 1.5f;
|
|
here.z = here.z - 1.5f;
|
|
location one = here;
|
|
|
|
here.z = here.z + 3;
|
|
location two = here;
|
|
|
|
here.x = here.x + 3;
|
|
location three = here;
|
|
|
|
here.z = here.z - 3;
|
|
location four = here;
|
|
|
|
here = getLocation(self);
|
|
here.x = here.x + rand (-3,3);
|
|
here.z = here.z + rand (-3,3);
|
|
location other = here;
|
|
|
|
if (x == 0)
|
|
{
|
|
return zero;
|
|
}
|
|
else if (x == 1)
|
|
{
|
|
return one;
|
|
}
|
|
else if (x == 2)
|
|
{
|
|
return two;
|
|
}
|
|
else if (x == 3)
|
|
{
|
|
return three;
|
|
}
|
|
else if (x == 4)
|
|
{
|
|
return four;
|
|
}
|
|
else
|
|
{
|
|
return other;
|
|
}
|
|
} |