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.