Triggering a script on the death of a group
#1
Posté 16 novembre 2010 - 06:11
SetLocalInt(GetPCSpeaker(), "nStaffKilled", 0);
This line is part of a script which starts the quest. I added it so that the variable nStaffKilled was defined for later on.
Then I've added to the onDeath script of the NPCs:
if (GetLocalInt(oKiller, "nStaffKilled") == 1)
{
object oPC = GetPCSpeaker();
AssignCommand(oPC, ClearAllActions());
SetCutsceneMode(oPC, TRUE);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectCutsceneDominated(), oPC, 100.0f);
SetCameraMode(oPC, CAMERA_MODE_TOP_DOWN);
DelayCommand (2.0f, AssignCommand(oPC, FadeToBlack(oPC, FADE_SPEED_SLOWEST)));
DelayCommand (3.0f, AssignCommand(oPC, EndGame("")));
}
SetLocalInt(oKiller, "nStaffKilled", 1);
Can anyone see what's wrong? This is driving me nuts.
#2
Posté 16 novembre 2010 - 03:49
1) There is no speaker when you are in an OnDeath script.
2) You don't show were the oKiller comes from. Is it supposed to be the PC?
3) You created the variable nStaffKilled on the PC but you try to read it from the oKiller object. That will only work if the oKiller is the PC. But right after that you try to get the PC using GetPCSpeaker().
#3
Posté 16 novembre 2010 - 04:05
This can all be done in the OnDeath script for the NPC quest givers.
Get the name of the OnDeath script for the NPC quest givers. I'll assume the name is "npc_death". Also I'll assume that you have 5 NPCs you are watching to die.
Make a new OnDeath script with a different name like "npc_death2".
void Main()
{
ExecuteScript( "npc_death");
object mod = GetModule();
int deadCnt = GetLocalInt(mod,"deadCnt");
SetLocalInt(mod,"deadCnt",deadCnt+1);
if( deadCnt == 4 )
{
//do the end stuff here
object pc = GetFirstPC();
AssignCommand( pc, ClearAllActions());
SetCutsceneMode(pc, TRUE);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectCutsceneDominated(), pc, 100.0f);
SetCameraMode(pc, CAMERA_MODE_TOP_DOWN);
DelayCommand (2.0f, AssignCommand(pc, FadeToBlack(pc, FADE_SPEED_SLOWEST)));
DelayCommand (3.0f, AssignCommand(pc, EndGame("")));
}
}
I haven't run this because I'm not at home. But the idea is sound and the code is close to what you need.
The variable used is called "deadCnt" and is on the module object.
It defaults to 0 so no need to set it at module startup.
Each time one of the selected NPCs dies they will increment the deadCnt.
When the 5th one dies the deadCnt will already be 4 so that will cause the block of ending code to run.
The name "npc_death" is not going to be the real name so you need to replace that with the real name of the OnDeath script that your NPCs are using.
If the number of NPCs is different than 5 then replace 4 with whatever it is minus 1. So if there were 3 NPCs you would put 2 in place of 4. Because 2 is 3 - 1.
Modifié par Mudeye, 16 novembre 2010 - 04:11 .
#4
Posté 16 novembre 2010 - 07:12
Mudeye wrote...
A couple of things look wrong.
1) There is no speaker when you are in an OnDeath script.
WAIT!!! I didn't see that! I think that might be the problem.
2) You don't show were the oKiller comes from. Is it supposed to be the PC?
I just didn't copy that part. oKiller is defined earlier as whoever killed the creature in question.
3) You created the variable nStaffKilled on the PC but you try to read it from the oKiller object. That will only work if the oKiller is the PC. But right after that you try to get the PC using GetPCSpeaker().
Yeah, I'm not very happy with having to do that but I couldn't think of any other way of defining nStaffKilled with a starting value of 0.
I think #1 might be the problem. I'll changed it then get back to you.
#5
Posté 16 novembre 2010 - 07:25
You don't actually have to define local int variables before you read them in NWNScript. If they haven't been defined, you can still read them. The value will be 0.
You may also have the case where a henchman or summon kills the creature. In those cases you would need to get the pc from the creature with something like GetMaster().
Modifié par Mudeye, 16 novembre 2010 - 07:29 .
#6
Posté 16 novembre 2010 - 09:27
#7
Posté 16 novembre 2010 - 09:47
uberdowzen wrote...
Oh right. I thought is was like C++ where you had to define variables before you could use them. My mistake. Thanks for your help!
You are half right. If you read the comments that proceed the GetLocal functions it clears it up a bit.
// Get oObject's local integer variable sVarName
// * Return value on error: 0
int GetLocalInt(object oObject, string sVarName)
So yes if the VarName is not defined on the object you get an Error that gives you a return value of 0.
#8
Posté 17 novembre 2010 - 04:00
#9
Posté 17 novembre 2010 - 06:15
The whole point, of the statment above, Is that if you read the Header's for the functions you plan on useing a some of the questions you have will be answered.
#10
Posté 17 novembre 2010 - 06:56





Retour en haut






