Author Topic: How to merge similar scripts or use them both at the same time?  (Read 380 times)

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0


               I am using this wonderful scripting package that spawns random commoners with random clothing with randomized one liners for populating cities:
Commoner Package 1.2 by EntropyDecay
My problem is that I wanted the ladies to be dressed in more colorful clothing so I altered and saved the scripts a little and then tried to run both scripts together by making a third heartbeat script that calls on to execute both scripts! I renamed the second script's waypoints so each gender will have their own waypoints to use.  But the problem is that the second script which is supposed to spawn the ladies is also spawning only gents!  If I use the lady script only then only ladies will spawn and I noticed that they will spawn on their 'lady' waypoints but get confused and also use the 'gent' waypoints to disappear!  I just hope this all makes sense!  If someone has used these scripts and done something similar to what I am trying to do then I would greatly appreciate their help!  Thanks in advance!

I know FesterPot has used these scripts extensively in his module Almraiven, (it's a wonderful module) and done some really fun things with them, so if you, Fester Pot, know an easy answer to this then do tell me and thank you!!
               
               

               


                     Modifié par vivienne.l, 02 avril 2012 - 02:36 .
                     
                  


            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #1 on: April 06, 2012, 08:49:24 pm »


               I think I've figured out the problem; since my altered script is very similar to the main script the spawned commoners are getting confused and sharing the waypoints! And the reason for only gents being spawned is that only the first script is being fired, if I run the lady script first only the lady script fires!  I'll just have to find another way I suppose...
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #2 on: April 08, 2012, 05:48:10 am »


               You need to post your script. EntropyDecay's scripts, I found, are wonky and confusing at best. What Almraiven uses is a modified version of the main script.

It's possible to do what you want with just one script, but you'll need to check the NPC's sex before dressing them up - unless you don't mind using clothing for the females that the men can wear. '<img'>

A variable within the script needs to be set based on the NPCs sex.

string sResRefClothing = "res_ref_here";   //ResRef-beginning of clothing
string sResRefClothingFemale = "res_ref_here";   //ResRef-beginning of clothing for Females

int nTypesOfClothing = 20;               //Number of different clothings
int nTypesOfClothingFemale = 20;               //Number of different clothings


So the above is an example.

In the same script, you'd want to find:

    //Initialization
    //Don't change anything in this block or the script package
    //won't function properly!
    SetLocalString(oArea, "sResRefClothing", sResRefClothing);
    SetLocalInt(oArea, "nTypesOfClothing", nTypesOfClothing);


Keep in mind, there are other Ints and Strings nestled in the above, I've just cut out what you don't need.

And also add the female portion.

    //Initialization
    //Don't change anything in this block or the script package
    //won't function properly!
    SetLocalString(oArea, "sResRefClothing", sResRefClothing);
    SetLocalString(oArea, "sResRefClothingFemale", sResRefClothingFemale);


In the same script, find:

for (i=1; i <= nSpawn; i++)
      {
        float fSpawnDelay = IntToFloat(Random(nSpawnInterval))/10 + ((IntToFloat(nSpawnInterval)/10) * (i-1));
        DelayCommand(fSpawnDelay, ExecuteScript("???", OBJECT_SELF));
      }


??? - I can't recall the name of the default script. This is what you want to open.

Find:

if (Random(100)+1 <= nClothingRandom)
    {
      sZero="00";
      nRandom = Random(nTypesOfClothing)+1;
      if (nRandom>9) {sZero="0";}
      if (nRandom>99) {sZero="";}
      object oClothing = CreateItemOnObject(sResRefClothing+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));
      object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");


Add:

if (Random(100)+1 <= nClothingRandom)
    {
      sZero="00";
      nRandom = Random(nTypesOfClothing)+1;
      if (nRandom>9) {sZero="0";}
      if (nRandom>99) {sZero="";}
      // CHECK FOR MALE VS. FEMALE
      if (GetGender(OBJECT_SELF) == MALE)
     {
      object oClothing = CreateItemOnObject(sResRefClothing+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));

      object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

     }

     else
    { 
      object oClothing = CreateItemOnObject(sResRefClothingFemale+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));


      object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

    }


Untested.

FP!
               
               

               


                     Modifié par Fester Pot, 08 avril 2012 - 05:13 .
                     
                  


            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #3 on: April 08, 2012, 08:34:49 pm »


               FesterPot, thanks for answering me, I was so frustrated and you're right about the original scripts being wonky! And this is exactly what I mean that I want the women to be dressed differently from the males and have made the clothing male only and female only but when I tested the script before, the females were able to wear the male clothing but it looked weird (some of the male clothing in CEP becomes a topless version if a female puts it on and I don't want that as I'm making my module primarily for my sons); I will try out the changes above and play around and see if it does what I want and will keep my results posted! Thanks again!
               
               

               
            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #4 on: May 14, 2012, 06:33:22 pm »


               I know it has been a while but ...the alteration for the script called commoner_main worked fine but the the other alteration in the script called commoner_creator gives an error but I can't seem to fix it.  Here is the altered script:

//::///////////////////////////////////////////////
//:: commoner_creator.nss
//:://////////////////////////////////////////////
/*
     Reads the various needed variables, creates
     a NPC and sends it to a random waypoint.
*/
//:://////////////////////////////////////////////
//:: Created By: EntropyDecay
//:: Created On: May 2003
//:: Altered to accomodate ladies with help from Fester Pot!
//:://////////////////////////////////////////////

void main()
{
  object oArea = GetArea(OBJECT_SELF);
  object oFirstPlayerInArea = GetLocalObject(oArea, "oFirstPlayerInArea");

  int nWeather = GetLocalInt(oArea, "nWeather");
  string sCommonerName = GetLocalString(oArea, "sCommonerName");
  string sResRefBody = GetLocalString(oArea, "sResRefBody");
  int nTypesOfCommoner = GetLocalInt(oArea, "nTypesOfCommoner");
  string sResRefClothing = GetLocalString(oArea, "sResRefClothing");
  int nTypesOfClothing = GetLocalInt(oArea, "nTypesOfClothing");
  int nClothingRandom = GetLocalInt(oArea, "nClothingRandom");
  int nCommonerCarry = GetLocalInt(oArea, "nCommonerCarry");
  int nCommonerTorchOnlyByNight = GetLocalInt(oArea, "nCommonerTorchOnlyByNight");
  int nCommonerTorch = GetLocalInt(oArea, "nCommonerTorch");
  int nWalkWayPoints = GetLocalInt(oArea, "nWalkWayPoints");
  int nDialogLines = GetLocalInt(oArea, "nDialogLines");
  int nWalkType = GetLocalInt(oArea, "nWalkType");
  int nRandom;
  string sZero;

  sZero="00";
  nRandom = Random(nTypesOfCommoner)+1;
  if (nRandom>9) {sZero="0";}
  if (nRandom>99) {sZero="";}
  string sSpawn = sResRefBody + sZero + IntToString(nRandom);

  object oStartWayPoint = GetNearestObjectByTag("NW_COMMONER_WALKTO1", oFirstPlayerInArea, Random(nWalkWayPoints)+1);
  object oCommoner = CreateObject(OBJECT_TYPE_CREATURE, sSpawn, GetLocation(oStartWayPoint));
  object oWalkTarget = GetNearestObjectByTag("NW_COMMONER_WALKTO1", oStartWayPoint, Random(nWalkWayPoints-1)+1);
  SetLocalObject(oCommoner, "oWalkTarget", oWalkTarget);

  SetLocalInt(oCommoner, "ambience_dialog", Random(nDialogLines)+1);
  AssignCommand(oCommoner, ClearAllActions());
  if (GetName(oCommoner)==sCommonerName)
  {
    if (Random(100)+1 <= nClothingRandom)
    {
      sZero="00";
      nRandom = Random(nTypesOfClothing)+1;
      if (nRandom>9) {sZero="0";}
      if (nRandom>99) {sZero="";}
      // CHECK FOR MALE VS. FEMALE
      if (GetGender(OBJECT_SELF) == MALE)
     {
      object oClothing = CreateItemOnObject(sResRefClothing+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));

      //object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

     }

     else
    {
      object oClothing = CreateItemOnObject(sResRefClothingFemale+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));


      //object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

    }
    if (Random(100)+1 > nCommonerCarry)
    {
      DestroyObject(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oCommoner));
      DestroyObject(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oCommoner));
    }
  }

  if (nCommonerTorchOnlyByNight==FALSE && Random(100)+1 <= nCommonerTorch)
  {
    object oTorch = CreateItemOnObject("NW_IT_TORCH001", oCommoner);
    AssignCommand(oCommoner, ActionEquipItem(oTorch, INVENTORY_SLOT_LEFTHAND));
  }
  else if (GetIsNight() && Random(100)+1 <= nCommonerTorch)
  {
    object oTorch = CreateItemOnObject("NW_IT_TORCH001", oCommoner);
    AssignCommand(oCommoner, ActionEquipItem(oTorch, INVENTORY_SLOT_LEFTHAND));
  }

  AssignCommand(oCommoner, ActionForceMoveToObject(oWalkTarget, nWalkType, 0.4, 60.0));
  AssignCommand(oCommoner, ActionDoCommand(DestroyObject(OBJECT_SELF, 0.1)));
}
}

The line I colored red is showing the error.
Thanks for the help in advance!
               
               

               


                     Modifié par vivienne.l, 14 mai 2012 - 05:34 .
                     
                  


            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #5 on: May 14, 2012, 09:31:16 pm »


               I think you want to use oCommoner not OBJECT_SELF in the gender test.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #6 on: May 14, 2012, 09:46:03 pm »


               

meaglyn wrote...

I think you want to use oCommoner not OBJECT_SELF in the gender test.



You are most likely correct.  That however would not throw a compile error.   It looks like the problem is that there is no constant named MALE it should be GENDER_MALE
               
               

               
            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #7 on: May 14, 2012, 11:22:18 pm »


               Thanks Meaglyn and Lightfoot, I'll try your suggestions and see how it works and then post here!
               
               

               
            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #8 on: May 15, 2012, 07:50:24 am »


               This is the fixed version of the script and it is giving no errors; I'm still going to need to test it in the module and will keeep the results posted. I have added the green colored line and fixed the red line:


//::///////////////////////////////////////////////
//:: commoner_creator.nss
//:://////////////////////////////////////////////
/*
     Reads the various needed variables, creates
     a NPC and sends it to a random waypoint.
*/
//:://////////////////////////////////////////////
//:: Created By: EntropyDecay
//:: Created On: May 2003
//:: Altered to accomodate ladies with help from Fester Pot!
//:://////////////////////////////////////////////

void main()
{
  object oArea = GetArea(OBJECT_SELF);
  object oFirstPlayerInArea = GetLocalObject(oArea, "oFirstPlayerInArea");

  int nWeather = GetLocalInt(oArea, "nWeather");
  string sCommonerName = GetLocalString(oArea, "sCommonerName");
  string sResRefBody = GetLocalString(oArea, "sResRefBody");
  int nTypesOfCommoner = GetLocalInt(oArea, "nTypesOfCommoner");
  string sResRefClothing = GetLocalString(oArea, "sResRefClothing");
  string sResRefClothingFemale = GetLocalString(oArea, "sResRefClothingFemale");
  int nTypesOfClothing = GetLocalInt(oArea, "nTypesOfClothing");
  int nClothingRandom = GetLocalInt(oArea, "nClothingRandom");
  int nCommonerCarry = GetLocalInt(oArea, "nCommonerCarry");
  int nCommonerTorchOnlyByNight = GetLocalInt(oArea, "nCommonerTorchOnlyByNight");
  int nCommonerTorch = GetLocalInt(oArea, "nCommonerTorch");
  int nWalkWayPoints = GetLocalInt(oArea, "nWalkWayPoints");
  int nDialogLines = GetLocalInt(oArea, "nDialogLines");
  int nWalkType = GetLocalInt(oArea, "nWalkType");
  int nRandom;
  string sZero;

  sZero="00";
  nRandom = Random(nTypesOfCommoner)+1;
  if (nRandom>9) {sZero="0";}
  if (nRandom>99) {sZero="";}
  string sSpawn = sResRefBody + sZero + IntToString(nRandom);

  object oStartWayPoint = GetNearestObjectByTag("NW_COMMONER_WALKTO1", oFirstPlayerInArea, Random(nWalkWayPoints)+1);
  object oCommoner = CreateObject(OBJECT_TYPE_CREATURE, sSpawn, GetLocation(oStartWayPoint));
  object oWalkTarget = GetNearestObjectByTag("NW_COMMONER_WALKTO1", oStartWayPoint, Random(nWalkWayPoints-1)+1);
  SetLocalObject(oCommoner, "oWalkTarget", oWalkTarget);

  SetLocalInt(oCommoner, "ambience_dialog", Random(nDialogLines)+1);
  AssignCommand(oCommoner, ClearAllActions());
  if (GetName(oCommoner)==sCommonerName)
  {
    if (Random(100)+1 <= nClothingRandom)
    {
      sZero="00";
      nRandom = Random(nTypesOfClothing)+1;
      if (nRandom>9) {sZero="0";}
      if (nRandom>99) {sZero="";}
      // CHECK FOR MALE VS. FEMALE
      if (GetGender(OBJECT_SELF) == GENDER_MALE)
     {
      object oClothing = CreateItemOnObject(sResRefClothing+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));

      //object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

     }

     else
    {
      object oClothing = CreateItemOnObject(sResRefClothingFemale+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));


      //object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

    }
    if (Random(100)+1 > nCommonerCarry)
    {
      DestroyObject(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oCommoner));
      DestroyObject(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oCommoner));
    }
  }

  if (nCommonerTorchOnlyByNight==FALSE && Random(100)+1 <= nCommonerTorch)
  {
    object oTorch = CreateItemOnObject("NW_IT_TORCH001", oCommoner);
    AssignCommand(oCommoner, ActionEquipItem(oTorch, INVENTORY_SLOT_LEFTHAND));
  }
  else if (GetIsNight() && Random(100)+1 <= nCommonerTorch)
  {
    object oTorch = CreateItemOnObject("NW_IT_TORCH001", oCommoner);
    AssignCommand(oCommoner, ActionEquipItem(oTorch, INVENTORY_SLOT_LEFTHAND));
  }

  AssignCommand(oCommoner, ActionForceMoveToObject(oWalkTarget, nWalkType, 0.4, 60.0));
  AssignCommand(oCommoner, ActionDoCommand(DestroyObject(OBJECT_SELF, 0.1)));
}
}
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #9 on: May 15, 2012, 03:31:32 pm »


               

Lightfoot8 wrote...

You are most likely correct.  That however would not throw a compile error.   It looks like the problem is that there is no constant named MALE it should be GENDER_MALE


Good point...  I think the OP'll want both fixes. 
               
               

               
            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #10 on: November 03, 2012, 07:21:43 pm »


               I know this was ages ago, but I've finally tested these scripts and it's still a little wonky as the gents are also wearing the ladies' clothes...for some reason the part of the script to dress the gents in their own clothing is not firing... oh well, I'll keep tweaking the scripts and post here if it gets fixed!
               
               

               
            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
How to merge similar scripts or use them both at the same time?
« Reply #11 on: November 03, 2012, 07:38:07 pm »


               Sweet Success, finally with help from Fester Pot, Meaglyn and Lightfoot!  Thanks!!
*note: OBJECT_SELF had to be changed to oCommoner like Meaglyn said!



//::///////////////////////////////////////////////
//:: commoner_creator.nss
//:://////////////////////////////////////////////
/*
     Reads the various needed variables, creates
     a NPC and sends it to a random waypoint.
*/
//:://////////////////////////////////////////////
//:: Created By: EntropyDecay
//:: Created On: May 2003
//:: Altered to accomodate ladies with help from Fester Pot, Meaglyn and Lightfoot!  Thanks
//:://////////////////////////////////////////////

void main()
{
  object oArea = GetArea(OBJECT_SELF);
  object oFirstPlayerInArea = GetLocalObject(oArea, "oFirstPlayerInArea");

  int nWeather = GetLocalInt(oArea, "nWeather");
  string sCommonerName = GetLocalString(oArea, "sCommonerName");
  string sResRefBody = GetLocalString(oArea, "sResRefBody");
  int nTypesOfCommoner = GetLocalInt(oArea, "nTypesOfCommoner");
  string sResRefClothing = GetLocalString(oArea, "sResRefClothing");
  string sResRefClothingFemale = GetLocalString(oArea, "sResRefClothingFemale");
  int nTypesOfClothing = GetLocalInt(oArea, "nTypesOfClothing");
  int nClothingRandom = GetLocalInt(oArea, "nClothingRandom");
  int nCommonerCarry = GetLocalInt(oArea, "nCommonerCarry");
  int nCommonerTorchOnlyByNight = GetLocalInt(oArea, "nCommonerTorchOnlyByNight");
  int nCommonerTorch = GetLocalInt(oArea, "nCommonerTorch");
  int nWalkWayPoints = GetLocalInt(oArea, "nWalkWayPoints");
  int nDialogLines = GetLocalInt(oArea, "nDialogLines");
  int nWalkType = GetLocalInt(oArea, "nWalkType");
  int nRandom;
  string sZero;

  sZero="00";
  nRandom = Random(nTypesOfCommoner)+1;
  if (nRandom>9) {sZero="0";}
  if (nRandom>99) {sZero="";}
  string sSpawn = sResRefBody + sZero + IntToString(nRandom);

  object oStartWayPoint = GetNearestObjectByTag("NW_COMMONER_WALKTO", oFirstPlayerInArea, Random(nWalkWayPoints)+1);
  object oCommoner = CreateObject(OBJECT_TYPE_CREATURE, sSpawn, GetLocation(oStartWayPoint));
  object oWalkTarget = GetNearestObjectByTag("NW_COMMONER_WALKTO", oStartWayPoint, Random(nWalkWayPoints-1)+1);
  SetLocalObject(oCommoner, "oWalkTarget", oWalkTarget);

  SetLocalInt(oCommoner, "ambience_dialog", Random(nDialogLines)+1);
  AssignCommand(oCommoner, ClearAllActions());
  if (GetName(oCommoner)==sCommonerName)
  {
    if (Random(100)+1 <= nClothingRandom)
    {
      sZero="00";
      nRandom = Random(nTypesOfClothing)+1;
      if (nRandom>9) {sZero="0";}
      if (nRandom>99) {sZero="";}
      // CHECK FOR MALE VS. FEMALE
      if (GetGender(oCommoner) == GENDER_MALE)
     {
      object oClothing = CreateItemOnObject(sResRefClothing+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));

      //object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

     }

     else
    {
      object oClothing = CreateItemOnObject(sResRefClothingFemale+sZero+IntToString(nRandom), oCommoner);
      AssignCommand(oCommoner, ActionEquipItem(oClothing, INVENTORY_SLOT_CHEST));


      //object oUmbrella=GetItemPossessedBy(OBJECT_SELF, "umbrella");

    }
    if (Random(100)+1 > nCommonerCarry)
    {
      DestroyObject(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oCommoner));
      DestroyObject(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oCommoner));
    }
  }

  if (nCommonerTorchOnlyByNight==FALSE && Random(100)+1 <= nCommonerTorch)
  {
    object oTorch = CreateItemOnObject("NW_IT_TORCH001", oCommoner);
    AssignCommand(oCommoner, ActionEquipItem(oTorch, INVENTORY_SLOT_LEFTHAND));
  }
  else if (GetIsNight() && Random(100)+1 <= nCommonerTorch)
  {
    object oTorch = CreateItemOnObject("NW_IT_TORCH001", oCommoner);
    AssignCommand(oCommoner, ActionEquipItem(oTorch, INVENTORY_SLOT_LEFTHAND));
  }

  AssignCommand(oCommoner, ActionForceMoveToObject(oWalkTarget, nWalkType, 0.4, 60.0));
  AssignCommand(oCommoner, ActionDoCommand(DestroyObject(OBJECT_SELF, 0.1)));
}
}
               
               

               


                     Modifié par vivienne.l, 03 novembre 2012 - 07:41 .