After following Celowin's excellent tutorials, I have a custom include file here. The functions have been very useful to me. Contains:

Flipswitch. Celowin's. Flips a lever on/off).

CreatureFlipSwitch. Makes a creature run/walk to the nearest lever tagged LEVER and switch it on or off, with a spoken taunt.

TeleportIn. Teleports in a creature (usually a wizard, of course, but you decide). Uses the Mage Armor visual effect (after a LOT of experiments) and the TeleportIn sound.

TeleportOut. Take a wild guess.

AbilityCheck. Makes an abilitycheck of any ability of a PC. Returns TRUE if the PC made the check.

Leave. Makes a creature run or walk to a waypoint tagged WP_FLEE and destroy itself.

Here you go:




//::///////////////////////////////////////////////
//:: Name lib_misc
//:: Include file
//:: Contains FlipSwitch, CreatureFlipSwitch,
//:: Leave, TeleportIn, TeleportOut, AbilityCheck
//:://////////////////////////////////////////////
//:: Created By: Windhawk
//:: Created On: 30.7.2002
//:://////////////////////////////////////////////
// Flips oLever to state 1 (on) or state 0 (off)
// Thanks to Celowin
void FlipSwitch(object oLever=OBJECT_SELF);
// Makes oLeaver flee to waypoint WP_FLEE and destroy itself
// Don't put the waypoint too far away!
void Leave(object oLeaver=OBJECT_SELF, int nRun=TRUE);
// Makes oFlipper (if INT>5) run/walk to the nearest
// lever with the tag LEVER and flip it, saying sTaunt.
// Don't let the creature run too far!
void CreatureFlipSwitch(object oFlipper=OBJECT_SELF, string sTaunt="", int nRun=TRUE);
// Teleport a creature with resref sResRef and tag sTag in
// at a waypoint with the tag sWPTag. Produces a hostile
// lvl 10 drow mage at WP_TELEPORT by default.
void TeleportIn (string sResRef = "nw_drowmage010", string sTag = "NW_DROWMAGE010", string sWPTag = "WP_TELEPORT", string sGreeting = "");
// Teleports oWizard out with a goodbye message.
void TeleportOut(object oWizard = OBJECT_SELF, string sGoodbye = "");
// Checks the ability (ABILITY_*) of oPC with DC iDC.
// Returns TRUE if oPC makes the check
int AbilityCheck(object oPC, int iAbility, int iDC = 25);
// This function flips a lever (or some other placeables) between two
// positions. The STATE variable on the lever is set to 1 the first time
// the lever is used, and 0 when used again.
//
// Written by Celowin
// Last Updated: 7/23/02
//
//
void FlipSwitch(object oLever=OBJECT_SELF)
{
// STATE will be 0 for off, 1 for on
int nUsed=GetLocalInt(oLever, "STATE");
if (nUsed == 0)
{
AssignCommand(oLever, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
SetLocalInt(oLever, "STATE", 1);
}
else
{
AssignCommand(oLever, ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE));
SetLocalInt(oLever, "STATE", 0);
}
}
void Leave(object oLeaver=OBJECT_SELF, int nRun=TRUE)
{
object oWP = GetNearestObjectByTag("WP_FLEE");
AssignCommand(oLeaver, ClearAllActions());
AssignCommand(oLeaver, ActionForceMoveToObject(oWP, nRun));
AssignCommand(oLeaver, ActionDoCommand(DestroyObject(OBJECT_SELF)));
AssignCommand(oLeaver, SetCommandable(FALSE));
}
void CreatureFlipSwitch(object oFlipper=OBJECT_SELF, string sTaunt="", int nRun=TRUE)
{
int nIntell=GetAbilityScore(oFlipper, ABILITY_INTELLIGENCE);
object oLever= GetNearestObjectByTag("LEVER", oFlipper);
if (nIntell > 5 && oLever != OBJECT_INVALID)
{
AssignCommand(oFlipper, ClearAllActions());
AssignCommand(oFlipper, ActionForceMoveToObject(oLever, nRun));
AssignCommand(oFlipper, ActionInteractObject(oLever));
if (sTaunt != "")
{
AssignCommand(oFlipper, SpeakString (sTaunt));
}
}
}
void TeleportIn (string sResRef = "nw_drowmage010",
string sTag = "NW_DROWMAGE010", string sWPTag = "WP_TELEPORT", string sGreeting = "")
{
object oWP = GetObjectByTag(sWPTag);
location lLoc=GetLocation(oWP);
string sSnd="as_mg_telepin1";
effect eTeleport=EffectVisualEffect(VFX_IMP_AC_BONUS, FALSE);
PlaySound(sSnd);
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eTeleport, lLoc);
CreateObject(OBJECT_TYPE_CREATURE, sResRef, lLoc, FALSE);
object oWizard=GetNearestObjectByTag(sTag,oWP);
if (sGreeting != "")
{
AssignCommand(oWizard, ActionSpeakString(sGreeting));
}
}
void TeleportOut(object oWizard = OBJECT_SELF, string sGoodbye = "")
{
location lLoc=GetLocation(oWizard);
string sSnd="as_mg_telepout1";
effect eTeleport=EffectVisualEffect(VFX_IMP_AC_BONUS, FALSE);
if (oWizard != OBJECT_INVALID)
{
AssignCommand(oWizard, ClearAllActions());
if (sGoodbye != "")
{
AssignCommand(oWizard, ActionSpeakString(sGoodbye));
}
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eTeleport, lLoc);
AssignCommand(oWizard, ActionDoCommand(DestroyObject(oWizard)));
AssignCommand(oWizard, SetCommandable(FALSE));
PlaySound(sSnd);
}
}
int AbilityCheck(object oPC, int iAbility, int iDC = 25)
{
int iScore = GetAbilityScore(oPC,iAbility);
if ((iScore + d20(1)) >= iDC)
{
return TRUE;
}
return FALSE;
}