OnEnter
// ConditionalTrigger_OnEnd (or whatever)
#include "ConditionalTrigger_Include" // (or whatever)
main()
{
// Find the PC who entered or exited - only trigger for PCs
object oPC = GetEnteringObject();
// Error checking code
if !GetIsPC(oPC) || GetIsDM(oPC)
return;
if GetLocalString(OBJECT_SELF,"sTriggerFiringEvent") != "OnEnter"
return;
ActionConditonalTriggering(oPC);
}
OnExit
// ConditionalTrigger_OnEnd (or whatever)
#include "ConditionalTrigger_Include" // (or whatever)
main()
{
// Find the PC who entered or exited - only trigger for PCs
object oPC = GetExitingObject();
// Error checking code
if !GetIsPC(oPC) || GetIsDM(oPC)
return;
if GetLocalString(OBJECT_SELF,"sTriggerFiringEvent") != "OnExit"
return;
ActionConditionalTriggering(oPC);
}
Include file
// "ConditionalTrigger_Include" (or whatever)
#include "NW_I0_PLOT"
// This function likely also allready exists in some include file in some COA system somewhere
int GetClassNumberByName(string sClass)
{
if sClass == "Barbarian" return CLASS_TYPE_BARBARIAN;
if sClass == "Cleric" return CLASS_TYPE_CLERIC;
if sClass == "Druid" return CLASS_TYPE_DRUID;
if sClass == "Fighter" return CLASS_TYPE_FIGHTER;
if sClass == "Monk" return CLASS_TYPE_MONK;
if sClass == "Paladin" return CLASS_TYPE_PALADIN;
if sClass == "Ranger" return CLASS_TYPE_RANGER;
if sClass == "Rogue" return CLASS_TYPE_ROGUE;
if sClass == "Sorcerer" return CLASS_TYPE_SORCERER;
if sClass == "Wizard" return CLASS_TYPE_WIZARD;
if sClass == "Arcane Archer" return CLASS_TYPE_ARCANE_ARCHER;
if sClass == "Assassin" return CLASS_TYPE_ASSASSIN;
if sClass == "Devine Champion" return CLASS_TYPE_DEVINE_CHAMPION;
if sClass == "Red Dragon Disciple" return CLASS_TYPE_DRAGON_DISCIPLE;
if sClass == "RDD" return CLASS_TYPE_DRAGON_DISCIPLE;
if sClass == "Harper Scout" return CLASS_TYPE_HARPER;
if sClass == "Harper" return CLASS_TYPE_HARPER;
if sClass == "Pale Master" return CLASS_TYPE_PALE_MASTER;
if sClass == "Shadow Dancer" return CLASS_TYPE_SHADOWDANCER;
if sClass == "Shifter" return CLASS_TYPE_SHIFTER;
if sClass == "Weapon Master" return CLASS_TYPE_WEAPON_MASTER;
return -1; // Invalid Class Name
}
int isTriggeringConditionMet(object oPC,string sConditionType,string sConditionValue)
{
// Various setup things
string sType;
string sValue;
string sValue2;
int iDelimiterLocation;
if (sConditionType == "") return FALSE; // No Condition then it can't be met
while sConditionType != ""
{
// extract entries from the strings using delimiters "," and ":"
iDelimiterLocation = FindSubString(sConditionType,",");
if iDelimiterLocation == -1
sType = sConditionType;
else {
sType = GetStringLeft(sConditionType,iDelimiterLocation);
sConditionType = GetStringRight(sConditionType,GetStringLength(sConditionType)-iDelimiterLocation-1); }
iDelimiterLocation = FindSubString(sConditionValue,",");
if iDelimiterLocation == -1
sValue = sConditionValue;
else {
sValue = GetStringLeft(sConditionValue,iDelimiterLocation);
sConditionValue = GetStringRight(sConditionValue,GetStringLength(sConditionValue)-iDelimiterLocation-1); }
iDelimiterLocation = FindSubString(sValue,":");
if iDelimiterLocation == -1
sValue2="";
else {
sValue = GetStringLeft(sValue,iDelimiterLocation);
sValue2 = GetStringRight(sValue,GetStringLength(sValue)-iDelimiterLocation-1);
}
///////////////////////////////////////////////////////////////
////////// HERE IS WHERE THE CONDITIONS ARE CHECKED //////////
///////////////////////////////////////////////////////////////
if sType == "HasItem"
{
if !HasItem(oPC,sValue) return FALSE;
}
else if sType == "UnderLevel"
{
if !(GetHitDice(oPC) < StringToInt(sValue)) return FALSE;
}
else if sType == "OverLevel"
{
if !(GetHitDice(oPC) > StringToInt(sValue)) return FALSE;
}
else if sType == "HasClass"
{
if !(GetLevelByClass(oPC,GetClassNumberByName(sValue)) > 0) return FALSE;
}
else if sType == "UnderClassLevel"
{
if !(GetLevelByClass(oPC,GetClassNumberByName(sValue)) < StringToInt(sValue2)) return FALSE;
}
else if sType == "OverClassLevel"
{
if !(GetLevelByClass(oPC,GetClassNumberByName(sValue)) > StringToInt(sValue2)) return FALSE;
}
// ect. ect. ect. more else ifs need to be added for more conditionals //
// Be sure to check if the condition is NOT met, and to return FALSE if NOT met //
else return FALSE; // Unsupported conditions can not be met.
///////////////////////////////////////////////////////////////
////////// END WHERE CONDITIONS ARE CHECKED //////////
///////////////////////////////////////////////////////////////
}
return TRUE;
}
void ActionConditionalTriggering(object oPC)
{
// Randomness - do first for efficiency
int iRandomness = GetLocalInt(OBJECT_SELF,"iRandomnessOfTriggering");
if (iRandomness != 0) && (iRandomness >= d100()) return;
// Find the object to execute the script - exit if unable to find
string sTagOfObjectToExecute = GetLocalString(OBJECT_SELF,"sTagOfObjectToExecute");
object oExecutingObject = (sTagOfObjectToExecute == "") ? OBJECT_SELF :
(sTagOfObjectToExecute == "SELF") ? OBJECT_SELF :
(sTagOfObjectToExecute == "PC") ? oPC :
GetObjectByTag(sTagOfObjectToExecute);
if oExecutingObject == OBJECT_INVALID return; // unable to find object, exit without comment
// Find if condition is met
if !isTriggeringConditionMet(oPC,
GetLocalString(OBJECT_SELF,"sTriggeringConditionType"),
GetLocalString(OBJECT_SELF,"sTriggeringConditionValue"))
return; // exit without comment if condition is not met
// Execute Script - invalid script name will perform no action.
SetLocalObject(oExecutingObject,"oCT_PC",oPC); // not sure how to pass this info to the script
SetLocalObject(oExecutingObject,"oCT_Trigger",OBJECT_SELF); // but probably have to do it somehow
ExecuteScript(GetLocalString(OBJECT_SELF,"sResultScript"),oExecutingObject);
return;
}
Implimented Conditions
HasItem - sItemTag = checks if triggering PC has sItemTag in it's inventory
UnderLevel - iLevel = checks if triggering PC has fewer hit dice than iLevel
OverLevel - iLevel = checks if triggering PC has more hit dice than iLevel
HasClass - sClassName = checks if triggering PC has at least 1 level in sClassName
UnderClassLevel - sClassName:iLevel - checks if Triggering PC has fewer than iLevel levels in sClassName
OverClassLevel - sClassName:iLevel - checks if Triggering PC has more then iLevel levels in sClassName
Someone else will have to write the code for the other conditions, but it should be realitively easy