It’s not very difficult. It’s slightly more complex if want to avoid awarding XP for using keys. Also you probably want to avoid giving XP more than once in case a lock can be re-locked using a key.
In fact I had already modified the script…
// sets the OnDisarmTrap script on every trap in a module
// that doesn't already have an OnDisarmTrap script
// requires our OnDisarmTrap script to be in override folder!
// name of our OnDisarmTrap script
const string ON_DISARM_TRAP_SCRIPTNAME = "mk_ondisarmtrap";
// name of our OnUnlock script
const string ON_UNLOCK_SCRIPTNAME = "mk_onunlock";
// Get current time in seconds (starting from when GetTime is called the first time)
int SECONDS_ZERO = -1;
float GetTime()
{
sqlquery query = SqlPrepareQueryObject(GetModule(), "SELECT STRFTIME('%s', 'now'), SUBSTR(STRFTIME('%f', 'now'), 4)");
SqlStep(query);
int nSeconds = SqlGetInt(query, 0);
int nMSeconds = SqlGetInt(query, 1);
if (SECONDS_ZERO<0)
{
SECONDS_ZERO = nSeconds;
nSeconds = 0;
}
else
{
nSeconds-=SECONDS_ZERO;
}
return IntToFloat(nSeconds)+IntToFloat(nMSeconds)/1000.0;
}
void main()
{
object oPC = GetFirstPC();
float fTime0 = GetTime();
int nCountDisarmGlobal=0;
int nCountUnlockGlobal=0;
// get location of our OnDisarmTrap script
string sScrLocDisarm = ResManGetAliasFor(ON_DISARM_TRAP_SCRIPTNAME, RESTYPE_NCS);
// get location of our OnUnlock script
string sScrLocUnlock = ResManGetAliasFor(ON_UNLOCK_SCRIPTNAME, RESTYPE_NCS);
int bModifyTraps = FALSE;
int bModifyLocks = FALSE;
if (sScrLocDisarm=="")
{
// Something wrong: OnDisarmTrap script does not exist!
SendMessageToPC(oPC, "Script "+ON_DISARM_TRAP_SCRIPTNAME+".ncs does not exist!");
}
else if (sScrLocDisarm!="OVERRIDE:")
{
// Something wrong (most likely): script with same name as our OnDisarmTrap script found
SendMessageToPC(oPC, "Script "+ON_DISARM_TRAP_SCRIPTNAME+".ncs found in "+sScrLocDisarm+"!");
SendMessageToPC(oPC, "Either our OnDisarmTrap script is misplaced or a script with the name exists at that location.");
}
else
{
bModifyTraps = TRUE;
}
if (sScrLocUnlock=="")
{
// Something wrong: OnDisarmTrap script does not exist!
SendMessageToPC(oPC, "Script "+ON_UNLOCK_SCRIPTNAME+".ncs does not exist!");
}
else if (sScrLocUnlock!="OVERRIDE:")
{
// Something wrong (most likely): script with same name as our OnUnlock script found
SendMessageToPC(oPC, "Script "+ON_UNLOCK_SCRIPTNAME+".ncs found in "+sScrLocUnlock+"!");
SendMessageToPC(oPC, "Either our OnUnlock script is misplaced or a script with the name exists at that location.");
}
else
{
bModifyLocks = TRUE;
}
if (bModifyTraps || bModifyLocks)
{
int nCountDisarmArea, nCountUnlockArea, nObjectType, nEventDisarm, nEventUnlock;
string sEventScript;
object oObject;
object oArea = GetFirstArea();
while (GetIsObjectValid(oArea))
{
oObject = GetFirstObjectInArea(oArea);
nCountDisarmArea=0;
nCountUnlockArea=0;
while (GetIsObjectValid(oObject))
{
nEventDisarm=-1;
nEventUnlock=-1;
nObjectType = GetObjectType(oObject);
switch (nObjectType)
{
case OBJECT_TYPE_TRIGGER:
nEventDisarm = EVENT_SCRIPT_TRIGGER_ON_DISARMED;
break;
case OBJECT_TYPE_DOOR:
nEventDisarm = EVENT_SCRIPT_DOOR_ON_DISARM;
nEventUnlock = EVENT_SCRIPT_DOOR_ON_UNLOCK;
break;
case OBJECT_TYPE_PLACEABLE:
nEventDisarm = EVENT_SCRIPT_PLACEABLE_ON_DISARM;
nEventUnlock = EVENT_SCRIPT_PLACEABLE_ON_UNLOCK;
break;
}
if (bModifyTraps && (nEventDisarm!=-1) && GetIsTrapped(oObject) && GetTrapDisarmable(oObject))
{
sEventScript = GetEventScript(oObject, nEventDisarm);
if (sEventScript == "")
{
SetEventScript(oObject, nEventDisarm, ON_DISARM_TRAP_SCRIPTNAME);
nCountDisarmArea++;
}
else if (sEventScript!=ON_DISARM_TRAP_SCRIPTNAME)
{
SendMessageToPC(oPC, "Area "+GetName(oArea)+": Object "+GetName(oObject)+" already has OnDisarmTrap script set ("+sEventScript+").");
}
}
if (bModifyLocks && (nEventUnlock!=-1) && GetLocked(oObject) && !GetLockKeyRequired(oObject))
{
sEventScript = GetEventScript(oObject, nEventUnlock);
if (sEventScript == "")
{
SetEventScript(oObject, nEventUnlock, ON_UNLOCK_SCRIPTNAME);
nCountUnlockArea++;
}
else if (sEventScript!=ON_UNLOCK_SCRIPTNAME)
{
SendMessageToPC(oPC, "Area "+GetName(oArea)+": Object "+GetName(oObject)+" already has OnUnlock script set ("+sEventScript+").");
}
}
oObject = GetNextObjectInArea(oArea);
}
if ((nCountDisarmArea>0) || (nCountUnlockArea>0))
{
SendMessageToPC(oPC, "Area "+GetName(oArea)+": "+IntToString(nCountDisarmArea)+" trap(s) modified, "+IntToString(nCountUnlockArea)+" lock(s) modified.");
nCountDisarmGlobal+=nCountDisarmArea;
nCountUnlockGlobal+=nCountUnlockArea;
}
oArea = GetNextArea();
}
}
float fTime1 = GetTime();
SendMessageToPC(oPC, "Number of traps modified: "+IntToString(nCountDisarmGlobal));
SendMessageToPC(oPC, "Number of locks modified: "+IntToString(nCountUnlockGlobal));
SendMessageToPC(oPC, "Duration: "+FloatToString(fTime1-fTime0, 0, 3)+"s.");
}
and the OnUnLock event script…
// OnDisarmTrap script
// script name should not exist in any module
const float UNLOCK_XP_FACTOR = 1.0f;
void main()
{
object oPC = GetLastUnlocked();
if (GetIsPC(oPC))
{
if (!GetLocalInt(OBJECT_SELF, "_DO_ONCE_XP_ON_UNLOCK"))
{
SetLocalInt(OBJECT_SELF, "_DO_ONCE_XP_ON_UNLOCK", TRUE);
string sKey = GetLockKeyTag(OBJECT_SELF);
object oKey = GetItemPossessedBy(oPC, sKey);
if (!GetIsObjectValid(oKey))
{
int nDC = GetLockUnlockDC(OBJECT_SELF);
int nXP = FloatToInt(IntToFloat(nDC) * UNLOCK_XP_FACTOR);
GiveXPToCreature(oPC, nXP);
}
}
}
}
GiveXPforUsingThiefSkills.zip (4.1 KB)