Thread: Script Request:
View Single Post
Old 06-02-2003, 02:19 PM   #5
Legolas
Jack Burton
 

Join Date: March 31, 2001
Location: The zephyr lands beneath the brine.
Age: 40
Posts: 5,459
I'd actually try changing the OnSpawn script by deleting the '//' in front of the 'SetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT);' line, then editing the OnUserDefined script as follows.
Quote:
...
if(nUser == 1001) //HEARTBEAT
{
if (GetDistanceToObject(oPC) 'smaller than symbol' 25.0) && (GetTag(OBJECT_SELF) == "speaker")
{
int iSpeakRand5 = Random(5);
if(iSpeakRand5 == 1)
{
SpeakString("Line number 1");
}
else if(iSpeakRand5 == 2)
{
SpeakString("Another line");
}
else if(iSpeakRand5 == 3)
{
SpeakString("The final line!");
}
else
{
}
}
}
else if(nUser == 1002) // PERCEIVE
...
Some things you may or may not note. First, the
Quote:
else
{
}
line is not necessary for the script to work. You could leave it out. I keep it because it feels more complete, and you can more easily test to see if the script runs by inserting a 'PrintString("...");' command.
Second, I'm using a random giving 5 answers instead of just three. That's because you probably do not want to have a new line on every single OnHeartbeat event. You can change it to higher numbers and that will decrease the frequency even further.
Third, this script only works when you are near the NPC, within 25 meters in this case.
Fourth, you'll need to define a speaker (just insert the tag of the NPC there) and an 'oPC'. SpiritWarrior's definition is rather complete, and also includes the distance factor which means you could leave it out here.
Fifth, I had to type 'smaller than symbol' because IW wouldn't allow the symbol in what it recognises to be html. Not even in the text down here. Virus protection, I assume. It's the V with the opening to the right, should you be unaware of what it looks like. Third key left of the rightshift.
Finally, it's put in the OnUserDefined script rather than inserted directly into the OnHeartbeat script. That's because I have found the OnHeartbeat script may cause your game to stutter when you put lines into it (like a ClearAllActions() for everyone every six seconds), whereas this should not. Using the UserDefined events is also the more organised way of doing things (although the switch is also more organised than the if-then-else procedure, you may want to mix the two of them).

[ 06-02-2003, 02:20 PM: Message edited by: Legolas ]
Legolas is offline   Reply With Quote