Author Topic: Variables - More then X but less than Y  (Read 529 times)

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Variables - More then X but less than Y
« on: August 01, 2012, 01:33:25 pm »


               I'm trying to design a quasi-skill that will be tracked via an incrementing int on a "database" item for persistency. I would like said skill to have a specific power use from say int 100-200 then switch to a slightly more powerful version from int 200-300, and grow even more powerful from 300-400, and top out at 500 where it would become permanent. This is far beyond my scripting capability any help is appreciated and cookies will be handed out.
               
               

               
            

Legacy_acomputerdood

  • Sr. Member
  • ****
  • Posts: 378
  • Karma: +0/-0
Variables - More then X but less than Y
« Reply #1 on: August 01, 2012, 02:02:34 pm »


               are you looking for:


if( nSkill < 100 ){
     // skill not high enough (under 100)
} else if (nSkill < 200) {
     // specific power (100 - 200)
} else if (nSkill < 300) {
     // slightly more powerful (200 - 300)
} else if (nSkill < 400) {
     // even more powerful (300 - 400)
} else if (nSkill < 500) {
     // i guess even more powerful (400 - 500)
} else {
     // capped out at 500+
}

you could do the same with a switch statement, but i always found if / else to be a little more intuitive for the beginning programmers.

"else if" will evaluate the statement only if the previous statement is false.  that way you can assume when it checks (nSkill < 200) that you're in the 100 - 200 range, since (nSkill < 100) already failed.  this avoids needing the compound checks of if ( (100 < nSkill) && (nSkill < 200) ) and such.

i suggest you check out:
http://www.nwnlexico...estatement.html

and many of the other tutorials in the Lyceum:
http://www.nwnlexico...her.lyceum.html
               
               

               


                     Modifié par acomputerdood, 01 août 2012 - 01:04 .
                     
                  


            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Variables - More then X but less than Y
« Reply #2 on: August 02, 2012, 01:31:58 am »


               This is what I am starting with, I was initially going to have it just 5 stages outright and hand out items according to player level, accomplishements, etc. Then I figured I would pose the question of how to make it a growing "skill" which would gain power over use and experience and eventually end in a permanent weapon enhancement. Thinking about it more today I would also want random chances of failure in lower "levels". Since this is conversation driven off the item itself, on failure it would send a message and decrement the int value so the player in essence is leveling their "skill" of sharpening.

#include "x2_inc_itemprop"

void main()
{
    object oItem;
    itemproperty ipAdd;

    // Get the PC who is in this conversation.
    object oPC = GetPCSpeaker();
    object oDatabase = GetItemPossessedBy(oPC,"Database");
    // If the local int on Database item is Equal to 100.
    if ( GetLocalInt(oDatabase, "sharpening_skill") == 100 )
    {
        // Alter the weapon equipped by the PC.
        oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
        SetPlotFlag(oItem, TRUE);
        SetStolenFlag(oItem, TRUE);
        ipAdd = ItemPropertyKeen();
        IPSafeAddItemProperty(oItem, ipAdd, 600.0);
    }
    // Else, if the local int on Database item is Equal to 200.
    else if ( GetLocalInt(oDatabase, "sharpening_skill") == 200 )
    {
        // Alter the weapon equipped by the PC.
        oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
        SetPlotFlag(oItem, TRUE);
        SetStolenFlag(oItem, TRUE);
        ipAdd = ItemPropertyKeen();
        IPSafeAddItemProperty(oItem, ipAdd, 1200.0);
    }
    // Else, if the local int on Database item is Equal to 300.
    else if ( GetLocalInt(oDatabase, "sharpening_skill") == 300 )
    {
        // Alter the weapon equipped by the PC.
        oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
        SetPlotFlag(oItem, TRUE);
        SetStolenFlag(oItem, TRUE);
        ipAdd = ItemPropertyKeen();
        IPSafeAddItemProperty(oItem, ipAdd, 1800.0);
    }
    // Else, if the local int on Database item is Equal to 400.
    else if ( GetLocalInt(oDatabase, "sharpening_skill") == 400 )
    {
        // Alter the weapon equipped by the PC.
        oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
        SetPlotFlag(oItem, TRUE);
        SetStolenFlag(oItem, TRUE);
        ipAdd = ItemPropertyKeen();
        IPSafeAddItemProperty(oItem, ipAdd, 2400.0);
    }
    // Else, if the local int on Database item is greater than 500.
    else if ( GetLocalInt(oDatabase, "sharpening_skill") > 500 )
    {
        // Alter the weapon equipped by the PC.
        oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
        SetPlotFlag(oItem, TRUE);
        SetStolenFlag(oItem, TRUE);
        ipAdd = ItemPropertyKeen();
        IPSafeAddItemProperty(oItem, ipAdd);
    }
    else
    {
    }
}
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Variables - More then X but less than Y
« Reply #3 on: August 02, 2012, 05:34:09 am »


               Try this.

void main()
{
    object oItem;
    itemproperty ipAdd;

    // Get the PC who is in this conversation.
    object oPC = GetPCSpeaker();
    object oDatabase = GetItemPossessedBy(oPC,"Database");

   // Get the skill on the DB item.
   int nSkill = GetLocalInt(oDatabase, "sharpening_skill");

   // Make sure the skill is greater then 0. (sanity check)
   if (nSkill)
   {

     // We at least have a skill,
     //Take care of the things that always happen at this point.
     oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
     SetPlotFlag(oItem, TRUE);
     SetStolenFlag(oItem, TRUE);
     ipAdd = ItemPropertyKeen();

     // calculate the duration
     float nDur;
     if (nSkill > 500)nDur = 0.0;
     else nDur = (nSkill / 100) * 600.0;

     // Add the property
     IPSafeAddItemProperty(oItem, ipAdd, nDur);
   }
}

 
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Variables - More then X but less than Y
« Reply #4 on: August 02, 2012, 01:27:30 pm »


               Awesome!! Thank you very much, any chance of adding in a random failure if below say 250 on the int value? Or better yet a selectable chance of failure so it could be changed by whomever decided to use the script?
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Variables - More then X but less than Y
« Reply #5 on: August 02, 2012, 01:53:52 pm »


               One potentially better way of doing it, would be to determine the
maximum strength/effect : of the power in question
ascertain the maximum skill amount: when this skill amount is acquired, you have the maximum strength/effect possible.


Then, any skill that the player has, is worked out as a percentage of the maximum possible

eg

Max Damage of the skill, (just as an example) = 700
100 points out of 500 = 20%
20% of the Maximum possible damage = 140   140 Used as a Base Damage (randomize it with some d12() additions?


But this process can easilly be adapted for Item Properties, or persistent effects on the player

eg
Maybe a Damage Reduction effect?

Max Skill = 100
Max Amount Absorbed = 30
Players Current skill = 35
35% of 30 = 10.5
Player gets 10.5 Damage Reduction effect for this skill level


It might sound rather lazy, but implimenting a flexible percentage based system, would
1. Mean you dont need to plan the different tiers
2. Every skill point counts - no need to worry about thresholds.
3. Well.... its just awesome - cause it can be turned into a framework.

Define you max effect
Define you max Skill level
Divide current Skill Level, by Max Skill level x by hundred = percentage
Then calculate the percentage value of the max effect.

This could be applied to damage immunity, damage reduction, damage shields.
Maybe even to item properties etc