Ironworks Gaming Forum

Ironworks Gaming Forum (http://www.ironworksforum.com/forum/index.php)
-   Neverwinter Nights 1 & 2 Also SoU & HotU Forum (http://www.ironworksforum.com/forum/forumdisplay.php?f=16)
-   -   Script Request: (http://www.ironworksforum.com/forum/showthread.php?t=35454)

Dreamer128 06-01-2003 01:06 PM

Does anyone know how to make an NPC fire a random Speakstring OnHeartbeat (or every x seconds)? I'm asking, because triggers will work only once and I'm working on part of an MP mod.

Thanks in advance.

SpiritWarrior 06-01-2003 03:29 PM

I ain't sure whether by 'random' you mean from a list of assigned strings or you just have the one string that you want the NPC to speak. Either way the one I made for you has only one string in it (you can add more if you wish).

Quote:

void main()
{

object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);

AssignCommand(oPC, ClearAllActions());

object oTarget;
SpeakString("I've got best prices this side of Amn!");
}

The problem with the Onheartbeat and string text is that the duration the text floats never ctaches up with the heartbeat so..in-game the text will just continuosuly float over the NPC's head without actually dissapearing.
I don't know exactly what you arte wanting to do but maybe if you call the script from the Onperceived lines it will work better for you (that is everytime a PC is seen by an NPC he/she will utter the string of text). Let me know if this is what you need and i'll make one up for you.

philip 06-01-2003 03:55 PM

nRandom = Random(4)

switch(nRandom)
{
case 0:
SpeakString("");
break;

case 1:
SpeakString("");
break;

case 2:
SpeakString("");
break;

case 3:
SpeakString("");
break;
}

edit: wrong function. you can add any number in Random(), results are the value in random - 1, so 4 would give results 0,1,2,3

[ 06-01-2003, 03:57 PM: Message edited by: philip ]

Dreamer128 06-02-2003 11:13 AM

Thanks guys. I'll test them as soon as possible [img]smile.gif[/img]

Legolas 06-02-2003 02:19 PM

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 ]


All times are GMT -4. The time now is 11:16 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved