GAME CONCEPT AND DESIGN
COSC 320.101_SU09
SUMMER 2009
Who Dun' It?
NWN scripts pretty much live alone, completely unaware of any of the other scripts that are there. That means that every time a script runs, you usually have to spend a few lines of code figuring out "who did it" and "who they did it to."
Who Spoke?
When a conversation takes place, it typically occurs between an object (NPC or placeable) and a player. When a conversation node kicks off a script (through the "Actions Taken" or the "Text Appears When" tabs) that means you're probably going to do something to the PC that's involved in the conversation and possible to the object running the conversation. Use these commands to locate that data:
object oSelf = OBJECT_SELF;
object oSpeaker = GetPCSpeaker( );
(Of course, OBJECT_SELF is a constant, so you don't really need to store it inside another variable). And I used oSpeaker, but you could use anything oPlayer is a favorite because, after all, who else would be speaking?
Who Used the Placeable?
If a player clicks on a placeable that is set to be "Used" then you'll want to find out who used it.
object oPlayer = GetLastUsedBy( );
Who Activated an Item?
If there's a "magic item" that can be used--particularly if you created it using the Unique Power-Self Only option, you'll need to find out who used it and what item was used. Remember that this is usually done as part of the module's onActivateItem script...
object oPlayer = GetItemActivator( );
oItem = GetItemActivated( );
string sItem = GetTag(oItem);
For all you programmers out there--yes you can nest things. I could have found the tag of the item with this line instead:
string sItem = GetTag(GetItemActivated( ));
If I want to test the tag of the item against a known string (say the "bent_wand") I could even nest that into my if( ):
if(GetTag(GetItemActivated()) == "bent_wand")
...but I find that to be a bit glazed-eye inducing, so I tend to break it out one-line-at-a-time, just like high school alegbra!
Who Crossed the Trigger? Who Entered the Area?
To find out who entered a trigger or entered an area, use:
object oCreature = GetEnteringObject( );
To find out who left a trigger or area, use:
object oCreature = GetExitingObject( );
Was It a Player? a DM?
Once you've "put your finger" on the creature that caused the script to run, you might want to find out if it was a player or a monster that did it.
For triggers and areas, its it quite possible that the "entering object" was not a player but was a creature. Typically you will want something to happen when it's the player...and nothing when it's a monster. So you'll have to test the identity of the creature after you find out who it is:
object oCreature = GetEnteringObject( );
if(GetIsPC(oCreature) == TRUE)
{
...//your code
}
Of course, here I'm testing to see if the entering object was a player, but once your script has identified the oCreature of any of the events, you can test to see if it was a player.
Usually, the DM character doesn't trip triggers. But he can (I think) make an area's onEnter script fire. Regardless, you can also find out if the person who caused the script to run is a DM character.
if(GetIsDM(oCreature) == TRUE)
and now you know. |