Aller au contenu

Photo

Need some help with script


  • Veuillez vous connecter pour répondre
10 réponses à ce sujet

#1
valasc

valasc
  • Members
  • 23 messages
Greetings!

I am working on a script based off a script by The Fred - combining a fly script with a hard landing that will damage enemies around the landing in a circle. It is class based, so I am setting the local variable in the OnEnter fucntion of the mod. The fly portion works, but no damage or knockdown efect is being applied to any enemies around. It is a tag based script.

#include "x0_i0_spells"
#include "x2_inc_switches"
void DeathAbove(int nSmashPower);
void main()
{
    int nEvent =GetUserDefinedItemEventNumber();
    object oPC;
    object oItem;

    // * This code runs when the item has the OnHitCastSpell: Unique power property
    // * and it hits a target(weapon) or is being hit (armor)
    // * Note that this event fires for non PC creatures as well.
    if (nEvent ==X2_ITEM_EVENT_ONHITCAST)
    {
        oItem  =  GetSpellCastItem();                  // The item casting triggering this spellscript
        object oSpellOrigin = OBJECT_SELF ;
        object oSpellTarget = GetSpellTargetObject();
        oPC = GetItemPossessor(oItem);
    }
    // * This code runs when the Unique Power property of the item is used
    // * Note that this event fires PCs only
    else if (nEvent ==  X2_ITEM_EVENT_ACTIVATE)
    {
        oPC   = GetItemActivator();
        oItem = GetItemActivated();
        object oTarget = GetItemActivatedTarget();
        location lTarget = GetItemActivatedTargetLocation();

        if((GetIsObjectValid(oTarget))&&(oTarget==oPC))
            {
            int iPhenoFinal;
            switch(GetPhenoType(oTarget))
                {
                case 0: iPhenoFinal = 16; break;//normal Pheno
                case 16: iPhenoFinal = 0; break;//CEP flying pheno
                case 2: iPhenoFinal = 25; break;//large Pheno
                case 25: iPhenoFinal = 2; break;//CEP flying large pheno
                default: iPhenoFinal = 0;break;
                }
            SetPhenoType(iPhenoFinal, oTarget);
            }
        else
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectDisappearAppear(lTarget), oPC, 3.0f);

     //Do Death From Above when landing
    int nSmashPower = GetLocalInt(oPC, "DeathAbove");
    if(nSmashPower)
    {
        DelayCommand(5.0, DeathAbove(nSmashPower));
    }
    }

    // * This code runs when the item is equipped
    // * Note that this event fires PCs only
    else if (nEvent ==X2_ITEM_EVENT_EQUIP)
    {
        oPC = GetPCItemLastEquippedBy();
        oItem = GetPCItemLastEquipped();
    }

    // * This code runs when the item is unequipped
    // * Note that this event fires PCs only
    else if (nEvent ==X2_ITEM_EVENT_UNEQUIP)
    {
        oPC    = GetPCItemLastUnequippedBy();
        oItem  = GetPCItemLastUnequipped();
    }
    // * This code runs when the item is acquired
    // * Note that this event fires PCs only
    else if (nEvent == X2_ITEM_EVENT_ACQUIRE)
    {
        oPC = GetModuleItemAcquiredBy();
        oItem  = GetModuleItemAcquired();
    }

    // * This code runs when the item is unaquire d
    // * Note that this event fires PCs only
    else if (nEvent == X2_ITEM_EVENT_UNACQUIRE)
    {
        oPC = GetModuleItemLostBy();
        oItem  = GetModuleItemLost();
    }

    //* This code runs when a PC or DM casts a spell from one of the
    //* standard spellbooks on the item
    else if (nEvent == X2_ITEM_EVENT_SPELLCAST_AT)
    {
        oPC = GetLastSpellCaster();
        oItem  = GetSpellTargetObject();
    }
}
 void DeathAbove(int nSmashPower)
{

    location lTarget = GetItemActivatedTargetLocation();
    effect eDust = EffectVisualEffect(VFX_IMP_DUST_EXPLOSION);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eDust, lTarget);

    int nNotCreature;
    int nDamage1;
    int nDamage2;
    effect eDamage;
    effect eKD = EffectKnockdown();
    float fDelay;

    float fRadius = 5.0 + IntToFloat(nSmashPower) / 2;
    if(fRadius >= 10.0) fRadius = 10.0;
    object oStomped = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lTarget, FALSE,
                        OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE |
                        OBJECT_TYPE_DOOR);
    while(GetIsObjectValid(oStomped))
    {
        if(GetObjectType(oStomped) == OBJECT_TYPE_PLACEABLE ||
           GetObjectType(oStomped) == OBJECT_TYPE_DOOR)
        {
            nNotCreature = TRUE;
        }

        if(GetIsEnemy(oStomped) || nNotCreature)
        {
            fDelay = GetRandomDelay();

            if(spellsIsFlying(oStomped))
            {
                nDamage1 = d10(nSmashPower);
                nDamage2 = GetReflexAdjustedDamage(nDamage1, oStomped, 15 +
                                    (nSmashPower / 2));
            }
            else
            {
                nDamage1 = d10(nSmashPower + nSmashPower * nNotCreature);
                nDamage2 = GetReflexAdjustedDamage(nDamage1, oStomped, 15 +
                                    nSmashPower);
            }

            eDamage = EffectDamage(nDamage2, DAMAGE_TYPE_BLUDGEONING);
            DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage,
                                oStomped));

            if(nDamage1 == nDamage2)
            {
                DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_TEMPORARY,
                                    eKD, oStomped, GetRandomDelay(3.5, 4.5)));
            }
        }

        oStomped = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lTarget, FALSE,
                        OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE |
                        OBJECT_TYPE_DOOR);
    }
}

Edit: Corrected mistype in answer to Magical Master.

Modifié par valasc, 03 septembre 2012 - 06:08 .


#2
MagicalMaster

MagicalMaster
  • Members
  • 2 003 messages
How is that compiling?  More specifically, where is lSelf declared/defined from this line (at the start of the stomp)?

ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eDust, lSelf);

#3
valasc

valasc
  • Members
  • 23 messages
Mistype. Corrected in original post.

#4
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
The first thing that stands out from a quick scan is that you are delaying the DeathAbove function then using  GetItemActivatedTargetLocation() from within the function.  Since the function is delayed it is no longet in the ItemActivate Event. That being the case GetItemActivatedTargetLocation()  is no longer a valid way to get the location.


try changing you function header to

void DeathAbove(int nSmashPower, location lTarget )

Remove the  location lTarget = GetItemActivatedTargetLocation(); line from the function.  

and change the call to the function to be:

 AssignCommand( oPC, DelayCommand(5.0, DeathAbove(nSmashPower,lTarget ))) ;


assigning the command will allow your PC to get credit of any damage done, If not the module will get the credit for the damage.

#5
MagicalMaster

MagicalMaster
  • Members
  • 2 003 messages
Edit: nevermind.

Modifié par MagicalMaster, 03 septembre 2012 - 08:11 .


#6
valasc

valasc
  • Members
  • 23 messages
Hmmm, that didn't seem to do the trick either. The fly portion of the script works perfectly, but the damage section does not fire. Any other suggestions?

#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Ok,
 in  order for the Creature to do a smash it would have to have a local int set on them for the power of the smash. 

it sounds like you are not setting that anywhere.   So I just commented out the check.   Here is the script.  


#include "x0_i0_spells"
#include "x2_inc_switches"
void DeathAbove(int nSmashPower, location lTarget);
void main()
{
    int nEvent =GetUserDefinedItemEventNumber();
    object oPC;
    object oItem;

    // * This code runs when the Unique Power property of the item is used
    // * Note that this event fires PCs only
    if (nEvent ==  X2_ITEM_EVENT_ACTIVATE)
    {
        oPC   = GetItemActivator();
        oItem = GetItemActivated();
        object oTarget = GetItemActivatedTarget();
        location lTarget = GetItemActivatedTargetLocation();

        if((GetIsObjectValid(oTarget))&&(oTarget==oPC))
            {
            int iPhenoFinal;
            switch(GetPhenoType(oTarget))
                {
                case 0: iPhenoFinal = 16; break;//normal Pheno
                case 16: iPhenoFinal = 0; break;//CEP flying pheno
                case 2: iPhenoFinal = 25; break;//large Pheno
                case 25: iPhenoFinal = 2; break;//CEP flying large pheno
                default: iPhenoFinal = 0;break;
                }
            SetPhenoType(iPhenoFinal, oTarget);
            }
        else
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectDisappearAppear(lTarget), oPC, 3.0f);

     //Do Death From Above when landing
    // I assume this was a check for if the PC had the Smash From Above ability
    // uncomment the two lines below if you reinstate something like that.
     int nSmashPower = GetLocalInt(oPC, "DeathAbove");
    // if(nSmashPower)
       AssignCommand(oPC, DelayCommand(5.0, DeathAbove(nSmashPower,lTarget )));
    }
}

void DeathAbove(int nSmashPower, location lTarget)
{

    location lTarget = GetItemActivatedTargetLocation();
    effect eDust = EffectVisualEffect(VFX_IMP_DUST_EXPLOSION);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eDust, lTarget);

    int nNotCreature;
    int nDamage1;
    int nDamage2;
    effect eDamage;
    effect eKD = EffectKnockdown();
    float fDelay;

    float fRadius = 5.0 + IntToFloat(nSmashPower) / 2;
    if(fRadius >= 10.0) fRadius = 10.0;
    object oStomped = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lTarget, FALSE,
                        OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE |
                        OBJECT_TYPE_DOOR);
    while(GetIsObjectValid(oStomped))
    {
        if(GetObjectType(oStomped) == OBJECT_TYPE_PLACEABLE ||
           GetObjectType(oStomped) == OBJECT_TYPE_DOOR)
        {
            nNotCreature = TRUE;
        }

        if(GetIsEnemy(oStomped) || nNotCreature)
        {
            fDelay = GetRandomDelay();

            if(spellsIsFlying(oStomped))
            {
                nDamage1 = d10(nSmashPower);
                nDamage2 = GetReflexAdjustedDamage(nDamage1, oStomped, 15 +
                                    (nSmashPower / 2));
            }
            else
            {
                nDamage1 = d10(nSmashPower + nSmashPower * nNotCreature);
                nDamage2 = GetReflexAdjustedDamage(nDamage1, oStomped, 15 +
                                    nSmashPower);
            }

            eDamage = EffectDamage(nDamage2, DAMAGE_TYPE_BLUDGEONING);
            DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage,
                                oStomped));

            if(nDamage1 == nDamage2)
            {
                DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_TEMPORARY,
                                    eKD, oStomped, GetRandomDelay(3.5, 4.5)));
            }
        }

        oStomped = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lTarget, FALSE,
                        OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE |
                        OBJECT_TYPE_DOOR);
    }
}
  

Modifié par Lightfoot8, 04 septembre 2012 - 11:34 .


#8
valasc

valasc
  • Members
  • 23 messages
You are right, the local init wasn't  being applied. It works fine now. Thanks for all your help!

Modifié par valasc, 04 septembre 2012 - 09:53 .


#9
valasc

valasc
  • Members
  • 23 messages
One more question. why does this line hang up in the compiler?

if (GetResRef(oGun1)=="x") || (GetResRef(oGun1)=="x") ) && GetHasFeat(RAPID_FIRE, oPC))

ERROR: UNKNOWN STATE IN COMPILER

#10
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

valasc wrote...

One more question. why does this line hang up in the compiler?

if (GetResRef(oGun1)=="x") || (GetResRef(oGun1)=="x") ) && GetHasFeat(RAPID_FIRE, oPC))

ERROR: UNKNOWN STATE IN COMPILER


The red and green part is the Expression that is getting evaluated.   The Blue part the compiler is looking at as the Statment to do if the Expression evaluated as true.    It starts with an ||  First error.  The statment does not end with a simicolon second error.     There are more   ')'  then there are '('     Third error.      


Try just adding one more ( after the if 

Modifié par Lightfoot8, 05 septembre 2012 - 03:12 .


#11
valasc

valasc
  • Members
  • 23 messages
Thanks again. I broke it apart and its working now. I am a very novice scripter and you have been a huge help!