Author Sticky: Post Working Scripts Here
Todmaerin Posted: Monday, 01 July 12:55AM
NOTE: 1 report by a user that said he could get neither of these scripts to work (and put them in the correct event slots).

Dynamic XP on Trap Disarm / Lock Unlocking

I wish I could go back and edit my original post to keep the thread clean. Ah well. I cleaned things up again, as well as decreasing the complexity of the test. Same gimmick as before, dynamically award XP based upon the rogue's level and skill versus the difficulty.

For traps, in OnDisarm:

NWScript:
//Disarm Trap XP award for Thieves

//Operates on this math: (TrapDC * XPMultiplier) - (ThiefLevel x Skill) = XP Award

// Created by Todmaerin 6/22/02

// Modified 6/30/02



object oThief = GetLastDisarmed();

void main()

{

       string sThiefLevel;

       int nPosition;

       int nRogueTrue;

       for (nPosition= 1; nPosition <= 3; nPosition ++)

        {

         nRogueTrue = GetLocalInt(oThief, IntToString(GetClassByPosition (nPosition, oThief) ));

        };

        if (nRogueTrue = CLASS_TYPE_ROGUE)

          {

           sThiefLevel = IntToString(GetLevelByClass (CLASS_TYPE_ROGUE, oThief));

                 int nDisarmSkill = GetSkillRank(SKILL_DISABLE_TRAP, oThief);

                 int nTrapDC = GetTrapDisarmDC(OBJECT_SELF);

                 float fXPMod = 1.2;

                 //the math

                 int nXPAward = FloatToInt((nTrapDC * fXPMod) - (StringToInt(sThiefLevel) * nDisarmSkill));

                 GiveXPToCreature (oThief, nXPAward);

          }



}



For locks, in OnUnlock:

NWScript:
//Unlock XP award for Thieves

//Operates on this math: (UnlockDC * XPMultiplier) - (ThiefLevel x Skill) = XP Award

//

// Created by Todmaerin 6/22/02

// Modified 6/30/02

object oThief = GetLastUnlocked();

void main()

{

       string sThiefLevel;

       int nPosition;

       int nRogueTrue;

       for (nPosition = 1; nPosition <= 3; nPosition ++)

        {

         nRogueTrue = GetLocalInt(oThief, IntToString (GetClassByPosition (nPosition, oThief) ));

        };

        if (nRogueTrue = CLASS_TYPE_ROGUE)

          {

           sThiefLevel = IntToString(GetLevelByClass (CLASS_TYPE_ROGUE, oThief) );

                 int nUnlockSkill = GetSkillRank(SKILL_OPEN_LOCK, oThief);

                 int nLockDC = GetLockUnlockDC(OBJECT_SELF);

                 float fXPMod = 1.2;

                 //the math

                 int nXPAward = FloatToInt((nLockDC * fXPMod) - (StringToInt(sThiefLevel) * nUnlockSkill) );

                 GiveXPToCreature( oThief, nXPAward);

          }



}



As always, drop me a line if you have any trouble with these. Now if only I can get traps to respawn...

Grrr.. too many characters notification again.

-Tod

There may be trouble with this script.  A visitor to the site has said:

PM to Dave: "I've been absolutely inundated with angry folks trying to get my dynamic XP on successful Unlock to work. As it turns out, the OnUnlock and OnDisarm events don't appear to be firing. Period. I've tried sending a simple message to the PC to complex debugging information from the script I'm calling; nothing is being returned. I know the events used to work, seeing as I wrote the scripts to be called back during 1.18 and tested it extensively."

Response from Dave: "Yup. If you look at the events listing in the scripting FAQ post, I do already know about this (and it has been reported). Hopefully we will get it fixed relatively soon, because I agree it's incredibly annoying."