Jump to content

Home

Spawning a person once.


Master Zionosis

Recommended Posts

hi guys and gals, im having a bit of a problem, i need to spawn a person once after a differant script has been fired using another script and if i attached it to a door transition surely it would keep firing again and again becuase the script is still attached to the door transition, please can someone help me because this is a real pain and i don't know what to do.

Link to comment
Share on other sites

hi guys and gals, im having a bit of a problem, i need to spawn a person once after a differant script has been fired using another script and if i attached it to a door transition surely it would keep firing again and again becuase the script is still attached to the door transition, please can someone help me because this is a real pain and i don't know what to do.

 

You can set a Local boolean on the door when the script has run once, and then check at the start of the script if that variable has been set before proceeding. That way you can block the code from being run more than once. Like:

 

void main() {
   [color=PaleGreen]// Abort script if it has already run.[/color]
   if (GetLocalBoolean(OBJECT_SELF, 40))
       return;

   // ... do what the script should do here ... 

   [color=PaleGreen]// Set that the script has run[/color]
   SetLocalBoolean(OBJECT_SELF, 40, TRUE);

}

Link to comment
Share on other sites

Exelant thanks stoffe, but how do i make it so that the script connected to the door only runs after another particular script has fired?

 

You can set a global variable in the other script, and then check if that global variable is set in the door script. Add a new global boolean variable to globalcat.2da, then use it with the SetGlobalBoolean() and GetGlobalBoolean() functions to set and check for it. The text in the name column in globalcat.2da is what you pass as the first parameter to those two functions.

Link to comment
Share on other sites

I sort of know what you mean, i have opened the globalcat.2da file and seen the booloean's but i dont know how the script layout is supposed to look, could you please post what the script is supposed to look like, lets just say the boolean is "DAN_ZAEN_DOOR_SPAWN".

 

Since I don't know what else your scripts are supposed to be doing, insert that code where the yellow lines are in the below examples:

 

void main() {
   [color=Yellow]// ... do what the script should do here ...[/color]

   [color=PaleGreen]// ST: Set global indicating script has run... [/color]
   SetGlobalBoolean("DAN_ZAEN_DOOR_SPAWN", TRUE);
}

 

void main() {
   [color=PaleGreen]// ST: Abort if the other script has not run yet.[/color]
   if (!GetGlobalBoolean("DAN_ZAEN_DOOR_SPAWN")) 
       return;

   [color=PaleGreen]// ST: Abort this script if it has already run.[/color]
   if (GetLocalBoolean(OBJECT_SELF, 40))
       return;

   [color=Yellow]// ... do what the script should do here ... [/color]

   [color=PaleGreen]// ST: Set that the script has run[/color]
   SetLocalBoolean(OBJECT_SELF, 40, TRUE);
}

 

Lines in green are comments describing what the line below does.

Link to comment
Share on other sites

Brilliant thanks Stoffe, but i just remembered another key point, i also only want the door script to fire if you havn't allready recruited Zaen.

 

The easiest way of checking that is probably to make another global boolean for it, which you set in the script that recruits your NPC. Then you check for that boolean value in a similar manner as above. (Just remember to add the new global boolean to globalcat.2da as well, or the game won't know about it.)

Link to comment
Share on other sites

im sorry stoffe but as im a beginer with scripts could you please demonstrait the scripts that i need to use. i need the scripts that tells to spawn a person but not to fire if they have allready been recruited. Thanks Stoffe, forgive my lack of understanding.

 

Please post the script source code you use for

  1. Recruiting your npc (i.e. adding it to the player's group)
  2. The door script
  3. The script that "must be run before the door script may trigger"

 

That would make it easier to try to give meaningful examples rather than attempting to guess what it is you are trying to do. :)

Link to comment
Share on other sites

Please post the script source code you use for
  1. Recruiting your npc (i.e. adding it to the player's group)
  2. The door script
  3. The script that "must be run before the door script may trigger"

 

That would make it easier to try to give meaningful examples rather than attempting to guess what it is you are trying to do. :)

 

Ok, here is the script for recruiting Zaen:

 

void main()
{
  RemoveAvailableNPC(7);
  AddAvailableNPCByTemplate(7, "p_zaenbenax");
  SetGlobalNumber("RH_RECRUIT", 7);
}

 

 

And here is the script for the door:

 

void main() 
{

float x=16.67f;  
float y=154.27f;
float z=7.28f;
float r=0.0f;
vector vecNPC=Vector(x,y,z);
location locNPC=Location(vecNPC, r);
object oNPC=GetObjectByTag("g_zaenbenax2");
object oTarget=CreateObjec (OBJECT_TYPE_CREATURE,"g_zaenbenax2",locNPC);
object oPC=GetFirstPC();
AssignCommand(oNPC,ActionMoveToObject(oPC));
AssignCommand(oNPC,ActionStartConversation(oPC,"enclavezb"));
}

 

And here is the script that has to be run before the door script can trigger:

 

void main() {
 object oNPC=GetObjectByTag("g_zaenbenax");
 ChangeToStandardFaction(oNPC, 1);

// and if there are any thugs to fight...
 object oThug1 = GetObjectByTag("g_zaenbenax");

 ChangeToStandardFaction(oThug1, 1);
}

 

I hope thats correct.

Link to comment
Share on other sites

Ok, here is the script (snip)

 

 

The recruit script:

void main() {
   RemoveAvailableNPC(7);
   AddAvailableNPCByTemplate(7, "p_zaenbenax");
   SetGlobalNumber("RH_RECRUIT", 7);
}

 

You are already setting the global number variable RH_RECRUIT to 7 here, so this may be used to check for if the character has been recruited below, so no further changes to that script should be needed.

 

 

The other script:

void main() {
   object oNPC = GetObjectByTag("g_zaenbenax");
   ChangeToStandardFaction(oNPC, STANDARD_FACTION_HOSTILE_1);

   [color=PaleGreen]// and if there are any thugs to fight...[/color]
   object oThug1 = GetObjectByTag("[color=Yellow]g_zaenbenax[/color]"[color=Red], 1[/color]);
   ChangeToStandardFaction(oThug1, STANDARD_FACTION_HOSTILE_1);

   SetGlobalBoolean("DAN_ZAEN_DOOR_SPAWN", TRUE);
}

 

This script now sets the "DAN_ZAEN_DOOR_SPAWN" global boolean variable when run, which can be checked for in the door script. There is something wrong with this script though, since you essentially do the same thing twice. You change the character with the tag g_zaenbenax to the Hostile faction, but do so twice.

 

If there is more than one character that should become hostile and they have the same tag you need to increase the second parameter of GetObjectByTag() like I've done above. If the second character has a different tag you'll need to set that instead of the one marked yellow above and remove the ", 1" part marked in red again.

 

 

The door script:

void main() {
   [color=PaleGreen]// ST: Abort if the other script has not run yet, if the script has 
   //     already run or if the character has joined the player.[/color]
   if (   !GetGlobalBoolean("DAN_ZAEN_DOOR_SPAWN")
       || (GetGlobalNumber("RH_RECRUIT") > 6) 
       ||  GetLocalBoolean(OBJECT_SELF, 40))
   {
       return;
   }

   [color=PaleGreen]// ST: Spawn character from g_zaenbenax2.utc[/color]
   location locNPC = Location(Vector(16.67, 154.27, 7.28), 0.0);
   object oNPC = CreateObject(OBJECT_TYPE_CREATURE, "g_zaenbenax2", locNPC);
   object oPC = GetFirstPC();

   [color=PaleGreen]// ST: move character towards the main character and start conversation[/color]
   AssignCommand(oNPC, ActionMoveToObject(oPC, FALSE, 2.0));
   AssignCommand(oNPC, ActionStartConversation(oPC, "enclavezb"));

   [color=PaleGreen]// ST: Set that the script has run once.[/color]
   SetLocalBoolean(OBJECT_SELF, 40, TRUE);
}

 

This has now been changed to check if the character is recruited, if the script has already run once or if the script turning NPCs hostile above has not run. If either of these is the case the rest of the script will not run.

 

Aside from that I fixed a mistake where you attempted to get the creature by tag for the oNPC variable before it had been spawned, which shouldn't have worked too well.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...