HoS_PRC8/_mod/_module/nss/uni_onactivateit.nss
Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

81 lines
3.6 KiB
Plaintext

//////////////////////////////////////////////////////////
// Universal Item Activation Script
// By Deva Bryson Winblood.
// Version 1.1
// 10/12/2003
//////////////////////////////////////////////////////////
/* What can you do with this script?
This script will use the ResRef of an item to call a
script with the same name as it's res ref. It can also
be used to GROUP multiple items into a single activation
script based on a prefix. There are some hardcoded
prefixes used with Deva's scripts but, if you set
a local string OnAct_Pre on the Module object to the
prefix you want it to look for and then set OnAct_PreScript
on the local module object to the name of the script to
run it will support your own grouped objects as well.
Using this method can reduce the amount of scripts you
might need if you are making a lot of items.
If you have other activation scripts you wish to run do not worry
you can have it run your old script by creating a waypoint
in the module somewhere called UNI_ACTIVATE and in the name field
simply place the name of the script you wish it to run.
NOTE: It would be better if you renamed the scripts to match the resref
of the item activated though. Then you would never have to mess with
activation scripts again.
PREFIX SPECIAL: You can also set the prefix setting without touching
any script. Create a waypoint tagged UNI_ACTIVATEPRE and set the name of the
waypoint to the prefix you want it to use. Create a second waypoint with the
tag UNI_ACTIVATEPRES and set the name of the waypoint to the name of the
script to run for items with this prefix.
*/
void main()
{
object oItem=GetItemActivated();
object oMod=GetModule();
string sPre=GetLocalString(oMod,"OnAct_Pre");
string sPreScript=GetLocalString(oMod,"OnAct_PreScript");
int nN=GetStringLength(sPre);
//SendMessageToPC(GetItemActivator(),"uni_onactivateit:'"+GetResRef(oItem)+"'.");
if (nN<1)
{ // check for prefix waypoint
oMod=GetWaypointByTag("UNI_ACTIVATEPRE");
if (oMod!=OBJECT_INVALID) sPre=GetName(oMod);
oMod=GetWaypointByTag("UNI_ACTIVATEPRES");
if (oMod!=OBJECT_INVALID) sPreScript=GetName(oMod);
nN=GetStringLength(sPre);
//SendMessageToPC(GetItemActivator()," prefix waypoint check: nN="+IntToString(nN)+".");
} // check for prefix waypoint
if (GetStringLeft(GetTag(oItem),4)=="DH2_") ExecuteScript("desertheat2",OBJECT_SELF);
else
{ // not a special
//SendMessageToPC(GetItemActivator()," not special.");
if (nN>0&&sPre!="")
{ // check for special prefix
if (GetStringLeft(GetTag(oItem),nN)==sPre) ExecuteScript(sPreScript,OBJECT_SELF);
else {nN=-1;}
//SendMessageToPC(GetItemActivator()," Check for special prefix:"+IntToString(nN)+".");
} // check for special prefix
if (nN<1)
{ // special prefix was not used
sPre=GetResRef(oItem);
//SendMessageToPC(GetItemActivator()," Special prefix not used.");
if (GetStringLength(sPre)>0)
{ // has res ref
//SendMessageToPC(GetItemActivator()," resref:'"+sPre+"'.");
ExecuteScript(sPre,OBJECT_SELF);
} // has res ref
else
{ // use tag
sPre=GetTag(oItem);
if (GetStringLength(sPre)>16) sPre=GetStringLeft(sPre,16);
//SendMessageToPC(GetItemActivator()," tag:'"+sPre+"'.");
ExecuteScript(sPre,OBJECT_SELF);
} // use tag
oMod=GetWaypointByTag("UNI_ACTIVATE");
if (oMod!=OBJECT_INVALID) ExecuteScript(GetName(oMod),OBJECT_SELF);
} // special prefix was not used
} // not a special
}