Ok so let's start with the tagbased script first. If you want one script to work with the OnEquip and OnUnequip events (or any of the other events for that matter) then you need to structure it so that you figure out which event is happening first. Then define your variables inside each "if" statement:
#include "x2_inc_switches"
void main()
{
int iEvent = GetUserDefinedItemEventNumber();
if (iEvent == X2_ITEM_EVENT_EQUIP)
//PC equips item {
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();
//Everything else
}
else if (iEvent == X2_ITEM_EVENT_UNEQUIP)
//PC unequips item {
object oPC = GetPCItemLast
UnequippedBy();
object oItem = GetPCItemLast
Unequipped();
//Everythihng else
}
//You can keep going with this is you want something to happen with other //events as well. else if (iEvent == X2_ITEM_EVENT_ACQUIRE)
//PC picks up, buys, gets item {
object oPC = GetModuleItemAcquiredBy();
object oItem = GetModuleItemAcquired();
//Everything else
}
else if (iEvent == X2_ITEM_EVENT_UNACQUIRE)
//PC sells, drops, loses item {
object oPC = GetModuleItemLostBy();
object oItem = GetModuleItemLost();
//Everything else
}
//else if (iEvent == etc...
}
You will notice that we put any variables that pertains specifically to one of those events inside the "if". In your script you define oPC at the top as "GetPCItemLastEquippedBy()". But what happens when the player is UNequipping it? He then needs to be defined differently as "GetPCItemLastUnequippedBy()".
Hopefully that makes sense.
So your script might look more like:
#include "x2_inc_switches"
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
if (nEvent == X2_ITEM_EVENT_EQUIP)
{
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();
int nSpeed = 30;
if(GetLevelByclass(class_TYPE_MONK, oPC)>=6)// ._.
{
nSpeed-= 25;
}
AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectMovementSpeedIncrease(nSpeed)), oPC));
}
else if (nEvent == X2_ITEM_EVENT_UNEQUIP)
{
object oPC = GetPCItemLastUnequippedBy();
object oItem = GetPCItemLastUnequipped();
effect eEffect = GetFirstEffect(oPC);
while (GetIsEffectValid(eEffect))
{
if(GetEffectCreator(eEffect) == oItem)
{
if (GetEffectType(eEffect) == EFFECT_TYPE_MOVEMENT_SPEED_INCREASE)
{
RemoveEffect(oPC, eEffect);
}
}
eEffect = GetNextEffect(oPC);
}
}
}
Modifié par GhostOfGod, 15 mai 2012 - 08:15 .