Can I have two or even three events in a single tag based script for an item? I feel like this is way easier than inserting the necessary events into each module event separately.. just have them all here in this one script for this one item. Unfortunately when a player unequips the item the penalty isn't removed.
#include "x2_inc_switches"
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
object oSelf;
object oItem;
SendMessageToPC(GetFirstPC(),IntToString(nEvent));
if (nEvent ==X2_ITEM_EVENT_EQUIP)
{
oSelf = GetPCItemLastEquippedBy();
oItem = GetPCItemLastEquipped();
int eHealSkill = GetSkillRank(SKILL_HEAL, oSelf, FALSE);
effect dHeal = EffectSkillDecrease(SKILL_HEAL, eHealSkill/2 );
ApplyEffectToObject(DURATION_TYPE_PERMANENT, dHeal, oSelf);
}
if (nEvent ==X2_ITEM_EVENT_UNEQUIP)
{
oSelf = GetPCItemLastUnequippedBy();
oItem = GetPCItemLastUnequipped();
int eHealSkill = GetSkillRank(SKILL_HEAL, oSelf, FALSE);
effect dHeal = EffectSkillDecrease(SKILL_HEAL, eHealSkill/2 );
RemoveEffect(oSelf, dHeal);
}
}
Also wondering how I can make the penalty for heal skill unrestorable :3 ...
Everything in nwn has its own unique ID
You cannot really see this, through NWScript, but it does exist.
You can use ObjectToString to see it for objects, but it doesn't end just there, effects have their own unique IDs too.
They are instanced classes which get created when you call one of the Effect functions.
So when you are doing
effect dHeal = EffectSkillDecrease(SKILL_HEAL, eHealSkill/2 );
RemoveEffect(oSelf, dHeal);
This does not remove the effect from the player, because you are attempting to remove an effect that has not been applied to the player in the first place.
dHeal has been created by EffectSkillDecrease(SKILL_HEAL, eHealSkill/2 );
but has not been applied to any creature, so the RemoveEffect call is redundant.
In order to remove the effect applied in the Equip event, you need to loop through the characters effects, and find an effect that matches the type and subtype you are looking for.
effect e = GetFirstEffect(oPC);
object oEffectCreator = GetMySpecialCreator();
while(GetIsEffectValid(e)){
int iType = GetEffectType(e);
int iSubType = GetEffectSubType(e);
object oCreator = GetEffectCreator(e);
if(iType == EFFECT_TYPE_SKILL_DECREASE && iSubType == SUBTYPE_SUPERNATURAL && oCreator == oEffectCreator) {
RemoveEffect(oPC,e);
}
e = GetNextEffect(oPC);
}
You are limited in the amount of information you can get from an existing effect.
Eg: Where it originally came from, eg: Was it created when you equipped the item, or was it created by a spell someone cast on you.
In order to differentiate between these, I recommend you create a placeable, or NPC, that applies the 'special' effects for you.
Then you can tell if these are the effects that you want to have removed on unequip.
object MyCreatorObject(){
return GetObjectByTag("my_effect_creator");
}
effect GetEffectFromID(int EffectID, int Value1, int Value2)
{
effect iEffect;
switch(EffectID)
{
case EFFECT_TYPE_ARCANE_SPELL_FAILURE: iEffect = EffectSpellFailure(Value1, Value2); break;
case EFFECT_TYPE_BLINDNESS: iEffect = EffectBlindness(); break;
case EFFECT_TYPE_CHARMED: iEffect = EffectCharmed();break;
case EFFECT_TYPE_CONCEALMENT: iEffect = EffectConcealment(Value1, Value2); break;
case EFFECT_TYPE_CONFUSED: iEffect = EffectConfused(); break;
case EFFECT_TYPE_CUTSCENEGHOST: iEffect = EffectCutsceneGhost(); break;
case EFFECT_TYPE_HASTE: iEffect = EffectHaste(); break;
case EFFECT_TYPE_IMMUNITY: iEffect = EffectImmunity(Value1); break;
case EFFECT_TYPE_IMPROVEDINVISIBILITY: iEffect = EffectInvisibility(INVISIBILITY_TYPE_IMPROVED); break;
case EFFECT_TYPE_INVISIBILITY: iEffect = EffectInvisibility(INVISIBILITY_TYPE_NORMAL); break;
case EFFECT_TYPE_MISS_CHANCE: iEffect = EffectMissChance(Value1, Value2); break;
case EFFECT_TYPE_MOVEMENT_SPEED_DECREASE: iEffect = EffectMovementSpeedDecrease(Value1); break;
case EFFECT_TYPE_MOVEMENT_SPEED_INCREASE: iEffect = EffectMovementSpeedIncrease(Value2); break;
case EFFECT_TYPE_POLYMORPH: iEffect = EffectPolymorph(Value1, Value2); break;
case EFFECT_TYPE_REGENERATE: iEffect = EffectRegenerate(Value1, IntToFloat(Value2)); break;
case EFFECT_TYPE_SANCTUARY: iEffect = EffectSanctuary(Value1); break;
case EFFECT_TYPE_SLOW: iEffect = EffectSlow();break;
case EFFECT_TYPE_TEMPORARY_HITPOINTS: iEffect = EffectTemporaryHitpoints(Value1); break;
case EFFECT_TYPE_TRUESEEING: iEffect = EffectTrueSeeing(); break;
case EFFECT_TYPE_ULTRAVISION: EffectUltravision(); break;
case EFFECT_TYPE_VISUALEFFECT: iEffect = EffectVisualEffect(Value1, Value2); break;
case EFFECT_TYPE_DAMAGE_IMMUNITY_INCREASE: iEffect = EffectDamageImmunityIncrease(Value1, Value2); break;
case EFFECT_TYPE_DAMAGE_IMMUNITY_DECREASE: iEffect = EffectDamageImmunityDecrease(Value1, Value2); break;
default: iEffect; break;
}
return iEffect;
}
//Note- Effects need to be 'created' by the creature, in order to have that creature as the creator.
//Who applies it is irrelevant.
void ApplyEffectFromCreator(object o, int effectType, int EffectNumber, int EffectNumber2, int durationType, float durationAmount){
effect e = GetEffectFromID(effectType, EffectNumber, EffectNumber2);
ApplyEffectToObject(durationType,e,o,durationAmount);
}
void Test(){
object oPC = GetFirstPC();
AssignCommand(MyCreatorObject(),ApplyEffectFromCreator(oPC, EFFECT_TYPE_SKILL_DECREASE, 10, 0, DURATION_TYPE_PERMANENT,0.00f));
}
This is pretty rough, but the idea is that you have to assign the effect creation and application, to another object, so that object gets marked as the creator.
Then when you do the removal, you can then check to see if that object was the creator of the effect.
If so - remove it.
If not, leave it.