Originally Posted by arsenalforever
Is the second parameter of ExecuteScript() always OBJECT_SELF?
What does the GetLastPerceived() function do?
And I get an error when I'm compiling the first script. The error has something to do with the compiler not being able to identify KOTOR_DEFAULT_EVENT_ON_HEARTBEAT. Also, why have you not used KOTOR_DEFAULT_EVENT_ON_HEARTBEAT parameter in the if condition?
Thanks for your reply
1. You don't have
to, but the second parameter is the target that calls the script. The caller is used by a lot of functions, but an example is giving the parameter as:
object oAtton = GetObjectByTag("atton");
ExecuteScript("k_ai_master", oAtton, 1001);
This will make any instances of "OBJECT_SELF" be Atton.
2. The GetLastPercieved() function will return the last creature percieved through any means. It will return the most recent creature detected by hearing, seeing, or a combination of a lack of one or the other. If you want to be more specific, there are functions to get the last percieved thing by sight or hearing(GetLastPercievedHeard() and GetLastPercievedSeen()).
3. There is a code loop syntax called the switch statement. It will take an integer variable and execute a section of code based on that integer. Here's a sample of code from K_ai_master to show you:
//DEFAULT AI EVENTS
int KOTOR_DEFAULT_EVENT_ON_HEARTBEAT = 1001;
int KOTOR_DEFAULT_EVENT_ON_PERCEPTION = 1002;
int KOTOR_DEFAULT_EVENT_ON_COMBAT_ROUND_END = 1003;
int KOTOR_DEFAULT_EVENT_ON_ATTACKED = 1005;
int KOTOR_DEFAULT_EVENT_ON_DAMAGE = 1006;
int KOTOR_DEFAULT_EVENT_ON_DEATH = 1007;
int KOTOR_DEFAULT_EVENT_ON_DISTURBED = 1008;
int KOTOR_DEFAULT_EVENT_ON_BLOCKED = 1009;
int KOTOR_DEFAULT_EVENT_ON_FORCE_AFFECTED = 1010;
int KOTOR_DEFAULT_EVENT_ON_GLOBAL_DIALOGUE_END = 1011;
int KOTOR_DEFAULT_EVENT_ON_PATH_BLOCKED = 1012;
case 1001: //KOTOR_DEFAULT_EVENT_ON_HEARTBEAT
case 1002: // KOTOR_DEFAULT_EVENT_ON_PERCEPTION
So, for your compile error, try replacing the "KOTOR_DEFAULT_EVENT_ON_HEARTBEAT" with "1001".
Also, I didn't use it in the if conditional because it wasn't needed. The script is
the OnHeartbeat, so there's no point in calling the script your currently running.
4. And no problem. I'm happy to share my scripting knowledge.