Jump to content

Home

Scripting help needed...


Darth InSidious

Recommended Posts

I'm trying to get this script to perform a global check so that as each of five characters dies, it increases a global number. When the number reaches five, it's meant to spawn a new character. Obviously, I don't know in what order the characters will be killed, so I'm trying to make it possible to do in any order. I've tried using if(GetGlobal[blahblahblah]){SetGlobal[blah]} else{if(GetGlobal...){SetGlobal...}else{etc} functions, switch and case functions, etc etc but nothing will let me set the number above 1. Here's the script I've been using so far:

 

#include "k_inc_generic"
#include "k_inc_utility"
void main()
{
{
   int nCurrentHP;
   int nUser = GetUserDefinedEventNumber();
   if(nUser == 1006) // DAMAGED
   {
      nCurrentHP=GetCurrentHitPoints();
      if (nCurrentHP<20) {
          CancelCombat (OBJECT_SELF);
          ClearAllActions();
          ChangeToStandardFaction(OBJECT_SELF, 5);

       SetLocalBoolean(OBJECT_SELF,0,TRUE); 

       SetMinOneHP(OBJECT_SELF,FALSE);

      }

   }
object oItem = GetFirstItemInInventory(OBJECT_SELF);
while (GetIsObjectValid(oItem)) {
	SetPlotFlag(oItem, FALSE);
	DestroyObject(oItem, 0.0);
	oItem = GetNextItemInInventory(OBJECT_SELF);

object oGoodbye;
oGoodbye = (OBJECT_SELF);    
DelayCommand(1.0, DestroyObject(oGoodbye));

int nQMD = GetGlobalNumber("MasterDead");
int nNoMasterDead = GetScriptParameter( 0 );
int n1MD = GetScriptParameter( 1 );
int n2MD = GetScriptParameter( 2 );
int n3MD = GetScriptParameter( 3 );
int n4MD = GetScriptParameter( 4 );
int n5MD = GetScriptParameter( 5 );
int nSet1 = GetScriptParameter( 1 );
int nSet2 = GetScriptParameter( 2 );
int nSet3 = GetScriptParameter( 3 );
int nSet4 = GetScriptParameter( 4 );
int nSet5 = GetScriptParameter( 5 );

switch (nQMD)
{
case 0:
{

if( GetGlobalNumber("MasterDead") == nNoMasterDead )
{ 
SetGlobalNumber( "MasterDead",  nSet1 );
SendMessageToPC(GetPartyLeader(), "DEBUG: GLOBAL NUMBER NOW SET TO 1");
}

else
{
}

}break;

case 1:
{
if(GetGlobalNumber("MasterDead") == n1MD)
{
SetGlobalNumber( "MasterDead", nSet2);
SendMessageToPC(GetPartyLeader(), "DEBUG: GLOBAL NUMBER NOW SET TO 2");
}
else
{
}
}break;

case 2:
{
if(GetGlobalNumber("MasterDead") == n2MD)
{
SetGlobalNumber( "MasterDead", nSet3);
SendMessageToPC(GetPartyLeader(), "DEBUG: GLOBAL NUMBER NOW SET TO 3");
}
else
{
}
}break;

case 3:
{
if(GetGlobalNumber("MasterDead") == n3MD)
{
SetGlobalNumber( "MasterDead", nSet4);
SendMessageToPC(GetPartyLeader(), "DEBUG: GLOBAL NUMBER NOW SET TO 4");
}
else
{
}
}break;

case 4:
{
if(GetGlobalNumber("MasterDead") == n4MD)
{
SetGlobalNumber( "MasterDead", nSet5);
SendMessageToPC(GetPartyLeader(), "DEBUG: GLOBAL NUMBER NOW SET TO 5!");
}
else
{
}
}break;

case 5:
{
if(GetGlobalNumber("MasterDead") == n5MD)
{
float x=0.98956f;  
float y=-0.68433f;
float z=0.00f;
float r=118.35471f;
vector vecNPC=Vector(x,y,z);
location locNPC=Location(vecNPC, r);
object oNPC=CreateObject(OBJECT_TYPE_CREATURE,"atton",locNPC);
SendMessageToPC(GetPartyLeader(), "DEBUG: SPAWN ATTON");
}
else
{
}
}break;
}
}
}
}

Thanks.

Link to comment
Share on other sites

- I don't think you need any include scripts since you're not using their functions.

 

- What spawn-in flags are you setting in your OnSpawn script? If you're only using the OnDeath event, then you can remove the if(nUser == 1006)) block (which appears to be part of a Talk-Fight-Talk sequence).

 

- It appears this while-loop should probably have a closing brace that comes before you do anything globals.

 

- I think you're using GetScriptParameter(x) when you should just use x. EGetScriptParameter retrieves the P1..P5 parameters as set in DLGEditor for a dialog-called script. Since (I believe) the script you listed is a custom UserEvent script, there will be no script parameters to retrieve. Even if there were parameters to retrieve, you can't retrieve parameter 0 (only 1 to 5).

 

 

- In the code that deals with globals, you can probably simplify things quite a bit by querying the global value, incrementing it, and writing it back immediately. The debug string can be generated dynamically.

 

- There's a couple of syntax issues especially with braces (eg. you don't need braces within a case: element) though the compiler might allow it, it will make your own debugging more confusing.

 

Here's what I think your UserDefined script could appear like this:

/* di_userdef.nss
 UserDefined script for the NPCs
  only OnDeath event is defined... in the NPCs' OnSpawn script,
  the GN_SetSpawnInCondition(SW_FLAG_EVENT_ON_DEATH); should 
  be uncommented */
void main()
{
   int nCurrentHP;
   int nUser = GetUserDefinedEventNumber();
   if(nUser == 1007) // DATH
   {
object oItem = GetFirstItemInInventory(OBJECT_SELF);
while (GetIsObjectValid(oItem)) 
       {
    SetPlotFlag(oItem, FALSE);
    DestroyObject(oItem, 0.0);
    oItem = GetNextItemInInventory(OBJECT_SELF);
}

      DelayCommand(1.0, DestroyObject(OBJECT_SELF));

      int nQMD = GetGlobalNumber("MasterDead");
      nQMD++;  
      SetGlobalNumber( "MasterDead",  nQMD ); 
      string strDebug="DEBUG: GLOBAL NUMBER NOW SET TO "+IntToString(nQMD);
      SendMessageToPC(GetPartyLeader(), strDebug);

      if (nQMD==5) 
      {  
   float x=0.98956f;  
   float y=-0.68433f;
   float z=0.00f;
   float r=118.35471f;
   vector vecNPC=Vector(x,y,z);
   location locNPC=Location(vecNPC, r);
   object oNPC=CreateObject(OBJECT_TYPE_CREATURE,"atton",locNPC);
   SendMessageToPC(GetPartyLeader(), "DEBUG: SPAWN ATTON");
      }
  }
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...