Page 1 of 1

OBJECT_SELF

Posted: Tue Nov 02, 2004 3:38 am
by 4x4_Ender
This might be a dumb question, proving my incredible n00bness in coding using NWNscript. But, what exactly does this command do and when can you use it?? I see it all the time in scripts but never know what its used for.

For example, its used in this script to define the oSourceFactionMember to adjust the reputation of an attacking creature by -35:

Code: Select all

// this function will lower by 35 points how the attackee's 
// faction will view the attacker.
main()
{
     object oAttacker = GetLastAttacker();
     if(GetIsObjectValid(oAttacker))
     {
          AdjustReputation(oAttacker, OBJECT_SELF, -35);
     }
}
In order for OBJECT_SELF to work, does it have to be assigned to an object itself somehow, mabye on some event in the object?

Posted: Tue Nov 02, 2004 4:00 am
by kombinat
It's not a command, it's a pre-defined variable which you can use to access the object that the currently executing script is attached to, be it placeable, character, item, creature, whatever, I believe. You should not try to assign anything to it.

Posted: Tue Nov 02, 2004 4:25 am
by Lafferty
It's a reference to the calling object. If you for example have a lever that gets pulled and opens a door and deals 5 damage to the user, you hook a script to OnUsed to the lever. That makes the lever the calling object in that moment (the OBJECT_SELF).
In order to access the other 2 objects involved in the example you need to utilize different commands of the nwn scripting engine like GetLastUsedBy() or GetObjectByTag().

Posted: Tue Nov 02, 2004 4:37 am
by 4x4_Ender
Makes sense. Thanks!

Posted: Tue Nov 02, 2004 6:17 pm
by 4x4_Ender
Something i was wondering about this (i know mist told me to cork it, but this wont take long :P ).....

Can you use OBJECT_SELF with GetObject() in a conversation to define an object variable for the NPC that has the conversation applied to them?? Otherwise, you have to use GetObjectByTag() for all the conversation scripts involving the NPC object, which means you need to make a bunch of scripts that are specific to that NPC's tag and cant be used for anything else.

Posted: Tue Nov 02, 2004 7:06 pm
by Sindol
4x4_Ender wrote: Can you use OBJECT_SELF with GetObject() in a conversation to define an object variable for the NPC that has the conversation applied to them?? Otherwise, you have to use GetObjectByTag() for all the conversation scripts involving the NPC object, which means you need to make a bunch of scripts that are specific to that NPC's tag and cant be used for anything else.
In conversation scripts the NPC that has the conversation attached is the caller and will be specified with OBJECT_SELF yes.