GhostOfGod wrote...
You can't really do this with one script since many of the things you want are triggered with different door events. OnUnLock, OnOpened. You could probably get away with 2 "all encompassing" scripts unless you want things to also happen in the OnFailToOpen, OnLock, etc..
You'd probably also need a specific list of what you want since "all encompassing" to one person does not mean the same thing to another.
Actually, you CAN mix n' match events with scripts. You have to be careful, though, as you can get some very hard-to-debug results and erratic behavior, if you don't get it right. Here, by way of example, is our script for handing out task objective objects, called by a number of different objects and events:
#include "hg_inc"
#include "tsk_inc"
void main()
{
CheckGivePCsTaskObjective();
}
And the included function:
void CheckGivePCsTaskObjective() {
object oPC, oArea, oItem;
int nTaskGiver, nTask, nType = GetObjectType(OBJECT_SELF);
string sTask, sObjTag, sConRes = "";
struct IntList list;
location lLoc;
if (nType == OBJECT_TYPE_PLACEABLE) {
if (!GetIsPC(oPC = GetLastUsedBy()))
return;
sTask = GetLocalString(OBJECT_SELF, "tsk_objective");
} else if (GetIsPC(OBJECT_SELF)) {//SIMTools search command
oPC = OBJECT_SELF;
lLoc = GetLocalLocation(oPC, "tsk_click");
DeleteLocalLocation(oPC, "tsk_click");
if (!GetIsObjectValid(GetAreaFromLocation(lLoc)))
return;
object oWay = GetNearestObjectOfTagToLocation("tsk_search", lLoc);
if (GetDistanceBetweenLocations(lLoc, GetLocation(oPC)) > 4.0) {
FloatingTextStringOnCreature("You must be closer to the spot you are attempting to search.", oPC, FALSE);
return;
}
float fDis = GetLocalFloat(oWay, "tsk_dist");
if (!GetIsObjectValid(oWay) || (GetDistanceBetweenLocations(GetLocation(oWay), lLoc) > fDis)) {
FloatingTextStringOnCreature("You search, but find nothing.", oPC, FALSE);
return;
}
sTask = GetLocalString(oWay, "tsk_objective");
} else if (nType == OBJECT_TYPE_CREATURE) {
oPC = GetIsPC(GetLastKiller()) ? GetLastKiller() : GetMaster(GetLastKiller());
if (!GetIsPC(oPC))
return;
sTask = GetLocalString(OBJECT_SELF, "tsk_objective");
} else if (GetIsObjectValid(oItem = GetItemActivated())) {//quest container item
oPC = GetItemActivator();
lLoc = GetItemActivatedTargetLocation();
if (!GetIsObjectValid(GetAreaFromLocation(lLoc)))
return;
if (GetDistanceBetweenLocations(lLoc, GetLocation(oPC)) > 4.0) {
FloatingTextStringOnCreature("You must be closer to the spot you are attempting to use the container on.", oPC, FALSE);
return;
}
string sNoFind = GetLocalString(oItem, "tsk_nofind");
if (sNoFind == "")
sNoFind = "You don't find anything to put in the container.";
string sFind = GetLocalString(oItem, "tsk_find");
if (sNoFind == "")
sNoFind = "You fill the container.";
object oWay = GetNearestObjectOfTagToLocation("tsk_container", lLoc);
sTask = GetLocalString(oWay, "tsk_objective");
list = GetIntList(sTask);
sConRes = GetTaskObjectiveItemResRef(list.i0, list.i1)+"_c";
float fDis = GetLocalFloat(oWay, "tsk_dist");
if (!GetIsObjectValid(oWay) || GetResRef(oItem) != sConRes || (GetDistanceBetweenLocations(GetLocation(oWay), lLoc) > fDis)) {
FloatingTextStringOnCreature(sNoFind, oPC, FALSE);
return;
}
FloatingTextStringOnCreature(sFind, oPC, FALSE);
}
if (sTask == "")
return;
list = GetIntList(sTask);
nTaskGiver = list.i0;
nTask = list.i1;
oArea = GetArea(oPC);
if (GetLocalInt(oArea, "DespawnTime")) {
FloatingTextStringOnCreature("You cannot find task objectives in a despawned area.", oPC, FALSE);
return;
}
sObjTag = GetTaskObjectiveItemResRef(nTaskGiver, nTask);
int nPCHD = GetHitDiceIncludingLLs(oPC);
object oCon, oMember = GetFirstFactionMember(oPC);
while (GetIsObjectValid(oMember)) {
if (!GetPCHasTaskActive(oMember, nTaskGiver) ||
(GetTaskCompleted(oMember, nTaskGiver) != (nTask-1)) ||
(abs(GetHitDiceIncludingLLs(oMember)-nPCHD) > 6)) {//no more than 6 level spread
oMember = GetNextFactionMember(oPC);
} else {
if (!GetLocalInt(oMember, sObjTag)) {
SetLocalInt(oMember, sObjTag, 1);//mark it fresh - doubles as a DoOnce
if (!GetIsObjectValid(GetItemPossessedByResRef(oMember, sObjTag))) {
oItem = CreateItemOnObject(sObjTag, oMember);
SetPickpocketableFlag(oItem, FALSE);
} else
FloatingTextStringOnCreature("You already acquired this.", oMember, FALSE);
if (sConRes != "" && GetIsObjectValid(oCon = GetItemPossessedByResRef(oMember, sConRes)))
DestroyObject(oCon);
} else
FloatingTextStringOnCreature("You already acquired this.", oMember, FALSE);
oMember = GetNextFactionMember(oPC);
}
}
}
Again, I'm not necessarily advocating that you do this, just noting that it is possible, and sometimes convenient. It can also generate serious debugging headaches. When you call event-related functions in different events, it can yeild very unpredictable results. Even after writing the above in a way that seemed logically safe to me, I had to shuffle the if/else order around, and alter the way I did some things, in order to stop some quixotic bugs.
Funky