Author Topic: Need some help changing this script  (Read 537 times)

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Need some help changing this script
« on: September 11, 2011, 04:01:05 pm »


               I'm trying to adapt this script to be used on a placeable as opposed to an item unique power. I don't need to lore check or the examine functions tbh, I just would like the recharge functions. If anyone can help out that'd be great!

/*
rchrgitmskl

A script designed to be used inconjuction with a item with a tag name of the
same value as the script name and has the cast spell unique ability set
that can be used to recharge magical items that use charges.

It works by if you have the item to be charged in your packpack it will examine
the item and inform the user of the difficulty, xp loss and gold loss to perfom
the charging. If its on the ground or equiped however it will attempt a charging
process.

The caster must have sufficient Lore to be able to perform a DC check to be
able to perform the operations and in the case of charging a Spellcraft check
is made.

It recharges based a value of the caster level divided by 2, and is set to a
maximum variable in the script currently set to 50.

It is a unlimited use per day item that is undroppable and only useable by
wizards and sorcerers, but I have offset the value of doing this
with balanced xp and gold losses. This is intentional so as not to make the
"skill" to powerful. (The values are open to debate and further testing but
I had lots of fun on a little mod with it, enjoy.)

*/

#include "nw_i0_generic"

void main ()
{

object oItem = GetItemActivated();
object oTarget = GetItemActivatedTarget();
location lTarget = GetItemActivatedTargetLocation();
object oPC = GetItemActivator();

int nMaxCharges = 50; // Maximum recharge value and check
int iDC;
int iEasy   = 30; // Easy Charge item DC value
int iNormal = 35; // Normal DC
int iHard   = 40; // Hard DC
int ixpweighter = 15; // xp loss is DC * weighter
int igpweighter = 3;  // gp loss is DC * weighter
int iValidType = FALSE;
int iExamMode = FALSE;

object oInv = GetFirstItemInInventory(oPC);

// Check to see if the target object is in the inventory or not
// If it is we examine the possibiltiy of success and loss factors and
// display them to the player.
// If not then the target object must be on the floor or elsewhere so
// we use the charging mode.

while (oInv != OBJECT_INVALID)
{
    if (oInv == oTarget)
    {
        iExamMode = TRUE;
        oInv = OBJECT_INVALID;

    }
    else
    {
        oInv = GetNextItemInInventory(oPC);
    }
}

int nCharges = GetItemCharges(oTarget);

// Check that oTarget is a magical item with ability to cast spells

if (GetItemHasItemProperty(oTarget, ITEM_PROPERTY_CAST_SPELL) == TRUE &&
    nCharges > 0)
{

 // Check that no of current charges < maximum recharge limit

 if (nCharges < nMaxCharges)
 {

    // Check that caster has required Lore and valid item type for action
    // Get DC (difficulty check at the same time)
    int iPCLore = GetSkillRank(SKILL_LORE, oPC);
    int itype   = GetBaseItemType(oTarget);

    switch(itype)
    {
    case BASE_ITEM_AMULET:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_ARMOR:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_BASTARDSWORD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_BATTLEAXE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_BELT:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_BOOTS:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_BRACER:
        iDC = iEasy;
        iValidType = TRUE;
        break;
    case BASE_ITEM_CBLUDGWEAPON:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_CLOAK:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_CLUB:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_CPIERCWEAPON:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_CSLASHWEAPON:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_CSLSHPRCWEAP:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_DAGGER:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_DIREMACE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_DOUBLEAXE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_DWARVENWARAXE:
        iDC = iHard;
        // Perhaps put check for caster to be race dwarf here?
        iValidType = TRUE;
        break;
    case BASE_ITEM_GLOVES:
        iDC = iEasy;
        iValidType = TRUE;
        break;
    case BASE_ITEM_GREATAXE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_GREATSWORD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_HALBERD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_HANDAXE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_HEAVYCROSSBOW:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_HEAVYFLAIL:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_HELMET:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_KAMA:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_KATANA:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_KUKRI:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_LARGESHIELD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_LIGHTCROSSBOW:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_LIGHTFLAIL:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_LIGHTHAMMER:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_LIGHTMACE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_LONGBOW:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_LONGSWORD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_MAGICROD:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_MAGICSTAFF:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_MAGICWAND:
        iDC = iEasy;
        iValidType = TRUE;
        break;
    case BASE_ITEM_MORNINGSTAR:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_QUARTERSTAFF:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_RAPIER:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_RING:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SCIMITAR:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SCYTHE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SHORTBOW:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SHORTSPEAR:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SHORTSWORD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SICKLE:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SLING:
        iDC = iNormal;
        iValidType = TRUE;
        break;
    case BASE_ITEM_SMALLSHIELD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_TOWERSHIELD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_TWOBLADEDSWORD:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_WARHAMMER:
        iDC = iHard;
        iValidType = TRUE;
        break;
    case BASE_ITEM_WHIP:
        iDC = iHard;
        iValidType = TRUE;
        break;

    }
    if (iValidType == TRUE)
    {

      if ((iPCLore + 20) >= iDC) // Sufficient Lore to do it
      {

        // Determine xp and gold loss

        int ixploss = (iDC * ixpweighter);
        int igploss = (iDC * igpweighter);

        // Check Mode

        // IF examine Mode

        if (iExamMode == TRUE)
        {
            // Display Chance of success and xp/gold amounts
            string sExamine = "Charging will be at Spellcraft DC: ";
            sExamine = sExamine + IntToString(iDC);
            sExamine = sExamine + " and will Cost: ";
            sExamine = sExamine + IntToString(ixploss) + " xp";
            if (igploss > 0)
            {
                sExamine = sExamine + " and " + IntToString(igploss) +" gp";
            }
            sExamine = sExamine + ".";

            SendMessageToPC(oPC, sExamine);


            // Restore daily use in unique item (OBJECT_SELF)?
        }
        else
        {
        // IF charge Mode

            // Check player has sufficient gold and xp

            int iPCxp = GetXP(oPC);
            int iPCgp = GetGold(oPC);

            if ((iPCxp - ixploss) > 0)
            {
            if ((iPCgp - igploss) > 0)
            {
            // Attempt Charge process

            int iSpellCraft = GetSkillRank(SKILL_SPELLCRAFT, oPC);

            if (GetIsSkillSuccessful(oPC, SKILL_SPELLCRAFT, iDC) == TRUE)
            {
                // If successfull
                int iWizlvl = GetLevelByclass(class_TYPE_WIZARD, oPC);
                int iSorlvl = GetLevelByclass(class_TYPE_SORCERER, oPC);

                int itotlvl = iWizlvl + iSorlvl;

                int nRecharge = itotlvl / 2;
                if (nRecharge == 0)
                {
                    nRecharge = 1;
                }

                if (nCharges + nRecharge > 50)
                {
                    nRecharge = 50;
                }
                else
                {
                    nRecharge = nCharges + nRecharge;
                }

                // play spell animation for effect

                FloatingTextStringOnCreature
                ("Enzur Hirath alka ishdo.", oPC, TRUE);

                effect eCharge = EffectDispelMagicAll(itotlvl);

                ApplyEffectToObject(DURATION_TYPE_TEMPORARY,
                eCharge, oTarget, 5.0);

                // Recharge item

                SetItemCharges(oTarget, nRecharge);

                string sRecharge = "Object recharged to value: ";
                sRecharge = sRecharge + IntToString(nRecharge);
                SendMessageToPC(oPC, sRecharge); // Debug

                // reduce xp/gold

                int inewxp =  iPCxp - ixploss;
                SetXP(oPC, inewxp);
                if (igploss > 0)
                {
                    TakeGoldFromCreature(igploss, oPC, TRUE);
                }

            }
            else
            {
            // If unsucssfull check for critical failure, reduce charges and check
            // to see whether to destroy item

            int ifail = d20(1);

            if (ifail == 1)
                {
                int iReduce = (d4(1) - 1);
                nCharges = nCharges - iReduce;
                if (nCharges < 0)
                    {
                    nCharges = 0;
                    }
                 string sfailed = "Critical Failure: Reduced charges by";
                 sfailed = sfailed + IntToString(iReduce);
                 SendMessageToPC(oPC, sfailed);
                 SetItemCharges(oTarget, nCharges);
                }
            }
            }
            else
              {
              SendMessageToPC(oPC, "You do not have enough Gold.");
              }
            }
            else
              {
              SendMessageToPC(oPC, "You haven't enough experience to do this.");
              }
        } // Exam Mode

      } // Sufficient Lore
      else
      {
      SendMessageToPC(oPC, "You do not have sufficient Lore to do this.");
      }
    } // Valid Type
    else
    {
    SendMessageToPC(oPC, "Cannot Recharge that Item.");
    }
  } // Check charges
  else
  {
  SendMessageToPC(oPC, "Item is fully recharged.");
  }
} // Check magical
else
{
SendMessageToPC(oPC,"Item is not a spell casting type object that has charges");
}

}
               
               

               


                     Modifié par Birdman076, 11 septembre 2011 - 03:01 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Need some help changing this script
« Reply #1 on: September 11, 2011, 06:51:30 pm »


               First you will need to determine how you want to target the item that needs to be recharged. Using another item to do that makes it pretty easy since you can target the item. If you want a placeable then you are probably going to go with the "Item in chest then pull the lever" type scenario. It doesn't have to be that literally but something like it. Unless you want all the items the player has to be recharged at once which is another option.
Do you still want it so that only the above item types can be recharged?
Do you still want it so that wizards and sorcerers get extra charges?

So we'll need a bit more info from you on how you want it to work specifically but it can be done. It might even be easier just to start from scratch than to alter this script since there is stuff in there that you don't want or need.
               
               

               


                     Modifié par GhostOfGod, 11 septembre 2011 - 05:54 .
                     
                  


            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Need some help changing this script
« Reply #2 on: September 11, 2011, 07:01:42 pm »


               Lever would be fine as I am thinking of either a chest or an alchemy table type placeable you put the item it to recharge.

Ideally any item that has a charge on it would be rechargable.
I'd like it set for only Arcane classes to be able to use.
I wasn't aware of extra charges, I thought 50 was tops for any item to be charged? Regardless, if its limited to only Arcane caster classes then it would be a moot point for extra charges.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Need some help changing this script
« Reply #3 on: September 11, 2011, 07:56:19 pm »


               And last part. How do you want gold or xp loss handled if any?
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Need some help changing this script
« Reply #4 on: September 11, 2011, 08:11:50 pm »


               I'd like that to remain configurable as it is in the current script if possible. If it wouldn't be too much trouble perhaps variables which can be stipulated on the placeable so one script could run multiple rechargers with different gold/xp values for each.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Need some help changing this script
« Reply #5 on: September 11, 2011, 08:18:42 pm »


               The thing is, the gold and xp loss currently take that lore check into consideration to determine the amount. And since you don't want to use that you will need to come up with some other way to charge for both. Maybe just give an automatic 30, 35 or 40 (easy, normal or hard)? There are lots of ways you could go with this.

Scratch that. Lore check has nothing to do with the gold cost. This script is a bit confusing to read.
               
               

               


                     Modifié par GhostOfGod, 13 septembre 2011 - 08:52 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Need some help changing this script
« Reply #6 on: September 11, 2011, 08:36:50 pm »


               So far, without taking any gold or XP, this is how I see the OnUsed of your placeable(lever or object):

void main()
{
    object oPC = GetLastUsedBy();
    object oContainer = GetObjectByTag("RECHARGE_CONTAINER");
    object oItem = GetFirstItemInInventory(oContainer);
    if (!GetIsObjectValid(oItem))
    {
        FloatingTextStringOnCreature("There is no item in the container.", oPC);
        return;
    }

    object oItem2 = GetNextItemInInventory(oContainer);
    if (GetIsObjectValid(oItem2))
    {
        FloatingTextStringOnCreature("There must be only one item in the container.", oPC);
        return;
    }

    int iWizlvl = GetLevelByclass(class_TYPE_WIZARD, oPC);
    int iSorlvl = GetLevelByclass(class_TYPE_SORCERER, oPC);
    int iMagtotal = iWizlvl + iSorlvl;
    if (!iMagtotal)
    {
        FloatingTextStringOnCreature("You must be a wizard or sorcerer to use this.", oPC);
        return;
    }

    if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_CAST_SPELL) == TRUE &&
                               GetItemCharges(oItem) > 0)
    {
        //int iGold = GetGold(oPC);
        //int iXP = GetXP(oPC);
        SetItemCharges(oItem, 50);
        FloatingTextStringOnCreature("Your item has been recharged.", oPC);
    }

    else
    {
        FloatingTextStringOnCreature("This item is not rechargable.", oPC);
    }
}

Something like that anyhow.
               
               

               


                     Modifié par GhostOfGod, 11 septembre 2011 - 07:41 .
                     
                  


            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Need some help changing this script
« Reply #7 on: September 11, 2011, 08:51:51 pm »


               

GhostOfGod wrote...

The thing is, the gold and xp loss currently take that lore check into consideration to determine the amount. And since you don't want to use that you will need to come up with some other way to charge for both. Maybe just give an automatic 30, 35 or 40 (easy, normal or hard)? There are lots of ways you could go with this.


How about going off of Spellcraft for the check instead of lore? I mean most wizards/Sorcs would have lore but I would think spellcraft would have more in common with charging an item then lore does. I mean the item is already identified, we are looking at the arcane practioners knowledge and ability to recharge it using the placeable as a conduit.

Or even concentration for that matter.

BTW, thanks for all the help GOG, always nice to have you lending a hand and fleshing these things out '<img'>
               
               

               


                     Modifié par Birdman076, 11 septembre 2011 - 07:52 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Need some help changing this script
« Reply #8 on: September 12, 2011, 01:36:45 am »


               Do you still want the chance of failure to reduce charges and critical failure to destroy the item?
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Need some help changing this script
« Reply #9 on: September 12, 2011, 01:45:33 am »


               But of course, what fun is item enhancement if its a guarantee. '<img'>
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Need some help changing this script
« Reply #10 on: September 13, 2011, 09:45:46 pm »


               Sorry Birdman. Didn't mean to leave you hanging with this. "Real life" came up. I'll get back to it as soon as I can unless someone else wants to tackle it in the meantime.
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Need some help changing this script
« Reply #11 on: September 13, 2011, 11:25:19 pm »


               

GhostOfGod wrote...

Sorry Birdman. Didn't mean to leave you hanging with this. "Real life" came up. I'll get back to it as soon as I can unless someone else wants to tackle it in the meantime.


No worries at all GOG, RL comes first.
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Need some help changing this script
« Reply #12 on: September 28, 2011, 01:28:10 am »


               Bumpity Bump Bump.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need some help changing this script
« Reply #13 on: October 05, 2011, 01:09:19 am »


               bump
               
               

               
            

Legacy_KMdS

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Need some help changing this script
« Reply #14 on: October 07, 2011, 11:57:22 pm »


               I've got it, working on it now.  There are a couple of errors in the basic script as posted.  I have them fixed and am working on the request, I should have something for you sometime within the next few hours.