182 lines
8.2 KiB
Plaintext
182 lines
8.2 KiB
Plaintext
//::///////////////////////////////////////////////
|
|
//:: OnItemActivate
|
|
//:: em_onitmactvt.nss
|
|
//:: Copyright (c) 2003 James Robinson. (aka Ryuujin)
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
Triggered when a player activates
|
|
a special power item . Determines course
|
|
of action
|
|
|
|
Assign this script to the onItemActivate
|
|
slot under "Edit -> Module Properties". If
|
|
You already have a script there, copy/paste
|
|
The below scripts, changing variable names
|
|
appropriatly.
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: James Robinson
|
|
//:: Created On: June 18 2003
|
|
//:://////////////////////////////////////////////
|
|
|
|
void main()
|
|
{
|
|
object oPlayer = GetItemActivator();
|
|
object oItem = GetItemActivated();
|
|
string sItem = GetTag(oItem);
|
|
|
|
// BINDSTONE
|
|
// This script handles several functions:
|
|
////////////////////////////////////////////////////////////////
|
|
// - Checks if the target is a valid one
|
|
// - Captures and adds a new creature on failing will save
|
|
// - Triggers unsummoning if player clicks his own summon
|
|
// - Applies all related visuals except unsummoning
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
if (sItem == "em_bindstone"){
|
|
// Phew thats a lot of declarations
|
|
object oTarget = GetItemActivatedTarget();
|
|
location lTarget = GetItemActivatedTargetLocation();
|
|
string sResRef = GetLocalString(oItem, "lsResRef");
|
|
string sTrgtRef = GetResRef(oTarget);
|
|
int iIsPC = GetIsPC(oTarget);
|
|
int iIsDM = GetIsDM(oTarget);
|
|
int iEmpathyBonus = GetSkillRank(SKILL_ANIMAL_EMPATHY, oPlayer);
|
|
int iIsPlot = GetIsImmune(oTarget, IMMUNITY_TYPE_TRAP);
|
|
int iObjectType = GetObjectType(oTarget);
|
|
string sMessage = "ERROR: Script returned false on all sub scripts";
|
|
object oSummon = GetHenchman(oPlayer);
|
|
|
|
// if the player has clicked something besides his summon see if we can catch it
|
|
if (oTarget != oSummon || GetIsObjectValid(oTarget) == FALSE){
|
|
if (sResRef == ""){
|
|
|
|
// Error Messages
|
|
if (sTrgtRef == ""){
|
|
sMessage = "You missed your target!";
|
|
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_COM_SPARKS_PARRY), lTarget, 3.0);
|
|
}
|
|
if ( iIsPC == TRUE || iIsDM == TRUE){ sMessage = "You may not capture Player Controlled creatures"; }
|
|
if ( iIsPlot == TRUE){ sMessage = "Sorry, this creature is part of the plot, I know it's not RP but you're not allowed to capture this guy"; }
|
|
if ( iObjectType != OBJECT_TYPE_CREATURE){ sMessage = "You may only target creatures with a Bindstone"; }
|
|
|
|
// We have a winner...
|
|
if (sTrgtRef != "" && iIsDM == FALSE && iIsPC == FALSE && iIsPlot != TRUE && iObjectType == OBJECT_TYPE_CREATURE){
|
|
int iMaxLife = GetMaxHitPoints(oTarget);
|
|
int iCrntLife = GetCurrentHitPoints(oTarget);
|
|
int iPercentLeft = FloatToInt(IntToFloat(iCrntLife) * (100 / IntToFloat(iMaxLife)));
|
|
int iInverse = FloatToInt((100 - IntToFloat(iPercentLeft)) / 4);
|
|
int iSaveThrow = WillSave(oTarget, iInverse + iEmpathyBonus);
|
|
|
|
// You got it!
|
|
if (iSaveThrow == FALSE){
|
|
int iLifeLeft = iMaxLife - iCrntLife;
|
|
|
|
sMessage = "You captured a creature!";
|
|
|
|
DestroyObject(oTarget, 0.1);
|
|
SetLocalString(oItem, "lsResRef", sTrgtRef);
|
|
SetLocalInt(oItem, "liDamage", iLifeLeft);
|
|
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_PWSTUN), lTarget, 3.0);
|
|
}
|
|
|
|
// No you didn't....
|
|
if (iSaveThrow == TRUE){
|
|
sMessage = "The creature resisted your attempts of capturing it";
|
|
|
|
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_WILL_SAVING_THROW_USE), oTarget);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Summon a new creature only if the bindstone has a creature bound
|
|
if (sResRef != ""){
|
|
object oCreature = CreateObject(OBJECT_TYPE_CREATURE, sResRef, lTarget);
|
|
int iDmgToApply = GetLocalInt(oItem, "liDamage");
|
|
|
|
// Better unsummon the existing creature pronto
|
|
if (GetIsObjectValid(oSummon) == TRUE){
|
|
ExecuteScript("em_unsummon", oSummon);
|
|
}
|
|
|
|
sMessage = "Summoning creature...";
|
|
|
|
ChangeToStandardFaction(oCreature, STANDARD_FACTION_DEFENDER); // Ensure it's on a friendly faction
|
|
DelayCommand(1.0, AddHenchman(oPlayer, oCreature)); // Log it as a henchman
|
|
SetLocalObject(oCreature, "loMyStone", oItem);
|
|
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(iDmgToApply), oCreature); // Apply any damage it had when last unsummoned
|
|
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1), lTarget, 3.0);
|
|
ExecuteScript("em_follow", oPlayer);
|
|
}
|
|
}
|
|
|
|
// If player clicks his summon, unsummon it
|
|
if (oTarget == oSummon){
|
|
sMessage = "";
|
|
ExecuteScript("em_unsummon", oSummon);
|
|
}
|
|
|
|
// Display whatever message was stored for the player
|
|
SendMessageToPC(oPlayer, sMessage);
|
|
}
|
|
|
|
|
|
|
|
// BINDSTONE CHARGER
|
|
// Triggers the heal stones script when item is sued
|
|
////////////////////////////////////////////////////////////////
|
|
if (sItem == "em_charger"){
|
|
ExecuteScript("em_healstones", oPlayer);
|
|
}
|
|
|
|
|
|
// BINDING CRYSTAL SCRIPT
|
|
// This script has 2 functions:
|
|
////////////////////////////////////////////////////////////////
|
|
// - Standard Crystals assign monster based on their tag to bindstone
|
|
// - Special Crystals assign monster based on local string "lsResRef"
|
|
// - Crystal will only destroy self if binding is successful
|
|
// - Crystal tag MUST begin with "bind", any letters after that are the ResRef
|
|
////////////////////////////////////////////////////////////////
|
|
if (GetStringLeft(GetTag(oItem), 4) == "bind"){
|
|
object oInvItem = GetFirstItemInInventory(oPlayer);
|
|
int iDoneIt = FALSE;
|
|
|
|
// Check their inventory for an unused Bindstone
|
|
while(GetIsObjectValid(oInvItem) == TRUE && iDoneIt == FALSE){
|
|
int iRightLength = GetStringLength(GetTag(oItem)) - 4;
|
|
string sItemRef = GetStringRight(GetTag(oItem), iRightLength);
|
|
string sInvItem = GetTag(oInvItem);
|
|
|
|
// Excellent we got one
|
|
if (sInvItem == "em_bindstone"){
|
|
string sCurrentRef = GetLocalString(oInvItem, "lsResRef");
|
|
string sExtraRef = GetLocalString(oItem, "lsResRef");
|
|
|
|
if (sExtraRef != ""){
|
|
sItemRef = sExtraRef; // If the crystals have their own ref then they must be custom ones.
|
|
}
|
|
|
|
if (sCurrentRef == ""){
|
|
// Take the binding crystal's tag and call that the creature resref
|
|
SendMessageToPC(oPlayer, "New creature bound to binding stone");
|
|
SetLocalString(oInvItem, "lsResRef", sItemRef);
|
|
SetLocalInt(oInvItem, "liDamage", 0);
|
|
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_REDUCE_ABILITY_SCORE), oPlayer);
|
|
|
|
iDoneIt = TRUE;
|
|
DestroyObject(oItem);
|
|
}
|
|
}
|
|
|
|
oInvItem = GetNextItemInInventory(oPlayer);
|
|
}
|
|
|
|
// Um, we checked their whole inventory and got nothing...
|
|
if (iDoneIt == FALSE){
|
|
SendMessageToPC(oPlayer, "You need to have at least 1 Bindstone in your possesion with no creatures bound to it to use this item");
|
|
}
|
|
}
|
|
}
|