mirror of
https://bitbucket.org/seefoe/dsrc.git
synced 2026-07-31 01:15:55 -04:00
311 lines
8.2 KiB
Plaintext
311 lines
8.2 KiB
Plaintext
|
|
include library.utils;
|
|
include library.space_utils;
|
|
|
|
|
|
void activateSpawnerHack(obj_id objPlayer)
|
|
{
|
|
// hack to turn on the new spawn system
|
|
obj_id[] objSpawners = getAllObjectsWithObjVar(getLocation(objPlayer), 24000, "intSpawnSystem");
|
|
if(objSpawners.length==0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
messageTo(objSpawners[rand(0, objSpawners.length-1)], "doSpawnEvent", null, 0, false);
|
|
return;
|
|
}
|
|
|
|
|
|
location getRandomLocationInCircle(location locTest, float fltSize)
|
|
{
|
|
locTest.x = locTest.x + rand(-1*fltSize, fltSize);
|
|
locTest.z= locTest.z + rand(-1*fltSize, fltSize);
|
|
return locTest;
|
|
}
|
|
|
|
location getRandomLocationAtDistance(location locTest, float fltSize)
|
|
{
|
|
// will "fixed" coordinate be positive or negative
|
|
int position = 1;
|
|
if ( rand(0,1) == 0 )
|
|
{
|
|
position = -1;
|
|
}
|
|
|
|
// which coordinate will be "fixed"
|
|
if ( rand(0,1) == 1 )
|
|
{
|
|
// random x
|
|
locTest.x = locTest.x + rand(-1*fltSize, fltSize);
|
|
locTest.z= locTest.z + fltSize*position;
|
|
}
|
|
else
|
|
{
|
|
// random z
|
|
locTest.x = locTest.x + fltSize*position;
|
|
locTest.z= locTest.z + rand(-1*fltSize, fltSize);
|
|
}
|
|
|
|
return locTest;
|
|
}
|
|
|
|
boolean checkSpawnCount(obj_id self)
|
|
{
|
|
int intSpawnCount = getIntObjVar(self, "intSpawnCount");
|
|
int intCurrentSpawnCount = utils.getIntScriptVar(self, "intCurrentSpawnCount");
|
|
if(intCurrentSpawnCount>=intSpawnCount)
|
|
{
|
|
//LOG("spawning", "No Spawns due to hitting limit locally");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void incrementSpawnCount(obj_id self)
|
|
{
|
|
int intCurrentSpawnCount = utils.getIntScriptVar(self, "intCurrentSpawnCount");
|
|
int intSpawnCount = getIntObjVar(self, "intSpawnCount");
|
|
intCurrentSpawnCount = intCurrentSpawnCount +1;
|
|
if(intCurrentSpawnCount <= intSpawnCount)
|
|
{
|
|
|
|
utils.setScriptVar(self, "intCurrentSpawnCount", intCurrentSpawnCount);
|
|
}
|
|
return;
|
|
|
|
}
|
|
|
|
void addToSpawnDebugList(obj_id self, obj_id spawned)
|
|
{
|
|
resizeable obj_id[] debugSpawnList = new obj_id[0];
|
|
if (utils.hasScriptVar(self, "debugSpawnList"))
|
|
{
|
|
debugSpawnList = utils.getResizeableObjIdArrayScriptVar(self, "debugSpawnList");
|
|
}
|
|
|
|
debugSpawnList = utils.addElement(debugSpawnList, spawned);
|
|
|
|
utils.setScriptVar(self, "debugSpawnList", debugSpawnList);
|
|
}
|
|
|
|
resizeable obj_id[] getAllObjectsWithObjVar(location locTest, string strObjVarName)
|
|
{
|
|
//obj_id[] objMasterList = getAllObjectsInRange(locTest, 320000);
|
|
resizeable obj_id[] objArray = new obj_id[0];
|
|
//for(int intI = 0; intI < objMasterList.length; intI++)
|
|
//{
|
|
// getObjectsWithObjVar(objMasterList[intI], strObjVarName, objArray);
|
|
//}
|
|
return objArray;
|
|
}
|
|
resizeable obj_id[] getObjectsWithObjVar(obj_id objParent, string strObjVarName, resizeable obj_id[] objArray)
|
|
{
|
|
if(hasObjVar(objParent, strObjVarName))
|
|
{
|
|
objArray = utils.addElement(objArray, objParent);
|
|
}
|
|
obj_id[] objContents = getContents(objParent);
|
|
if((objContents!=null)&&(objContents.length>0))
|
|
{
|
|
for(int intI = 0; intI < objContents.length; intI++)
|
|
{
|
|
getObjectsWithObjVar(objContents[intI], strObjVarName, objArray);
|
|
}
|
|
}
|
|
return objArray;
|
|
}
|
|
|
|
|
|
obj_id[] getAllContents(obj_id objObject)
|
|
{
|
|
resizeable obj_id[] objContents = new obj_id[0];
|
|
obj_id[] objCells = getContents(objObject);
|
|
|
|
for(int intI = 0; intI< objCells.length; intI++)
|
|
{
|
|
obj_id[] objTestContents = getContents(objCells[intI]);
|
|
if((objTestContents!=null)&&(objTestContents.length>0))
|
|
{
|
|
for(int intJ = 0; intJ < objTestContents.length; intJ++)
|
|
{
|
|
objContents = utils.addElement(objContents, objTestContents[intJ]);
|
|
}
|
|
}
|
|
}
|
|
return objContents;
|
|
}
|
|
|
|
void planetSpawnersCreatureDied(obj_id spawner, obj_id deadGuy)
|
|
{
|
|
//LOG("sissynoid", "MOB SPAWNER: " + spawner + " is spawning mobs.");
|
|
if(!isIdValid(spawner))
|
|
{
|
|
//LOG("sissynoid", "Spawner ID is not valid");
|
|
CustomerServiceLog("SPAWNER_OVERLOAD", "Spawner " + spawner + " is invalid");
|
|
return;
|
|
}
|
|
|
|
int count = utils.getIntScriptVar(spawner, "count");
|
|
//LOG("sissynoid", "Library - Retrieving Count("+ count +")");
|
|
count = count - 1;
|
|
//LOG("sissynoid", "Library - Decrementing Count("+ count +")");
|
|
if(count < 0)
|
|
{
|
|
//LOG("sissynoid", "Count Less Than Zero");
|
|
CustomerServiceLog("SPAWNER_OVERLOAD", "Count went below 0 on " + spawner + " on Rori. Rori_npc_medium script.");
|
|
count = 0;
|
|
}
|
|
//LOG("sissynoid", "Library - Setting Count("+ count +")");
|
|
utils.setScriptVar(spawner, "count", count);
|
|
|
|
resizeable obj_id[] spawnedList = utils.getResizeableObjIdArrayScriptVar (spawner, "myCreations");
|
|
|
|
for(int i = 0; i < spawnedList.length; i++)
|
|
{
|
|
//This NPC has died
|
|
if(spawnedList[i] == deadGuy)
|
|
{
|
|
//LOG("sissynoid", "Dead Guy ("+ deadGuy +")Found - Continuing Through Loop - Removing");
|
|
spawnedList.remove(spawnedList[i]);
|
|
continue;
|
|
}
|
|
//Bug causing spawners to stop spawning
|
|
if(spawnedList[i] == null)
|
|
{
|
|
//LOG("sissynoid", "SpawnedList Loop - Null ID (" + spawnedList[i] + ") - Removing");
|
|
spawnedList.remove(spawnedList[i]);
|
|
continue;
|
|
}
|
|
}
|
|
//Set the ScriptVar back on the spawner
|
|
utils.setScriptVar(spawner, "myCreations", spawnedList);
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
createSpawnInLegacyCell
|
|
You can spawn NPCs/Creatures from the creatures table in the old legacy dungeons by passing in the following:
|
|
Dungeon - The OID of the cave, bunker, etc.
|
|
cretureLocation - This is the coordinates, planet and cell OID of the dungeon
|
|
cellName - This is the cell name used to call back to the dungeon when the creature is killed.
|
|
creatureName - This is the creature name as defined in the creatures table.
|
|
*/
|
|
obj_id createSpawnInLegacyCell(obj_id dungeon, location creatureLocation, string creatureName)
|
|
{
|
|
if(!isValidId(dungeon))
|
|
{
|
|
CustomerServiceLog("bad_spawner_data", "createSpawnInLegacyCell - Dungeon passed to function was invalid.");
|
|
return null;
|
|
}
|
|
|
|
if(creatureLocation == null)
|
|
{
|
|
CustomerServiceLog("bad_spawner_data", "createSpawnInLegacyCell - Location passed to function was invalid for dungeon: "+dungeon);
|
|
return null;
|
|
}
|
|
|
|
if(creatureName == null || creatureName.length() <= 0)
|
|
{
|
|
CustomerServiceLog("bad_spawner_data", "createSpawnInLegacyCell - Creature Name passed to function was invalid for dungeon: "+dungeon);
|
|
return null;
|
|
}
|
|
|
|
obj_id creature = create.object(creatureName, creatureLocation);
|
|
if(!isValidId(creature))
|
|
{
|
|
CustomerServiceLog("bad_spawner_data", "createSpawnInLegacyCell - Creature could not be created for dungeon: "+dungeon);
|
|
return null;
|
|
}
|
|
|
|
setObjVar(creature, "dungeon", dungeon);
|
|
create.addDestroyMessage(creature, creatureName+"Dead", 300f, dungeon);
|
|
return creature;
|
|
}
|
|
|
|
|
|
//Spawn objects inside an old dungeon using datatable
|
|
boolean spawnObjectsInDungeonFromTable(obj_id dungeon, string planet, string table)
|
|
{
|
|
if(!isValidId(dungeon))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(table == null || table.length() <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(planet == null || planet.length() <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
int numberOfObjectsToSpawn = dataTableGetNumRows(table);
|
|
if(numberOfObjectsToSpawn <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
for(int i = 0; i < numberOfObjectsToSpawn; i++)
|
|
{
|
|
dictionary objToSpawn = dataTableGetRow(table, i);
|
|
if(objToSpawn == null)
|
|
continue;
|
|
|
|
string object = objToSpawn.getString("object");
|
|
if(object == null || object.length() <= 0)
|
|
continue;
|
|
|
|
float xCoord = objToSpawn.getFloat("loc_x");
|
|
float yCoord = objToSpawn.getFloat("loc_y");
|
|
float zCoord = objToSpawn.getFloat("loc_z");
|
|
float yaw = objToSpawn.getFloat("yaw");
|
|
|
|
string spawnRoom = objToSpawn.getString("room");
|
|
if(spawnRoom == null || spawnRoom.length() <= 0)
|
|
continue;
|
|
|
|
obj_id room = getCellId(dungeon, spawnRoom);
|
|
if(!isValidId(room))
|
|
continue;
|
|
|
|
location objectLocation = new location (xCoord, yCoord, zCoord, planet, room);
|
|
|
|
obj_id objectCreated = createObject(object, objectLocation);
|
|
if(!isValidId(objectCreated))
|
|
continue;
|
|
|
|
setYaw(objectCreated, yaw);
|
|
|
|
string script = objToSpawn.getString("script");
|
|
if(script != null && script.length() > 0)
|
|
{
|
|
//SPLIT for multiple
|
|
string[] scripts = split(script, ',');
|
|
for(int j = 0; j < scripts.length; j++)
|
|
{
|
|
if (!hasScript(objectCreated, scripts[j]))
|
|
{
|
|
attachScript(objectCreated, scripts[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
string objVars = objToSpawn.getString("objvar");
|
|
if(objVars != null && objVars.length() > 0)
|
|
{
|
|
utils.setObjVarsListUsingSemiColon(objectCreated, objVars);
|
|
}
|
|
|
|
string objName = objToSpawn.getString("name");
|
|
if(objName != null && objName.length() > 0)
|
|
{
|
|
setName(objectCreated, objName);
|
|
}
|
|
}
|
|
return true;
|
|
} |