Author Topic: TakeGold and TakeGoldFromCreature  (Read 327 times)

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
TakeGold and TakeGoldFromCreature
« on: January 26, 2013, 04:11:07 am »


               Just thought I'd share something I wandered across - and I'm sure others have too...

Contrary to what the Lexicon states, TakeGold and TakeGoldFromCreature can be made to fire from the Module's OnModuleLoad or an Area's OnEnter event by using this block of code:


ExecuteScript("script_name", GetEnteringObject());

Calling TakeGold or TakeGoldFromCreature from within the executed script bypasses the restriction upon the functions. Thus script_name.nss would look something like this:


void main()
{
     int nAmount = 100;
     TakeGoldFromCreature(nAmount, OBJECT_SELF, TRUE);
}

This would take 100 gold from the caller (the entering creature) and destroy it.

Can't help but woinder what other limitations can be bypassed by using the ExecuteScript function...
               
               

               


                     Modifié par Pstemarie, 26 janvier 2013 - 04:16 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
TakeGold and TakeGoldFromCreature
« Reply #1 on: January 26, 2013, 11:40:40 am »


               I'd been using it from the start areas OnEnter in my mod, didn't even realize you weren't supposed to be able to.
 I'd been using it assigned to the PC though, which is likely why it worked, and must be handled similarly by the engine for handling it through ExecuteScript.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
TakeGold and TakeGoldFromCreature
« Reply #2 on: January 26, 2013, 02:38:50 pm »


               I think the warning in the Lexicon is about having the area or module do the taking. Assigning it to someone else works and is what both ExecuteScript("foo", GetEnteringObject()) and
AssignCommand(GetEnteringObject(), Take...) do. I.e. they're essentially doing the same thing.
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
TakeGold and TakeGoldFromCreature
« Reply #3 on: January 26, 2013, 03:28:44 pm »


               Maybe we can get these updated in the Lexicon with the notation that ExecuteScript and AssignCommand will bypass the hard-coded limitation...
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
TakeGold and TakeGoldFromCreature
« Reply #4 on: January 26, 2013, 09:24:19 pm »


               This line was in there, already:

NWN Lexicon wrote...

The taker needs to be a non-area and non-module object for it to work correctly. It can be the creature passed into oCreatureToTakeFrom, of course.

I added the following to clarify:

NWN Lexicon wrote...

If the function caller (OBJECT_SELF) is the module or an area, this function will fail. If you want to use this function in an area or module event (like an area's OnEnter), you can use AssignCommand() or ExecuteScript() to assign the function to another object.