Author Topic: Need help with Continuous Light spell cost decrease  (Read 362 times)

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Need help with Continuous Light spell cost decrease
« on: July 20, 2014, 12:50:05 pm »


               

I am trying to reduce item cost after casting of Continuous Light spell. I made this already but the problem is that my script is ending with lower cost then original item had. And its quite ugly way to do that. So if anyone knows how to make it better and possibly seamless (without dozens of huge switch cases etc.) then this is your chance to show off. I will pay 500 vault kredits to person who manage this task.


 


This requires Community Patch 1.71 + 1.72beta installed (or its content ripped off and stolen) because there are all neccessary files and included to create an item cost decrease itemproperty in script. And a closer look at the Item Cost Parameter property (try it in toolset manually first)


 


Current code:



//::///////////////////////////////////////////////
//:: Continual Flame
//:: x0_s0_clight.nss
//:: Copyright (c) 2002 Bioware Corp.
//:://////////////////////////////////////////////
/*
 Permanent Light spell

    XP2
    If cast on an item, item will get permanently
    get the property "light".
    Previously existing permanent light properties
    will be removed!

*/
//:://////////////////////////////////////////////
//:: Created By: Brent Knowles
//:: Created On: July 18, 2002
//:://////////////////////////////////////////////
//:: VFX Pass By:
//:: Added XP2 cast on item code: Georg Z, 2003-06-05
//:://////////////////////////////////////////////
/*
Patch 1.71

- any item that this spell is cast at is now marked as stolen to disable the cast/sell exploit
- spell can dispell the shadowblend effect
*/

#include "70_inc_itemprop"
#include "70_inc_spells"
#include "x0_i0_spells"
#include "x2_inc_spellhook"

void DecreaseItemCost(int nCost)
{
    SendMessageToPC(spell.Caster,"test cost after: "+IntToString(GetGoldPieceValue(spell.Target)));
    itemproperty ip = ItemPropertyItemCostParameter(1,2);
    if(GetIsItemPropertyValid(ip))
    {
        while(GetGoldPieceValue(spell.Target)-nCost >= 500)
        {
            SendMessageToPC(spell.Caster,"test cost while: "+IntToString(GetGoldPieceValue(spell.Target)));
            AddItemProperty(DURATION_TYPE_PERMANENT,ip,spell.Target);
        }
    }
    SendMessageToPC(spell.Caster,"test cost end: "+IntToString(GetGoldPieceValue(spell.Target)));
}

void main()
{
    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run
    // this spell.
    if (!X2PreSpellCastCode())
    {
        return;
    }
    int nDuration;
    int nMetaMagic;

    spellsDeclareMajorVariables();

    // Handle spell cast on item....
    if (GetObjectType(spell.Target) == OBJECT_TYPE_ITEM && !CIGetIsCraftFeatBaseItem(spell.Target))
    {
        // Do not allow casting on not equippable items
        if (!IPGetIsItemEquipable(spell.Target))
        {
            // Item must be equipable...
            FloatingTextStrRefOnCreature(83326,spell.Caster);
            return;
        }
        int prevCost = GetGoldPieceValue(spell.Target);      SendMessageToPC(spell.Caster,"test cost prev: "+IntToString(prevCost));
        itemproperty ip = ItemPropertyLight (IP_CONST_LIGHTBRIGHTNESS_BRIGHT, IP_CONST_LIGHTCOLOR_WHITE);
        IPSafeAddItemProperty(spell.Target, ip, 0.0,X2_IP_ADDPROP_POLICY_REPLACE_EXISTING,TRUE,TRUE);
        DelayCommand(0.0,DecreaseItemCost(prevCost));

    }
    else
    {
        if(GetHasSpellEffect(757, spell.Target))
        {
            //Continual light effectively dispells shadowblend effect
            RemoveEffectsFromSpell(spell.Target, 757);
        }
        //Declare major variables
        effect eVis = EffectVisualEffect(VFX_DUR_LIGHT_WHITE_20);
        effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
        effect eLink = SupernaturalEffect(EffectLinkEffects(eVis, eDur));

        //Fire cast spell at event for the specified target
        SignalEvent(spell.Target, EventSpellCastAt(spell.Caster, spell.Id, FALSE));

        //Apply the VFX impact and effects
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLink, spell.Target);
   }
}

Log after the spell was cast on amulet of natural armor +5:



[Sun Jul 20 13:45:14] test cost prev: 19449
[Sun Jul 20 13:45:14] test cost after: 24109
[Sun Jul 20 13:45:14] test cost while: 24109
[Sun Jul 20 13:45:14] test cost while: 24069
[Sun Jul 20 13:45:14] test cost while: 23949
[Sun Jul 20 13:45:14] test cost while: 23749
[Sun Jul 20 13:45:14] test cost while: 23469
[Sun Jul 20 13:45:14] test cost while: 23109
[Sun Jul 20 13:45:14] test cost while: 22669
[Sun Jul 20 13:45:14] test cost while: 22149
[Sun Jul 20 13:45:14] test cost while: 21549
[Sun Jul 20 13:45:14] test cost while: 20869
[Sun Jul 20 13:45:14] test cost while: 20109
[Sun Jul 20 13:45:14] test cost end: 19269

as you can see, the script applies the item decrease itemproperty almost twenty times (ugly!) and end up with lower cost than before. I don't mine if the end cost would be greater than original but not more than 500.


 


It is possible to choose item propertsy with greater negative value but then the end cost ends up with much less than original.


 


 


Well, time to show off, master scripters.



               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Need help with Continuous Light spell cost decrease
« Reply #1 on: July 20, 2014, 05:06:34 pm »


               

Have you thought about just adjusting the iprp_lightcost.2da to all 0 and have you look the sub types



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Need help with Continuous Light spell cost decrease
« Reply #2 on: July 20, 2014, 05:26:35 pm »


               


Have you thought about just adjusting the iprp_lightcost.2da to all 0 and have you look the sub types




no because thats not suitable for project like this


 


and before you say


 


same for other methods such as applying the itemproperty temporary - this is the only way I can use, just need to make it better



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need help with Continuous Light spell cost decrease
« Reply #3 on: July 21, 2014, 02:35:05 am »


               

Lower price with respect to what?  You could make items that have permanent light (but not continual flame) have a cost increase or duplicate light properties.


 


Your log indicates that ItemPropertyItemCostParameter(1,2) is reducing the cost by 40gp + 80gp per additional iteration.  This ratio 1:2 and 40:80 may indicate a pattern.