/*---------------------------------------------------------------- // Title: Fast buffing item //---------------------------------------------------------------- // Scriptname: fastbuff.nss //---------------------------------------------------------------- // Description //---------------------------------------------------------------- // This item will buff the player or player's party member auto- // matically as long as the player has the spells prepared, memo- // rized or learned. It'll automatically skip weapon buffing // spells if the player doesn't have any weapons equipped. // It also detects if the player is equipping a melee, slashing, // quarterstaff or ranged weapon. // If the item itself is targeted, a script conversation will // pop up for the player to configure the fast buff item. //---------------------------------------------------------------- // Created By: Stefano, 30/October/2020 // Modified By: Stefano, 20/November/2020 //--------------------------------------------------------------*/ #include "zdlg_include_i" #include "fastbuff_inc" // Main part of the script void main() { // Will create array for spells if it's not created yet if(GetLocalInt(GetModule(), "Spell_Array_Created") != 1) { CreateArray(); } int iEvent = GetUserDefinedItemEventNumber(); // Declaring variables object oPC; // The Player object oItem; // The Item Activated object oItem2; // The fast buff item (just for sanity check) object oTarget; // Target of fast buff int iSpellID; // Spell ID int i; // Int for "for" loop int startI; // Starting int for "for" loop int arraySize; // Gets the size of array for "for" loop int iWeapon; // Weapon type if (iEvent == X2_ITEM_EVENT_ACTIVATE) { // Setting variables oPC = GetItemActivator(); oItem = GetItemActivated(); oItem2 = GetItemPossessedBy(oPC, "fastbuff"); oTarget = GetItemActivatedTarget(); // Not usable in combat if(GetIsInCombat(oPC)) { FloatingTextStringOnCreature("Can't do this in combat", oPC, FALSE); return; } // Check if it's itself if(oItem == oTarget) { // Start script dialog named "script_conv" StartDlg(oPC, oItem, "script_conv", TRUE, FALSE, FALSE); return; } // Check if object is valid if(!GetIsObjectValid(oTarget) || !GetIsPartyMember(oPC, oTarget)) { SendMessageToPC(oPC, "Invalid target"); return; } // Get weapon type iWeapon = GetWeaponType(oPC); // Sets parameters for "for" loop according to the weapon type switch (iWeapon) { /* ORIGINAL case 0: startI = 10; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; case 1: startI = 4; arraySize = GetIntArraySize("SpellBuff", GetModule()); break; case 2: startI = 0; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; case 3: startI = 2; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; case 4: startI = 10; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; */ case 0: startI = 10; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; case 1: startI = 0; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; case 2: startI = 0; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; case 3: startI = 0; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; case 4: startI = 10; arraySize = GetIntArraySize("SpellBuff", GetModule()) - 1; break; } // For loop for(i = startI; i < arraySize; i++) { // Sets iSpellID the value found at index i from array iSpellID = GetIntArrayElement("SpellBuff", i, GetModule()); // If the player has the spell prepared/memorized/learned // And want the spell to be cast (set by the conversation) if(iSpellID != 0 && GetHasSpell(iSpellID, oPC) >= 1 && GetLocalInt(oItem2, IntToString(iSpellID)) != 1) { AssignCommand(oPC, ActionCastSpellAtObject(iSpellID, oTarget, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE)); } } } }