Hi all. I know people have done this before, and I also know some posted their work around but a search provided no results. Perhaps I use the wrong key words, but in any case. Can someone provide me with a system which awards XP for disabling traps and unlocking devices?
Here’s a couple you could try. Just increase/decrease the iMultiplier to suit your needs. They also work for uncontrolled party members that are set to automatically unlock/disarm.
For disarming traps:
// Place in the OnDisarm handler.
#include "x0_i0_partywide"
void main()
{
object oPC = GetLastDisarmed();
object oControlledPC = GetFirstPC(FALSE);
int iMultiplier = 4;
int iXPawarddc = GetTrapDisarmDC(OBJECT_SELF) * iMultiplier;
int iXPaward = (iXPawarddc - ((GetHitDice(oPC) -1) * iMultiplier)) *2;
if (oControlledPC == oPC) SendMessageToPC(oControlledPC, "Trap disarmed");
else SendMessageToPC(oControlledPC, GetName(oPC) + " disarmed a trap");
GiveXPToAllEqually (oControlledPC, ((iXPaward > 1) ? iXPaward : 1));
}
For unlocking locks:
// Place this on Unlock event of the door.
#include "x0_i0_partywide"
void main()
{
object oPC = GetLastUnlocked();
object oControlledPC = GetFirstPC(FALSE);
int iMultiplier = 4;
int iXPawarddc = GetLockUnlockDC(OBJECT_SELF) * iMultiplier;
int iXPaward = (iXPawarddc - ((GetHitDice(oPC) -1) * iMultiplier)) *2;
if(!GetLocalInt(OBJECT_SELF, "unlocked"))
{
if (oControlledPC == oPC) SendMessageToPC(oControlledPC, "Lock unlocked");
else SendMessageToPC(oControlledPC, GetName(oPC) + " unlocked a lock");
GiveXPToAllEqually (oControlledPC, ((iXPaward > 1) ? iXPaward : 1));
SetLocalInt(OBJECT_SELF, "unlocked", TRUE);
}
}
Thanks. That should work. Now the question is if it’s worth the effort going back to all my areas and adding it. I was mostly hoping for a system which works on top of the standard behavior. Maybe overriding the default scripts which take care of the disarming. But this is hardcoded right?
In theory, you could run this script in conjunction with the Unlock/Disarm scripts. Just put this in every module’s OnClientEnter handler. I haven’t tested this, but I’m thinking you could try this instead of adding the Unlock/Disarm scripts to every trapped/locked object in the game. Worth a shot.
// place this on the module's OnClientEnter handler.
void main()
{
object oModule = GetModule();
if (!GetLocalInt(oModule, "module_updated"))
{
SetLocalInt(oModule, "module_updated", TRUE);
string sDisarm = "on_disarm_xp"; // name of the disarm xp script
string sUnlock = "on_unlock_xp"; // name of the unlock xp script
object oArea = GetFirstArea();
while (GetIsObjectValid(oArea))
{
object oObject = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(oObject))
{
if (GetIsTrapped(oObject))
{
SetEventHandler(oObject, SCRIPT_DOOR_ON_DISARM, sDisarm);
SetEventHandler(oObject, SCRIPT_PLACEABLE_ON_DISARM, sDisarm);
SetEventHandler(oObject, SCRIPT_TRIGGER_ON_DISARMED, sDisarm);
}
if (GetLocked(oObject) && !GetLockKeyRequired(oObject))
{
SetEventHandler(oObject, SCRIPT_DOOR_ON_UNLOCK, sUnlock);
SetEventHandler(oObject, SCRIPT_PLACEABLE_ON_UNLOCK, sUnlock);
}
oObject = GetNextObjectInArea(oArea);
}
oArea = GetNextArea();
}
}
}