Files
dsrc/sku.0/sys.server/compiled/game/script/event/honor_guard.script
T

325 lines
10 KiB
Plaintext

include library.create;
include library.utils;
include java.lang.Math;
include library.ai_lib;
include library.sui;
const string[] PROMPT_TEXT = { "Enter \"setup\" to setup data, \"singleSetup\" to setup single spawn data, \"spawn\" to spawn NPCs using current data, \"data\" to view current data or \"quit\" end.",
"Enter the template name for the NPC to spawn (e.g. stormtrooper).",
"How many NPCs per line (shoulder to shoulder)?",
"How many rows of NPCs?",
"How far apart are the NPCs going to be spaced in meters?",
"Enter an expiration time in seconds.",
"Current data shows that more then 50 NPCs are set to be spawned. If this is intended type \"ok\" to ignore this warning and continue. Otherwise type \"setup\" to make changes."
};
const string[] TITLE = {
"Standby", // 0
"Template Name", // 1
"Number per Line", // 2
"Number per Row", // 3
"Spacing", // 4
"Expiration Time", // 5
"WARNING" // 6
};
trigger OnAttach()
{
if(!isGod(self))
{
detachScript(self, "event.honor_guard");
removeObjVar(self, "event.honor_guard");
sendSystemMessage(self, "You must be in God Mode to use this script.", null);
return SCRIPT_CONTINUE;
}
string template = "stormtrooper";
int numPerLine = 5;
int numRows = 2;
float offset = 1.0f;
int setupStep = 0;
int overRide = 0;
setObjVar(self, "event.honor_guard.template", template);
setObjVar(self, "event.honor_guard.numPerLine", numPerLine);
setObjVar(self, "event.honor_guard.numRows", numRows);
setObjVar(self, "event.honor_guard.offset", offset);
setObjVar(self, "event.honor_guard.setupStep", setupStep);
setObjVar(self, "event.honor_guard.overRide", overRide);
setObjVar(self, "event.honor_guard.single", 1);
showUI(self, self);
return SCRIPT_CONTINUE;
}
trigger OnHearSpeech(obj_id objSpeaker, string strText)
{
if(objSpeaker!=self)
{
return SCRIPT_CONTINUE;
}
if(strText.equals("help"))
sendSystemMessage(self, "If you lost the UI window, say \"showUI\" to get it back.", null);
if(strText.equals("showUI"))
messageTo(self, "continueCollectingData", null, 2, false);
return SCRIPT_CONTINUE;
}
int showUI(obj_id self, obj_id player)
{
int current = getIntObjVar(self, "event.honor_guard.setupStep");
int pid = sui.inputbox(self, self, PROMPT_TEXT[current], TITLE[current], "handleUIdata", 255, false, "");
return pid;
}
messageHandler handleUIdata()
{
int bp = sui.getIntButtonPressed(params);
string text = sui.getInputBoxText(params);
if ( bp == sui.BP_CANCEL || text == null || text.equals("") )
{
sendSystemMessage(self, "Enter \"setup\" to setup data, \"spawn\" to spawn NPCs using current data, \"data\" to view current data or \"quit\" end.", null);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.honor_guard.lastData", text);
int current = getIntObjVar(self, "event.honor_guard.setupStep");
messageTo(self, "storeLastDataObjVar", null, 0, false);
return SCRIPT_CONTINUE;
}
messageHandler storeLastDataObjVar()
{
int single = getIntObjVar(self, "event.honor_guard.single");
int setupStep = getIntObjVar(self, "event.honor_guard.setupStep");
string lastDataStr = getStringObjVar(self, "event.honor_guard.lastData");
if(lastDataStr.equals("setup"))
{
setObjVar(self, "event.honor_guard.setupStep", 1);
setObjVar(self, "event.honor_guard.single", 0);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
if(lastDataStr.equals("spawn"))
{
messageTo(self, "spawnHonorGuard", null, 0, false);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
if(lastDataStr.equals("data"))
{
string template = getStringObjVar(self, "event.honor_guard.template");
int numPerLine = getIntObjVar(self, "event.honor_guard.numPerLine");
int numRows = getIntObjVar(self, "event.honor_guard.numRows");
float offset = getFloatObjVar(self, "event.honor_guard.offset");
sendSystemMessage(self, "Current Template: " + template + ". Number per line: " + numPerLine + " . Number of Rows: " + numRows + " . Spacing: " + offset, null);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
if(lastDataStr.equals("quit"))
{
removeObjVar(self, "event.honor_guard");
detachScript(self, "event.honor_guard");
sendSystemMessage(self, "Many thank you for your playing.", null);
return SCRIPT_CONTINUE;
}
if(lastDataStr.equals("singleSetup"))
{
setObjVar(self, "event.honor_guard.single", 1);
setObjVar(self, "event.honor_guard.setupStep", 1);
setObjVar(self, "event.honor_guard.numPerLine", 1);
setObjVar(self, "event.honor_guard.numRows", 1);
setObjVar(self, "event.honor_guard.offset", 1.0f);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
if(setupStep == 0) // Standby state. Must do setup, spawn, data or quit.
{
sendSystemMessage(self, "Type \"quit\" to terminate the script, \"setup\" to start over, \"data\" to see current data or \"spawn\" to spawn the NPCs.", null);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
if(setupStep == 1) // String for template to spawn.
{
setObjVar(self, "event.honor_guard.template", lastDataStr);
if(single == 0)
setObjVar(self, "event.honor_guard.setupStep", 2);
else
setObjVar(self, "event.honor_guard.setupStep", 5);
sendSystemMessage(self, "Template set as: " + lastDataStr, null);
}
if(setupStep == 2) // Int number of spawns per line.
{
int lastDataInt = utils.stringToInt(lastDataStr);
if(lastDataInt <= 0)
{
sendSystemMessage(self, "You must enter a whole number greater then 0.", null);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.honor_guard.setupStep", 3);
setObjVar(self, "event.honor_guard.numPerLine", lastDataInt);
sendSystemMessage(self, "Number of spawns per line set to: " + lastDataInt, null);
}
if(setupStep == 3) // Int number of rows.
{
int lastDataInt = utils.stringToInt(lastDataStr);
if(lastDataInt <= 0)
{
sendSystemMessage(self, "You must enter a whole number greater then 0.", null);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.honor_guard.setupStep", 4);
setObjVar(self, "event.honor_guard.numRows", lastDataInt);
sendSystemMessage(self, "Number of rows set to: " + lastDataInt, null);
}
if(setupStep == 4) // Float spacing.
{
float lastDataFloat = utils.stringToFloat(lastDataStr);
if(lastDataFloat <= 0)
{
sendSystemMessage(self, "You must enter a value greater then 0.", null);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.honor_guard.setupStep", 5);
setObjVar(self, "event.honor_guard.offset", lastDataFloat);
sendSystemMessage(self, "Spacing between NPCs set to: " + lastDataFloat, null);
}
if(setupStep == 5) // Float Expiration time
{
float lastDataFloat = utils.stringToFloat(lastDataStr);
if(lastDataFloat <= 0 || lastDataFloat > 864001)
{
sendSystemMessage(self, "You must enter a value more then 0 and at most 864000 (10 days).", null);
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.honor_guard.setupStep", 0);
setObjVar(self, "event.honor_guard.expirationTime", lastDataFloat);
sendSystemMessage(self, "Expiration time set to: " + lastDataFloat + " seconds.", null);
}
if(setupStep == 6) // Warn about a lot of spawns if applicable
{
if(lastDataStr.equals("ok"))
{
setObjVar(self, "event.honor_guard.overRide", 1);
setObjVar(self, "event.honor_guard.setupStep", 4);
}
}
int numPerLine = getIntObjVar(self, "event.honor_guard.numPerLine");
int numRows = getIntObjVar(self, "event.honor_guard.numRows");
int overRide = getIntObjVar(self, "event.honor_guard.overRide");
if(overRide == 0)
{
int totalSpawns = numPerLine * numRows;
if(totalSpawns > 50)
setObjVar(self, "event.honor_guard.setupStep", 6);
}
removeObjVar(self, "event.honor_guard.lastData");
messageTo(self, "continueCollectingData", null, 1, false);
return SCRIPT_CONTINUE;
}
messageHandler continueCollectingData()
{
showUI(self, self);
return SCRIPT_CONTINUE;
}
messageHandler spawnHonorGuard()
{
string template = getStringObjVar(self, "event.honor_guard.template");
int numPerLine = getIntObjVar(self, "event.honor_guard.numPerLine");
int numRows = getIntObjVar(self, "event.honor_guard.numRows");
float offset = getFloatObjVar(self, "event.honor_guard.offset");
float expirationTime = getFloatObjVar(self, "event.honor_guard.expirationTime");
float timeStamp = getGameTime();
location here = getLocation(self);
float heading = getYaw(self);
float xLoc = here.x;
float yLoc = here.y;
float zLoc = here.z;
obj_id room = here.cell;
for(int i = 0; i < numPerLine; i++)
{
double xRowOffsetDbl = Math.sin(Math.toRadians(heading + 90)) * (i * offset);
float xRowOffset = (float)xRowOffsetDbl;
double zRowOffsetDbl = Math.cos(Math.toRadians(heading + 90)) * (i * offset);
float zRowOffset = (float)zRowOffsetDbl;
for(int j = 0; j < numRows; j++)
{
double xSpawnDbl = Math.sin(Math.toRadians(heading)) * (j * offset) + xLoc + xRowOffset;
double zSpawnDbl = Math.cos(Math.toRadians(heading)) * (j * offset) + zLoc + zRowOffset;
float xSpawn = (float)xSpawnDbl;
float zSpawn = (float)zSpawnDbl;
location spawnPoint = new location();
spawnPoint.x = xSpawn;
spawnPoint.y = yLoc;
spawnPoint.z = zSpawn;
spawnPoint.cell = room;
obj_id honorGuard = create.object(template, spawnPoint);
persistObject(honorGuard);
attachScript(honorGuard, "event.invasion.key_object");
setObjVar(honorGuard, "event.invasion.keyObject.expirationTime", expirationTime);
setObjVar(honorGuard, "event.invasion.keyObject.timeStamp", timeStamp);
setYaw(honorGuard, heading);
ai_lib.setDefaultCalmBehavior(honorGuard, ai_lib.BEHAVIOR_SENTINEL );
ai_lib.stop(honorGuard);
setInvulnerable(honorGuard, true);
}
}
return SCRIPT_CONTINUE;
}