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

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need some help changing this script
« Reply #15 on: October 08, 2011, 02:10:54 am »


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

               
            

Legacy_KMdS

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Need some help changing this script
« Reply #16 on: October 08, 2011, 03:38:44 am »


               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.
               
               

               
            

Legacy_KMdS

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Need some help changing this script
« Reply #17 on: October 08, 2011, 03:45:25 am »


               

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.
               
               

               
            

Legacy_KMdS

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Need some help changing this script
« Reply #18 on: October 08, 2011, 07:47:12 pm »


               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.