Aller au contenu

Photo

Need some help changing this script


  • Veuillez vous connecter pour répondre
18 réponses à ce sujet

#1
Birdman076

Birdman076
  • Members
  • 186 messages
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 .


#2
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#3
Birdman076

Birdman076
  • Members
  • 186 messages
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.

#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
And last part. How do you want gold or xp loss handled if any?

#5
Birdman076

Birdman076
  • Members
  • 186 messages
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.

#6
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#7
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#8
Birdman076

Birdman076
  • Members
  • 186 messages

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 ;)

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


#9
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Do you still want the chance of failure to reduce charges and critical failure to destroy the item?

#10
Birdman076

Birdman076
  • Members
  • 186 messages
But of course, what fun is item enhancement if its a guarantee. :P

#11
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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.

#12
Birdman076

Birdman076
  • Members
  • 186 messages

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.

#13
Birdman076

Birdman076
  • Members
  • 186 messages
Bumpity Bump Bump.

#14
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
bump

#15
KMdS

KMdS
  • Members
  • 26 messages
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.

#16
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Errors? If you mean the lower case class, well that is the forum here. It will change it to lower case whereever it appears.

#17
KMdS

KMdS
  • Members
  • 26 messages
Ok, here is what I have so far.  I have compiled and tested in the game and is good so far.  Not much left to do but I think I am calling it for the night.  I will continue tomorro.

script one

/*::////////////////////////////////////////////////////////////////////////////
//:: Name: KMdS Public Script and Systems Donations
//:: System: KMdS Magic Systems
//:: SubSystem: KMdS Magic Items Recharger
//:: FileName: chg_recharge_tri
//:: Copyright: © 2011 Michael Careaga
//::////////////////////////////////////////////////////////////////////////////
    Place this script on any placeable you wish to use as a trigger
    for a placeable objecty you wish to use to recharge item charges.
    The triggers tag must begin with "TRIGGER_" and conclude with the tag
    of the placeable you wish this item activate to recarge an items charges
    Place this script on a placeables on_activate event or call from within
    any script you may have for the on_activate event.
//::////////////////////////////////////////////////////////////////////////////
//:: Created By: Kilr Mik d Spik aka KMdS
//:: Created On: 10/07/2011
//:://////////////////////////////////////////////////////////////////////////*/
//  ----------------------------------------------------------------------------
//  LIBRARIES
//  ----------------------------------------------------------------------------
// BW library

// Custom library

//  ----------------------------------------------------------------------------
//  MAIN
//  ----------------------------------------------------------------------------
void main ()
{
    object oTrigger     = OBJECT_SELF;        //  TRIGGER_***
    string sTriggerTag  = GetTag(oTrigger);
    int iTagLength      = GetStringLength(sTriggerTag);
    object oTarget      = GetObjectByTag(GetStringRight(sTriggerTag, iTagLength-8));
    object oPC          = GetLastUsedBy();
    SetLocalObject(oPC, "ACTIVATOR", oTarget);
    ExecuteScript("chg_recharge_plc", oPC);
}

Script two

/*::////////////////////////////////////////////////////////////////////////////
//:: Name: KMdS Public Script and Systems Donations
//:: System: KMdS Magic Systems
//:: SubSystem: KMdS Magic Items Recharger
//:: FileName: chg_recharge_plc
//:: Copyright: © 2011 Michael Careaga
//::////////////////////////////////////////////////////////////////////////////
    This script is called from on_use event script of the triggering placeable
    and will process the item in the inventory of the recharger placeable.

    *See ,chg_recharge_tri,.nss for further information
//::////////////////////////////////////////////////////////////////////////////
//:: Created By: Kilr Mik d Spik aka KMdS
//:: Created On: 10/07/2011
//:://////////////////////////////////////////////////////////////////////////*/
//  ----------------------------------------------------------------------------
//  LIBRARIES
//  ----------------------------------------------------------------------------
// BW library

// Custom library

//  ----------------------------------------------------------------------------
//  PROTOTYPES
//  ----------------------------------------------------------------------------
// FILE: x3_inc_string      FUNCTION: StringToRGBString()
//
// This function will make sString be the specified color
// as specified in sRGB.  RGB is the Red, Green, and Blue
// components of the color.  Each color can have a value from
// 0 to 7.
// Ex: red   == "700"
//     green == "070"
//     blue  == "007"
//     white == "777"
//     black == "000"
// The STRING_COLOR_* constants may be used for sRGB.
//
//*NOTE - this is an original BioWare NWN function imported into this script
// to simlify portability and streamline variables listed within the file to
// those specefic to this script.  This code may be found located in the FILE
// listed within this prototype...KMdS
string StringToRGBString(string sString, string sRGB);
//  ----------------------------------------------------------------------------
//  FUNCTIONS
//  ----------------------------------------------------------------------------
string StringToRGBString(string sString, string sRGB)
{
    // The magic characters (padded -- the last three characters are the same).
    string sColorCodes = " fw®°Ìþþþ";
    // For the older version going 0 to 6, use:
    //string sColorCodes = " fw®°Ìþþþþ";
    return "<c" +   // Begin the color token.
            GetSubString(sColorCodes, StringToInt(GetSubString(sRGB, 0, 1)), 1) + // red
            GetSubString(sColorCodes, StringToInt(GetSubString(sRGB, 1, 1)), 1) + // green
            GetSubString(sColorCodes, StringToInt(GetSubString(sRGB, 2, 1)), 1) + // blue
            ">" +   // End the color token
            sString + "</c>";
}
//  ----------------------------------------------------------------------------
//  MAIN
//  ----------------------------------------------------------------------------
void main ()
{
    object oPC = OBJECT_SELF;
    // Exit if the we are not a PC
    if(!GetIsPC(oPC))
        return;
/* BEGIN SYSTEM VARIABLES */
    // Modify these strings with whatever messages you feel better suit you if desired
    string sSYSTEM_ERROR_ONE                = "There is an error with recharger system, please report this error in detail to server personel";
    string sSYSTEM_ERROR_TWO                = "The skill check is faulty, please report this error in detail to server personel";
    string sERROR_MORE_THAN_ONE_ITEM        = "Huh?  Silly me, I can only recharge one thing at a time";
    string sERROR_IS_NOT_A_MAGE             = "Hmmm,  I wonder what this does?";
    string sERROR_NOT_A_RECHARGEABLE_ITEM   = "I guess I can't recharge this";
    string sERROR_ALREADY_HAS_MAX_CHARGE    = "This seems to have as many charges as it can already";
    int iMAX_CHARGES_POSSIBLE   = 50;
    // you must set at least one of the skills to true for the system to function
    // Set both to true if you wish to use the sum of the two
    int bUSE_LORE_SKILL                 = FALSE;
    int bUSE_SPELLCRAFT_SKILL           = TRUE;
    // Set to TRUE if you wish to use the average of the two skill values
    int bUSE_AVERAGE_OF_SKILL_VALUES    = FALSE;
    // These values will be use as multipliers against the DC value stored on the placeable
    int iXP_LOSS_MULTPLIER  = 15;
    int iGP_LOSS_MULTIPLIER = 3;
    // Usd to verify that the placeable has an int on it defining the DC value
    int bDC_CHECK           = FALSE;
    // If no DC value is found on the placeable, this will be the default value for the DC
    int iDEFAULT_DC         = 30;
/* END SYSTEM VARIABLES */
/* BEGIN CRITICAL SYSTEM CHECKS */
    object oRecharger = GetLocalObject(oPC, "ACTIVATOR");
    // Exit if the recharger object is invalid and send an error message to the PC
    if(oRecharger == OBJECT_INVALID)
    {
        SendMessageToPC(oPC, StringToRGBString(sSYSTEM_ERROR_ONE ,"700"));
        return;
    }
    // There is an error, the bUSE_*_SKILL are not set properly
    if(bUSE_LORE_SKILL + bUSE_SPELLCRAFT_SKILL == FALSE)
    {
        SendMessageToPC(oPC, StringToRGBString(sSYSTEM_ERROR_TWO ,"700"));
        return;
    }
/* END CRITICAL SYSTEM CHECKS */
/* BEGIN STANDARD CHECKS */
    int bIsNotMage = GetLevelByclass(class_TYPE_SORCERER)+GetLevelByclass(class_TYPE_WIZARD) == FALSE;
    // Exit if the PC has no levels in class types sorcerer or mage.....Add any other class checks here by adding
    // +GetLevelByclass(class_TYPE_*) to the addition...KMdS
    if(bIsNotMage)
    {
        SpeakString(StringToRGBString(sERROR_IS_NOT_A_MAGE,"070"));
        return;
    }
    object oInventory = GetFirstItemInInventory(oRecharger);
    // If there is more than one item in the recharger placeable inventory, send the PC a message and exit
    if(GetNextItemInInventory(oRecharger) != OBJECT_INVALID)
    {
        SpeakString(StringToRGBString(sERROR_MORE_THAN_ONE_ITEM,"070"));
        return;
    }
    // Does the item have any charges?
    int iItemCharges = GetItemCharges(oInventory);
    // Is the item rechargeable?
    int bCanBeRecharged = iItemCharges != FALSE && GetItemHasItemProperty(oInventory, ITEM_PROPERTY_CAST_SPELL);
    // If it is rechargable.....
    if(bCanBeRecharged)
    {
        // Does the item already have max charges or more, send the PC a message and exit.
        if(iItemCharges >= iMAX_CHARGES_POSSIBLE)
        {
            SpeakString(StringToRGBString(sERROR_ALREADY_HAS_MAX_CHARGE,"070"));
            return;
        }
    }
    // Otherwise, send 'em a message and exit
    else
    {
        SpeakString(StringToRGBString(sERROR_NOT_A_RECHARGEABLE_ITEM,"070"));
        return;
    }
/* END STANDARD CHECKS */
/* BEGIN PROCESSING */
    int iSkillCheck = 0;
    if(bUSE_LORE_SKILL)
        iSkillCheck += GetSkillRank(SKILL_LORE, oPC);
    if(bUSE_SPELLCRAFT_SKILL)
        iSkillCheck += GetSkillRank(SKILL_SPELLCRAFT, oPC);
    if(bUSE_AVERAGE_OF_SKILL_VALUES)
        iSkillCheck /= 2;
}

I have place alot more documentation in the script so that others that need it can hopefully find it easy to understand.

#18
KMdS

KMdS
  • Members
  • 26 messages

Lightfoot8 wrote...

Errors? If you mean the lower case class, well that is the forum here. It will change it to lower case whereever it appears.


If there are issues with uppercase being changed to lowercase, or any other issues, i can place the final version in my own site and put in a redirect to it so you can pull down clean code.

#19
KMdS

KMdS
  • Members
  • 26 messages
Ok, I made a few modifications to the above posted work and completed the system. Here are the scripts. They compile and I need someone to run them through their paces. From the limited testing I have given them, they are ready.

script #1

/*::////////////////////////////////////////////////////////////////////////////
//:: Name: KMdS Public Script and Systems Donations
//:: System: KMdS Magic Systems
//:: SubSystem: KMdS Magic Items Recharger
//:: FileName: chg_recharge_tri
//:: Copyright: © 2011 Michael Careaga
//::////////////////////////////////////////////////////////////////////////////

Place this script on any placeable you wish to use as a trigger
for a placeable objecty you wish to use to recharge item charges.

The triggers tag must begin with "TRIGGER_" and conclude with the tag
of the placeable you wish this item activate to recarge an items charges

The placeable used used to recharge the item should have an int "DC" stored
upon it to represent the difficulty of use. If no value is set, the system
defaults to a DC of 30.

Default values for many of the system variable may be modified in the
associated script chg_recharge_plc.

Place this script on a placeables on_activate event or call from within
any script you may have for the on_activate event.


//::////////////////////////////////////////////////////////////////////////////
//:: Created By: Kilr Mik d Spik aka KMdS
//:: Created On: 10/07/2011
//:://////////////////////////////////////////////////////////////////////////*/

// ----------------------------------------------------------------------------
// LIBRARIES
// ----------------------------------------------------------------------------

// BW library


// Custom library


// ----------------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------------

void main ()
{
object oTrigger = OBJECT_SELF;
string sTriggerTag = GetTag(oTrigger);
int iTagLength = GetStringLength(sTriggerTag);
object oTarget = GetObjectByTag(GetStringRight(sTriggerTag, iTagLength-8));
object oPC = GetLastUsedBy();

SetLocalObject(oPC, "RECHARGER_PLC", oTarget);
ExecuteScript("chg_recharge_plc", oPC);
}

Script #2

/*::////////////////////////////////////////////////////////////////////////////
//:: Name: KMdS Public Script and Systems Donations
//:: System: KMdS Magic Systems
//:: SubSystem: KMdS Magic Items Recharger
//:: FileName: chg_recharge_plc
//:: Copyright: © 2011 Michael Careaga
//::////////////////////////////////////////////////////////////////////////////

This script is called from on_use event script of the triggering placeable
and will process the item in the inventory of the recharger placeable.

Modify system variable within the Main of the system below

Misc note:
Critical failures are any skill check that fails by 10 or more and will
cause the loss of 1 to 4 charges.

*See ,chg_recharge_tri.nss for further information

//::////////////////////////////////////////////////////////////////////////////
//:: Created By: Kilr Mik d Spik aka KMdS
//:: Created On: 10/07/2011
//:://////////////////////////////////////////////////////////////////////////*/

// ----------------------------------------------------------------------------
// LIBRARIES
// ----------------------------------------------------------------------------

// BW library


// Custom library


// ----------------------------------------------------------------------------
// PROTOTYPES
// ----------------------------------------------------------------------------

// FILE: x3_inc_string FUNCTION: StringToRGBString()
//
// This function will make sString be the specified color
// as specified in sRGB. RGB is the Red, Green, and Blue
// components of the color. Each color can have a value from
// 0 to 7.
// Ex: red == "700"
// green == "070"
// blue == "007"
// white == "777"
// black == "000"
// The STRING_COLOR_* constants may be used for sRGB.
//
//*NOTE - this is an original BioWare NWN function imported into this script
// to simlify portability and streamline variables listed within the file to
// those specefic to this script. This code may be found located in the FILE
// listed within this prototype...KMdS
string StringToRGBString(string sString, string sRGB);

// ----------------------------------------------------------------------------
// FUNCTIONS
// ----------------------------------------------------------------------------

string StringToRGBString(string sString, string sRGB)
{
// The magic characters (padded -- the last three characters are the same).
string sColorCodes = " fw®°Ìþþþ";
// For the older version going 0 to 6, use:
//string sColorCodes = " fw®°Ìþþþþ";

return "<c" + // Begin the color token.
GetSubString(sColorCodes, StringToInt(GetSubString(sRGB, 0, 1)), 1) + // red
GetSubString(sColorCodes, StringToInt(GetSubString(sRGB, 1, 1)), 1) + // green
GetSubString(sColorCodes, StringToInt(GetSubString(sRGB, 2, 1)), 1) + // blue
">" + // End the color token
sString + "</c>";
}

// ----------------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------------

void main ()
{
object oPC = OBJECT_SELF;
// Exit if the we are not a PC
if(!GetIsPC(oPC))
return;

/* BEGIN SYSTEM VARIABLES */

// Modify these strings with whatever messages you feel better suit you if desired
string sSYSTEM_ERROR_ONE = "There is an error with recharger system, please report this error in detail to server personel";
string sSYSTEM_ERROR_TWO = "The skill check is faulty, please report this error in detail to server personel";
string sERROR_MORE_THAN_ONE_ITEM = "Huh? Silly me, I can only recharge one thing at a time";
string sERROR_IS_NOT_A_MAGE = "Hmmm, I wonder what this does?";
string sERROR_NOT_A_RECHARGEABLE_ITEM = "I guess I can't recharge this";
string sERROR_ALREADY_HAS_MAX_CHARGE = "This seems to have as many charges as it can already";

// you must set at least one of the skills to true for the system to function
// Set both to true if you wish to use the sum of the two
int bUSE_LORE_SKILL = FALSE;
int bUSE_SPELLCRAFT_SKILL = TRUE;
// Set to TRUE if you wish to use the average of the two skill values
int bUSE_AVERAGE_OF_SKILL_VALUES = FALSE;

// These values will be use as multipliers against the DC value stored on the placeable
int iXP_LOSS_MULTPLIER = 15;
int iGP_LOSS_MULTIPLIER = 3;

// Maximum possible item charges
int iMAX_CHARGES_POSSIBLE = 50;

// If no DC value is found on the placeable, this will be the default value for the DC
int iDEFAULT_DC = 30;
// The difference of skill value and dc that triggers critical failure
int iCRITICAL_FAILURE = -10;

/* END SYSTEM VARIABLES */

/* BEGIN CRITICAL SYSTEM CHECKS */

object oRecharger = GetLocalObject(oPC, "RECHARGER_PLC");
// Exit if the recharger object is invalid and send an error message to the PC
if(oRecharger == OBJECT_INVALID)
{
SendMessageToPC(oPC, StringToRGBString(sSYSTEM_ERROR_ONE ,"700"));
return;
}

// There is an error, the bUSE_*_SKILL are not set properly
if(bUSE_LORE_SKILL + bUSE_SPELLCRAFT_SKILL == FALSE)
{
SendMessageToPC(oPC, StringToRGBString(sSYSTEM_ERROR_TWO ,"700"));
return;
}

/* END CRITICAL SYSTEM CHECKS */

/* BEGIN STANDARD CHECKS */

int iMageLevels = GetLevelByclass(class_TYPE_SORCERER)+GetLevelByclass(class_TYPE_WIZARD);
// Exit if the PC has no levels in class types sorcerer or mage
if(iMageLevels == FALSE)
{
SpeakString(StringToRGBString(sERROR_IS_NOT_A_MAGE,"070"));
return;
}

object oInventory = GetFirstItemInInventory(oRecharger);
// If there is more than one item in the recharger placeable inventory, send the PC a message and exit
if(GetNextItemInInventory(oRecharger) != OBJECT_INVALID)
{
SpeakString(StringToRGBString(sERROR_MORE_THAN_ONE_ITEM,"070"));
return;
}

// Does the item have any charges?
int iItemCharges = GetItemCharges(oInventory);

// Is the item rechargeable?
int bCanBeRecharged = iItemCharges != FALSE && GetItemHasItemProperty(oInventory, ITEM_PROPERTY_CAST_SPELL);
// If it is rechargable.....
if(bCanBeRecharged)
{
// Does the item already have max charges or more, send the PC a message and exit.
if(iItemCharges >= iMAX_CHARGES_POSSIBLE)
{
SpeakString(StringToRGBString(sERROR_ALREADY_HAS_MAX_CHARGE,"070"));
return;
}
}
// Otherwise, send 'em a message and exit
else
{
SpeakString(StringToRGBString(sERROR_NOT_A_RECHARGEABLE_ITEM,"070"));
return;
}

/* END STANDARD CHECKS */

/* BEGIN PROCESSING */

// Derive PC total skill score
int iSkillCheck = 0;
if(bUSE_LORE_SKILL)
iSkillCheck += GetSkillRank(SKILL_LORE, oPC);
if(bUSE_SPELLCRAFT_SKILL)
iSkillCheck += GetSkillRank(SKILL_SPELLCRAFT, oPC);
if(bUSE_AVERAGE_OF_SKILL_VALUES)
iSkillCheck /= 2;
iSkillCheck += d20();

// Derive Difficulty class value, use default is no dc set on recharger placeable
int iDC = GetLocalInt(oRecharger, "DC");
if(iDC == FALSE)
iDC = iDEFAULT_DC;

int iResult = iSkillCheck-iDC;
// Success
if(iResult > -1)
{
int iXPCost = iDC * iXP_LOSS_MULTPLIER;
int iGPCost = iDC * iGP_LOSS_MULTIPLIER;
int bHasXPs = FALSE;
int bHasGPs = FALSE;

if(GetXP(oPC)-1 < iXPCost)
bHasXPs = TRUE;
if(GetGold(oPC) < iGPCost)
bHasGPs = TRUE;

// If the players have the gold and XP's needed
if(bHasXPs && bHasGPs)
{
int iNewChargeLvl = iItemCharges +(iMageLevels*2);
if(iNewChargeLvl > iMAX_CHARGES_POSSIBLE)
iNewChargeLvl = iMAX_CHARGES_POSSIBLE;
SetItemCharges(oInventory, iNewChargeLvl);
// Let the PC hear the sucsess
AssignCommand(oRecharger, PlaySound("gui_learnspell"));
}
// Otherwise
else
{
string sText = "I need to have ";
if(!bHasXPs)
sText += IntToString(iXPCost+1)+" experience";
if(!bHasXPs && !bHasGPs)
sText += " and ";
if(!bHasGPs)
sText += IntToString(iGPCost)+" gold";
// Let them know what the cost is so they come prepared the next time.
SpeakString(StringToRGBString(sText,"070"));
}
}
// Critical Failure
else if(iResult <= iCRITICAL_FAILURE)
{
int iNewChargeLvl = iItemCharges - d4();
if(iNewChargeLvl < 0)
iNewChargeLvl = 0;
SetItemCharges(oInventory, iNewChargeLvl);
// Let the PC hear the failure
AssignCommand(oRecharger, PlaySound("bf_large"));
}
/* END PROCESSING */
}

All that is needed are two placeables, one that is someform of lever/trigger, and the second that can hold an inventory where the item to be recharged is placed. The trigger placeable must have the tag "TRIGGER_" and the recharging placeable must be identical to the trigger's tag but without the "TRIGGER_" part. Set an int "DC" with whatever value you want for the difficulty. The system will default to a DC of 30 even if no int is set.