Need a small fix on this script

Moderator: Event DM

Post Reply
User avatar
4x4_Ender
Sage
Posts: 1782
Joined: Wed Jun 04, 2003 11:26 pm
Location: Woodbury, MN (GMT -6)
Contact:

Need a small fix on this script

Post by 4x4_Ender » Tue Nov 09, 2004 3:38 am

For some reason, the nested loop on this script isnt working. Instead of creating only the objects under the conditions of the appropriate if statement, it creates ALL of the objects under all if statements (all 4 of them).

Code: Select all

void main()
{
    int nXP = GetXP(GetPCSpeaker());
    int nObjectType = OBJECT_TYPE_CREATURE;
    string strguardm = "amm_guardmale";
    string strguardf = "amm_guardfemale";
    string strhigrdm = "amm_higrdmale";
    string strhigrdf = "amm_higrdfemale";
    location locLocation = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAppearAnimation = TRUE;

    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3),locLocation);

    if(0 <= nXP < 10000)
        {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
        }
            if(10000 <= nXP < 45000)
                {
                CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
                CreateObject(nObjectType, strguardf, locLocation, bUseAppearAnimation);
                }
                    if(45000 <= nXP < 105000)
                        {
                        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
                        }
    else
        {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strhigrdf, locLocation, bUseAppearAnimation);
        }
}
"Many make a trade of delusions and false miracles, deceiving the stupid multitude." -Leonardo Da Vinci
Eliyas
Squire of Babble
Posts: 46
Joined: Tue May 25, 2004 3:40 am
Location: GMT -4

Post by Eliyas » Tue Nov 09, 2004 4:06 am

I think the 2nd and 3rd ifs should be else if statements. Also, I don't know if the 0 <= x < 10000 syntax works, and it would be more clear if you made it (x >= 0) AND (x < 10000), and might fix the problem.
User avatar
Jonezie
Team Member; Retired with Honors
Posts: 3905
Joined: Wed Jun 09, 2004 7:05 am
Location: Melbourne (GMT +10)

Post by Jonezie » Tue Nov 09, 2004 4:13 am

The 'else' statement you've used at the end only works off of the preceeding (3rd) 'if' statement. All of the other 'if's are independant of each other.

Have you tried it with characters of differant experience?
The way I read it, if youre 0-10000, it should spawn 3 creature - strguardm from the first 'if', and 2 higuards from the 'else'

10000 - 45000: All 4. 2 from the 2nd 'if' and 2 from the 'else'

45000 - 105000: just 1, from the third 'if'

Greater than 105000 - the two from the 'else'

I think if you change the 'else' to:

If (nXP>105000) {...

It should work the way you're wanting.
User avatar
4x4_Ender
Sage
Posts: 1782
Joined: Wed Jun 04, 2003 11:26 pm
Location: Woodbury, MN (GMT -6)
Contact:

Post by 4x4_Ender » Tue Nov 09, 2004 5:36 am

what is the symbol used for the "AND" function? I tried | and || but they dont seem to combine the two conditions.
"Many make a trade of delusions and false miracles, deceiving the stupid multitude." -Leonardo Da Vinci
User avatar
Tissa
Team Member; Retired with Honors
Posts: 623
Joined: Mon Sep 13, 2004 6:19 am
Location: Southern California
Contact:

Post by Tissa » Tue Nov 09, 2004 5:59 am

4x4_Ender wrote:what is the symbol used for the "AND" function? I tried | and || but they dont seem to combine the two conditions.
AND is &&

as a note:
"&&" is Short circuit logical AND
"&" is bitwise AND
"||" is Short circuit logical OR
and "|" is bitwise OR
I will not kill or hurt any living creature needlessly, nor destroy any beautiful thing,
but will strive to save and comfort all gentle life, and guard and protect all natural beauty that surrounds me
User avatar
Jonezie
Team Member; Retired with Honors
Posts: 3905
Joined: Wed Jun 09, 2004 7:05 am
Location: Melbourne (GMT +10)

Post by Jonezie » Tue Nov 09, 2004 6:00 am

Try this, it should work, although there's probably a more elegant way of doing it. I think it was the (x < nXP < y) notation that was causing problems.

Code: Select all

void main()
{
    int nXP = GetXP(GetPCSpeaker());
    int nObjectType = OBJECT_TYPE_CREATURE;
    string strguardm = "amm_guardmale";
    string strguardf = "amm_guardfemale";
    string strhigrdm = "amm_higrdmale";
    string strhigrdf = "amm_higrdfemale";
    location locLocation = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAppearAnimation = TRUE;

    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3),locLocation);

    if(nXP < 10000)
        {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
        }
    else {  if(nXP < 45000)
            {
            CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
            CreateObject(nObjectType, strguardf, locLocation, bUseAppearAnimation);
            }
            else{   if(nXP < 105000)
                    {
                    CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
                    }
                    }
                    }
     if(nXP >= 105000)
        {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strhigrdf, locLocation, bUseAppearAnimation);
        }
}
User avatar
Tissa
Team Member; Retired with Honors
Posts: 623
Joined: Mon Sep 13, 2004 6:19 am
Location: Southern California
Contact:

Post by Tissa » Tue Nov 09, 2004 6:50 am

I think this is what you want: (just fixing the if statements)

Code: Select all

void main()
{
    int nXP = GetXP(GetPCSpeaker());
    int nObjectType = OBJECT_TYPE_CREATURE;
    string strguardm = "amm_guardmale";
    string strguardf = "amm_guardfemale";
    string strhigrdm = "amm_higrdmale";
    string strhigrdf = "amm_higrdfemale";
    location locLocation = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAppearAnimation = TRUE;

    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3), locLocation);

    if (nXP < 10000)
    {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
    }
    else if (nXP < 45000)
    {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strguardf, locLocation, bUseAppearAnimation);
    }
    else if (nXP < 105000)
    {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
    }
    else
    {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strhigrdf, locLocation, bUseAppearAnimation);
    }
}
another way to write it:

Code: Select all

void main()
{
    int iXP = GetXP(GetPCSpeaker());
    int iType = OBJECT_TYPE_CREATURE;
    location locSpawn = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAnimation = TRUE;

    effect eMonster = EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eMonster, locSpawn);

    if (iXP < 10000)
    {
        CreateObject(iType, "amm_guardmale", locSpawn, bUseAnimation);
    }
    else if (iXP < 45000)
    {
        CreateObject(iType, "amm_guardmale", locSpawn, bUseAnimation);
        CreateObject(iType, "amm_guardfemale", locSpawn, bUseAnimation);
    }
    else if (iXP < 105000)
    {
        CreateObject(iType, "amm_higrdmale", locSpawn, bUseAnimation);
    }
    else
    {
        CreateObject(iType, "amm_higrdmale", locSpawn, bUseAnimation);
        CreateObject(iType, "amm_higrdfemale", locSpawn, bUseAnimation);
    }
}
somewhat following the Avlis coding standard post viewtopic.php?t=7739 using a prefix of "i" for integer variables.
I will not kill or hurt any living creature needlessly, nor destroy any beautiful thing,
but will strive to save and comfort all gentle life, and guard and protect all natural beauty that surrounds me
User avatar
Jonezie
Team Member; Retired with Honors
Posts: 3905
Joined: Wed Jun 09, 2004 7:05 am
Location: Melbourne (GMT +10)

Post by Jonezie » Tue Nov 09, 2004 7:17 am

Heh....much nicer to look at then mine, too.
User avatar
4x4_Ender
Sage
Posts: 1782
Joined: Wed Jun 04, 2003 11:26 pm
Location: Woodbury, MN (GMT -6)
Contact:

Post by 4x4_Ender » Tue Nov 09, 2004 2:54 pm

Thanks guys. 8)
"Many make a trade of delusions and false miracles, deceiving the stupid multitude." -Leonardo Da Vinci
Post Reply