PDA

View Full Version : Script that activates from multiple deaths


Doc Valentine
01-11-2005, 07:29 AM
Hey guys, I need to know how to make it so that when you kill 4 guards a convo will activate. Here is the scene, you are in a cantina talking to a hutt and his guards attack you, how do i make it so that when all of them die he talks to you?

tk102
01-11-2005, 07:36 AM
Here's one way: User-defined on-death script for each of them. The script looks to see if there are any living guards left. If not, ActionStartConversation is fired on the Hutt.

Doc Valentine
01-11-2005, 07:46 AM
so uh, how would that look like? in code i mean

tk102
01-11-2005, 08:59 AM
See this (http://www.lucasforums.com/showthread.php?s=&postid=1522866#post1522866) thread starting at DeathDisco's request for implementing an OnUserDefine script for the OnDeath event.

Assuming the NPCs have different tags, the OnDeath code would go something like this:


void main () {
if (
GetIsDead(GetObjectByTag("NPC1_tag")) &&
GetIsDead(GetObjectByTag("NPC2_tag")) &&
GetIsDead(GetObjectByTag("NPC3_tag")) &&
GetIsDead(GetObjectByTag("NPC4_tag"))
) {
AssignCommand(
GetObjectByTag("Hutt_tag"),
ActionDoCommand( ActionStartConversation(GetFirstPC(),"The_2nd_dialog_name"))
);
}
}

deathdisco
01-25-2005, 08:34 AM
TK, Is there any reason why this script would not work consistently? I found that it does not work often unless the fight is real short. IE: All the enemies(three of them, script adjusted accordingly) VP is set to 10. :confused: I have more details if need be.

tk102
01-25-2005, 10:50 AM
Maybe the enemies are disappearing (body fading) before the fight is over? In that case the GetObjectByTag function would be returning OBJECT_INVALID. To circumvent this, you could toss in the following line of code before the if statement:
SetIsDestroyable(FALSE);

deathdisco
01-25-2005, 11:25 AM
No they don't disappear, I tried it anyway but got the same results. Could it be a goofy savegame I'm working from?

tk102
01-25-2005, 11:39 AM
Strange. Maybe this would work:
void main () {
SetLocalBoolean(OBJECT_SELF,3,TRUE);
if (
GetLocalBoolean(GetObjectByTag("NPC1_tag"),3) &&
GetLocalBoolean(GetObjectByTag("NPC2_tag"),3) &&
GetLocalBoolean(GetObjectByTag("NPC3_tag"),3) &&
GetLocalBoolean(GetObjectByTag("NPC4_tag"),3)
) {
AssignCommand(
GetObjectByTag("Hutt_tag"),
ActionDoCommand( ActionStartConversation(GetFirstPC(),"The_2nd_dialog_name"))
);
}
}

deathdisco
01-25-2005, 01:32 PM
Doesn't work:( The last set of && are unnesessary correct?

tk102
01-25-2005, 01:45 PM
(I removed the erroneous &&)

I guess it's time to try the SendMessageToPC function to see whether or not the scripts are being fired.

Insert this before the SetLocalBoolean function.

SendMessageToPC(GetFirstPC(),"OnDeath Script Fired for "+GetTag(OBJECT_SELF));


Maybe we should take this to PM land.

Doc Valentine
04-11-2005, 09:36 PM
Hey guys sorry to bring this dinosaur up but i am having a similar situation in the mod. I have it where there are 17 guys on a ship you have to kill, and when they are all dead, a script will fire that has dialog with ace playing. Can I jsut set it to one tag or do i have to do ALL of them unique and set it up here, because there are 17 of them. Is there a script that will chekc to see if there are enemies in the area?

stoffe
04-12-2005, 06:30 AM
Originally posted by Gsccc
I have it where there are 17 guys on a ship you have to kill, and when they are all dead, a script will fire that has dialog with ace playing. Can I jsut set it to one tag or do i have to do ALL of them unique and set it up here, because there are 17 of them.

A custom OnDeath script like this one would probably work if set on the 17 enemies if they all have the same tag.

I would use the OnDeath event script directly rather than a UserDefined script for this since the OnDeath UserDefined was somewhat unreliable in Neverwinter Nights (didn't always fire) and I am unsure if they fixed that problem for KotOR.


// OnDeath Event Script

#include "k_inc_switch"

void main()
{
string sTag = GetTag(OBJECT_SELF);
int nCount = 0;
int i = 0;

object oTalker = GetObjectByTag("speaker_tag");
object oGuard = GetObjectByTag(sTag, i);

while (GetIsObjectValid(oGuard)) {
if ((oGuard != OBJECT_SELF) && !GetIsDead(oGuard)) {
nCount++;
break;
}

oGuard = GetObjectByTag(sTag, ++i);
}

if ((nCount == 0) && !GetIsInConversation(oTalker)) {
AssignCommand(oTalker, ClearAllActions());
AssignCommand(oTalker, ActionStartConversation(GetFirstPC(), "alldead_dialog"));
}

ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_DEATH);
}


Or, if you wish to check for any hostile creature in the area and not just a defined group, this would probably work as well:


// OnDeath Event Script

#include "k_inc_switch"

void main() {
int nCount = 0;
object oTalker = GetObjectByTag("speaker_tag");
object oCreature = GetFirstObjectInArea();

while (GetIsObjectValid(oCreature)) {
if (((GetStandardFaction(oCreature) == STANDARD_FACTION_HOSTILE_1)
|| (GetStandardFaction(oCreature) == STANDARD_FACTION_HOSTILE_2))
&& (oCreature != OBJECT_SELF)
&& !GetIsDead(oCreature))
{
nCount++;
break;
}

oCreature = GetNextObjectInArea();
}

if ((nCount == 0) && !GetIsInConversation(oTalker)) {
AssignCommand(oTalker, ClearAllActions());
AssignCommand(oTalker, ActionStartConversation(GetFirstPC(), "alldead_dialog"));
}

ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_DEATH);
}

Razorfish.8
04-13-2005, 02:51 PM
Just wanted to add that GetIsObjectValid( GetNearestCreature( CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1 ) ) would probably return an accurate indication of whether or not there are any enemies left in the module. The script c_foeinsight contains a variant of the above snippet with a perception check.

Also, have you checked out the code for the Sith boarding party sequence after the Peragus turret game in 005EBO? It does mostly what the people in this thread describe (OnDeath script), with the only exception being that it uses a global number to keep track of how many troopers you still have to kill.