#include "x2_inc_switches" #include "adv_include" #include "nwnx_events" #include "nwnx_funcsext" #include "x0_i0_position" // Use Lockpick script. // This fires when a player uses his or her lockpick on a door or placeable. // Checks are made to see if player meets prerequisite lockpicking skill level and if so, // the process to unlock the object is made. At any point during the process the player may // Temporary variable used to determine whether or not a PC is currently picking a lock // cancel the process by using the lockpick again. // Unlocked objects will automatically relock after two minutes. ////////////////////////////////// // LOCKPICKING SYSTEM CONSTANTS // ////////////////////////////////// // Keeps track of the PC's current status (I.E: If they're lockpicking at the moment or not) const string LOCKPICK_TEMP_CURRENT_STATUS = "LOCKPICK_TEMPORARY_CURRENTLY_PICKING_LOCK"; // Tracks the object being unlocked. const string LOCKPICK_TEMP_UNLOCKING_OBJECT = "LOCKPICK_TEMP_UNLOCKING_OBJECT"; // Name of the variable stored on the locked object which determines the level of lockpicking skill required const string LOCKPICK_SKILL_REQUIRED = "LOCKPICK_SKILL_REQUIRED"; // The maximum distance a player may be from the target const float LOCKPICK_MAX_DISTANCE = 2.5; void main() { object oPC; object oLockpick; object oTarget; if(ADV_USING_LINUX) { oPC = OBJECT_SELF; oLockpick = GetEventItem(); oTarget = GetEventTarget(); } else { if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return; oPC = GetItemActivator(); oLockpick = GetItemActivated(); oTarget = GetItemActivatedTarget(); } int iSkillRequired = GetLocalInt(oTarget, LOCKPICK_SKILL_REQUIRED); int iSkill = ADV_GetUpgradeLevel(oPC, ADV_ID_LOCKPICKING); // Already picking the lock - cancel the action and inform the user if(GetLocalInt(oPC, LOCKPICK_TEMP_CURRENT_STATUS)) { DeleteLocalInt(oPC, LOCKPICK_TEMP_CURRENT_STATUS); StopTimingBar(oPC); FloatingTextStringOnCreature(ColorTokenRed() + "Lockpicking canceled!" + ColorTokenEnd(), oPC, FALSE); SetCommandable(TRUE, oPC); // Remove temporary variable linking to the object being unlocked DeleteLocalObject(oPC, LOCKPICK_TEMP_UNLOCKING_OBJECT); } // Object is not locked. else if(!GetLocked(oTarget)) { FloatingTextStringOnCreature(ColorTokenRed() + "That object is not locked." + ColorTokenEnd(), oPC, FALSE); return; } // Object cannot be unlocked using a lockpick else if(iSkillRequired <= 0) { FloatingTextStringOnCreature(ColorTokenRed() + "You cannot pick that lock." + ColorTokenEnd(), oPC, FALSE); return; } // Skill level is too low else if(iSkillRequired > iSkill) { FloatingTextStringOnCreature(ColorTokenRed() + "Your skill level is too low. (Required: " + IntToString(iSkillRequired) + ")" + ColorTokenEnd(), oPC, FALSE); return; } // Too far away else if(GetDistanceBetween(oPC, oTarget) > LOCKPICK_MAX_DISTANCE) { FloatingTextStringOnCreature(ColorTokenRed() + "You must get closer to do that." + ColorTokenEnd(), oPC, FALSE); return; } // All requirements met. Begin process to unlock object else { int iSeconds = 10 + Random(5); float fSeconds = IntToFloat(iSeconds); int iSkillBonus = abs(iSkillRequired - iSkill); // Number of seconds is reduced depending on how many skill ranks a player // has over the minimum skill required. // Cap is 75% of normal if(iSkillBonus > 0) { float fMultiplier = iSkillBonus * 0.05; if(fMultiplier > 0.75) fMultiplier = 0.75; fSeconds = fSeconds * fMultiplier; iSeconds = FloatToInt(fSeconds); } // Animation stuff TurnToFaceObject(oTarget, oPC); AssignCommand(oPC, PlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0, fSeconds)); AssignCommand(oPC, SetCommandable(FALSE,oPC)); DelayCommand(fSeconds, SetCommandable(TRUE, oPC)); // Show timing bar, set PC's current action status, and inform PC they're picking a lock. StartTimingBar(oPC, iSeconds, "perform_lockpick"); SetLocalObject(oPC, LOCKPICK_TEMP_UNLOCKING_OBJECT, oTarget); SetLocalInt(oPC, LOCKPICK_TEMP_CURRENT_STATUS, TRUE); DelayCommand(fSeconds + 0.2, DeleteLocalInt(oPC, LOCKPICK_TEMP_CURRENT_STATUS)); FloatingTextStringOnCreature(ColorTokenPurple() + "You begin picking the lock..." + ColorTokenEnd(), oPC, FALSE); } }