View Single Post
Old 03-30-2013, 08:16 AM   #12
Fair Strides 2
Witty Programmer
 
Fair Strides 2's Avatar
 
Join Date: Jan 2012
Location: Oregon, United States
Posts: 595
Current Game: Master of Orion 2
Helpful! 
Quote:
Originally Posted by arsenalforever View Post
So my final code will be:

Code:
void main()
{
ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_HEARTBEAT);

if(GetLastPerceived() == GetFirstPC)
{
ExecuteScript("talk", OBJECT_SELF);
}
}
right?

The script me and zbyl2 made is saved by the name of "talk.ncs" on the desktop.
Also, I have a few questions regarding the above script:

1. What do the second and third parameter indicate in the ExecuteScript function?
2. Can you explain what the if condition actually means? What does it do? Thanks.
3. What name should I save the above script as? What should I do next?
4. What should I write in place of "KOTOR_DEFAULT_EVENT_ON_HEARTBEAT"?
1. They mean the target of the script and the script variable repectively. The script variable is a number or Constant(which can be words) and is passed to the script. The third arguement above will execute the code in the block following the arguement. An example is the spell system; it uses one execution script and one reference script that has all the spell code in it, just switched based on the Constant passed to it.

2. The if statement will perform a calculation based on data returned to it. It will compare the pieces of data(in this case whatever is returned by my functions) using a given operator(==, !=). It returns a 1(True) or 0(False). If it returns true, it does whatever's in the code block, if it returns false, the script skips the code block and continues.

P.S: You can make an if statement do more than one calculation by using &&(which means "AND") and ||(which means "OR"). Useful for checking if a person is visible AND is the first pc, for instance. Another example: You check if the target is a Soldier OR a Scout.

3. Any name you want, so long as it matches the OnHeartbeat script's field. Now if it compiles, move the .ncs for it and the talk.ncs to your override folder, along with the .utc file.

Follow this tutorial to make your guy spawn when you enter the module. Just use this code as the OnEnter script and you should be okay(though you'll have to know which module script it is, which you can get the same as the .utc but with a module's .ifo file under "Tsl or Kotor->rims-your module".):

Code:
void main()
{
        vector Spawn; \\ declare a vector
        Spawn.x = f;   \\ Specify the x-coordinate
        Spawn.y = f;   \\ Specify the y-coordinate
        Spawn.z = f;   \\ Specify the z-coordinate
        float a = f;      \\ Specify the float(direction the creature will face)

CreateObject(OBJECT_TYPE_CREATURE, "dgon", location(Spawn, a)); \\ Easy made location with the vector and float all wrapped up

ExecuteScript("Name of module's script here", OBJECT_SELF);
}
That oughta work, and if you don't understand what's going on here, then check my PM about the nwn lexicon.

P.S: If you want the script to activate when you're 3 meters from the gamorrean, use this(just replace the 3 if you want a different distance):
Code:
void main()
{
ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_HEARTBEAT);

if(GetLastPerceived() == GetFirstPC && GetDistanceToObject(GeFirstPC()) == 3)
{
ExecuteScript("talk", OBJECT_SELF);
}
}
4. Nothing. Keep it as it is.


All of my mods are available on Deadlystream.

Always remember modders: "Quality= Effort*Time"

KSE 3.3.4 is LIVE!!! Check it out here.

Check out WalkSwitch, the Walkmesh-changing tool!
Fair Strides 2 is offline   you may: quote & reply,