How do I put a delay in a script?

I’m not a fan of scripting but I thought I could at least manage this… But I couldn’t !

I’ve got a conversation firing when somebody dies but I can’t delay it and it’s weird to jump from a fight straight to talking here’s my script…

void main()
{
object oPC = GetLastKiller();
if (!GetIsPC(oPC)) return;
object oTarget;
oTarget = GetObjectByTag("conversation_owner");
AssignCommand(oTarget, ActionStartConversation(oPC, "my_conversation",FALSE,FALSE,TRUE,FALSE));

}

I tried putting a delay as the last line before the } using…

DelayCommand(2.0, StartConversation);

But it wont work and on the functions bit of the scripting area that’s all it says it needs and I’ve seen delays in other scripts just put as the last lines so what’s up with mine ?

Maybe try:

DelayCommand(2.0, AssignCommand(oTarget, ActionStartConversation(oPC,"my_conversation",FALSE,FALSE,TRUE,FALSE)));

Edit: corrected a mistake

1 Like

Thanks andgalf it definitely compiles I’ll test it later as I have to battle to that point in the module.

Does this mean that the delay cannot be separate it has to include what it’s delaying ?

Not sure exactly what you’re getting at, but yes.

EDIT: Ok, I think I know what you mean now. You wonder if you can just put a random delay in that delays everything that comes after? I don’t believe you can do it like that. I think you have to always show the game what it is that you want delayed. I also think, not 100 % sure about this, that the things that you delay are the the last things the script do. So if you have a series of events and a delay on an event in the middle (maybe “event” is the wrong word here, but I hope you get what I mean) of the script, the script will run that last. It’s how I’ve understood it, but I could be wrong here.

What you can do also, is to wrap up everything it’s suppose to delay in a function. I often do that if I want a series of events to be delayed. Let’s say you first want to destroy an object and then the conversation is suppose to start, and you want to delay the whole thing (it’s easier to get that right than just put a delay on every single function you want delayed, if they are to be delayed equally much (is that correct english?)), then you could do it like this:

void DestroyAndTalk(object oPC)
{

object oTarget = GetObjectByTag("conversation_owner");
object oTheObject  = GetObjectByTag("dontdestroymeplease");

DestroyObject(oTheObject);
AssignCommand(oTarget, ActionStartConversation(oPC,"my_conversation",FALSE,FALSE,TRUE,FALSE));	


}


void main()
{

object oPC = GetLastKiller();
if (!GetIsPC(oPC)) return;

DelayCommand(2.0,DestroyAndTalk(oPC));

}

EDIT: This is a great source to check, even if in the beginning didn’t grasp it all (still some things I don’t quite grasp, I guess), to learn more about scritping:
https://neverwintervault.org/forums/neverwinter-nights-2/nwn2-tutorials/basic-scripting-not-so-basic
I’ve always thought @kevL_s is great at explaining things, or maybe it’s like he understands how my confused brain works, and get what I mean when I’m asking him stuff. :man_shrugging:
Since you @Tsongo is probably way more intelligent than me, you might grasp it right away. :upside_down_face:

3 Likes

Thanks angalf and don’t worry I understand what you mean and I’ll have a look at the tutorial and see what I can understand.

The addition to my script that you wrote worked perfectly. I went at the module with a level 20 hasted monk and got to the script running point very fast. It was actually quite amusing to watch the devastation of the baddies !

1 Like