Author Topic: problem with scripted "random" spawns  (Read 304 times)

Legacy_Monsieur T

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +0/-0
problem with scripted "random" spawns
« on: July 17, 2013, 01:13:09 am »


               Howdy,
When using the BESIE system to spawn numbers of pre-made commoners/drinkers etc, the spawns very often end up producing 2 or sometimes 3 instances of one creature, even though I have bothered to make a fair amount of blueprints from which the script should choose....

I am hoping that this is due to a Maths Thing in the script, that I have not understood because I can barely add up!

This is the original script, which spawns various races as will be quite evident......


Custom Random Commoner Table for use with the BESIE
Random Encounter Package by Ray Miller
*/
////////////////////////////////////////////////////
void main()
{
int iVarNum = GetLocalInt(OBJECT_SELF, "re_iVarNum");
int END;
int iWeight;
int iCounter1;
int iCounter2;
string sChoice;
object oMod = GetModule();
while(!END)
    {
    sChoice = "";
    switch(iCounter1)
        {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//DO NOT EDIT ABOVE THIS LINE/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CUSTOM ENCOUNTER TABLE BELOW:///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        case 0:sChoice = "mhuman";// Creature tag goes between the " marks.
        iWeight = 10;        // This is the number of times this mob should be considered for the likelyhood of appearing.
        break;
        case 1:sChoice = "fhuman";
        iWeight = 10;
        break;
        case 2:sChoice = "melf";
        iWeight = 8;
        break;
        case 3:sChoice = "felf";
        iWeight = 8;
        break;
        case 4:sChoice = "mhalfelf";
        iWeight = 8;
        break;
        case 5:sChoice = "fhalfelf";
        iWeight = 8;
        break;
        case 6:sChoice = "mdwarf";
        iWeight = 6;
        break;
        case 7:sChoice = "fhalforc";
        iWeight = 1;
        break;
        case 8:sChoice = "mhalfling";
        iWeight = 4;
        break;
        case 9:sChoice = "fhalfling";
        iWeight = 4;
        break;
        case 10:sChoice = "mgnome";
        iWeight = 3;
        break;
        case 11:sChoice = "fgnome";
        iWeight = 2;
        break;
        case 12:sChoice = "mhalforc";
        iWeight = 2;
        break;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//END OF CUSTOM ENCOUNTER TABLE!  DO NOT EDIT BELOW THIS LINE//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        default:END = TRUE;
        break;
        }
    if(GetStringLowerCase(sChoice) != "")
        {
        for(iCounter2 = 1; iCounter2 <= iWeight; iCounter2++)
            {
            SetLocalString(oMod, "re_sCreatureList" + IntToString(iVarNum), sChoice);
            iVarNum++;
            }
        }
    iCounter1++;
    }
SetLocalInt(OBJECT_SELF, "re_iVarNum", iVarNum);
}



And this is the one that I have tried to modify to get a number of differently dressed appearances into a pub.....





COMMONER FACTION MALE MOBILE SOCIAL PHENO DRINKERS
*/
////////////////////////////////////////////////////
void main()
{
int iVarNum = GetLocalInt(OBJECT_SELF, "re_iVarNum");
int END;
int iWeight;
int iCounter1;
int iCounter2;
string sChoice;
object oMod = GetModule();
while(!END)
    {
    sChoice = "";
    switch(iCounter1)
        {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//DO NOT EDIT ABOVE THIS LINE/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CUSTOM ENCOUNTER TABLE BELOW:///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        case 0:sChoice = "pt_drinker100";// Creature resref goes between the " marks.
        iWeight = 1;        // This is the number of times this mob should be considered for the likelyhood of appearing.
        break;
        case 1:sChoice = "pt_drinker101";
        iWeight = 1;
        break;
        case 2:sChoice = "pt_drinker102";
        iWeight = 1;
        break;
        case 3:sChoice = "pt_drinker103";
        iWeight = 1;
        break;
        case 4:sChoice = "pt_drinker104";
        iWeight = 1;
        break;
        case 5:sChoice = "pt_drinker105";
        iWeight = 1;
        break;
        case 6:sChoice = "pt_drinker106";
        iWeight = 1;
        break;
        case 7:sChoice = "pt_drinker107";
        iWeight = 1;
        break;
        case 8:sChoice = "pt_drinker108";
        iWeight = 1;
        break;
        case 9:sChoice = "pt_drinker109";
        iWeight = 1;
        break;
        case 10:sChoice = "pt_drinker110";
        iWeight = 1;
        break;
        case 11:sChoice = "pt_drinker111";
        iWeight = 1;
        break;
        case 12:sChoice = "pt_drinker112";
        iWeight = 1;
        break;
        case 13:sChoice = "pt_drinker113";
        iWeight = 1;
        break;
        case 14:sChoice = "pt_drinker114";
        iWeight = 1;
        break;
        case 15:sChoice = "pt_drinker115";
        iWeight = 1;
        break;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//END OF CUSTOM ENCOUNTER TABLE!  DO NOT EDIT BELOW THIS LINE//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        default:END = TRUE;
        break;
        }
    if(GetStringLowerCase(sChoice) != "")
        {
        for(iCounter2 = 1; iCounter2 <= iWeight; iCounter2++)
            {
            SetLocalString(oMod, "re_sCreatureList" + IntToString(iVarNum), sChoice);
            iVarNum++;
            }
        }
    iCounter1++;
    }
SetLocalInt(OBJECT_SELF, "re_iVarNum", iVarNum);
}


I thought that that setting each instance to 1 would sort things out, but on every spawn I almost always find one or more pairs of "twins", which is hugely annoying!
Any help from the minds out there would be very gratefully received.....
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
problem with scripted "random" spawns
« Reply #1 on: July 17, 2013, 01:46:22 am »


               I'm not familiar with this system, but it looks like it's building a table of creature which is then used
to randomly pull things from. The original table had something like 63 creature to choose from
(although some repeated). Your table has 16, with no repeats. If you are choosing some random
handful of those it's actually pretty likely to get two the same since there is such a small range of choices.  One way to fix it is to make a lot more entries than just the 16. Another, if  you're only choosing a few at at time would be to mark the ones you used on any give spawning and re-roll if you get one you've used.

But this is somewhat speculative since I don't know exactly how the data the script is setting up is being used.

Cheers,
meaglyn
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
problem with scripted "random" spawns
« Reply #2 on: July 19, 2013, 05:05:41 pm »


               The way you have altered iweight to always be 1 this statement will never be false:
 for(iCounter2 = 1; iCounter2 <= iWeight; iCounter2++)