Author Topic: Need some help with script  (Read 369 times)

Legacy_valasc

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need some help with script
« on: September 03, 2012, 04:19:02 pm »


               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 .
                     
                  


            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Need some help with script
« Reply #1 on: September 03, 2012, 05:19:21 pm »


               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);
               
               

               
            

Legacy_valasc

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need some help with script
« Reply #2 on: September 03, 2012, 07:09:13 pm »


               Mistype. Corrected in original post.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need some help with script
« Reply #3 on: September 03, 2012, 07:49:42 pm »


               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.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Need some help with script
« Reply #4 on: September 03, 2012, 09:07:55 pm »


               Edit: nevermind.
               
               

               


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


            

Legacy_valasc

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need some help with script
« Reply #5 on: September 04, 2012, 02:43:19 am »


               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?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need some help with script
« Reply #6 on: September 04, 2012, 03:50:29 am »


               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 .
                     
                  


            

Legacy_valasc

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need some help with script
« Reply #7 on: September 04, 2012, 10:35:19 pm »


               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 .
                     
                  


            

Legacy_valasc

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need some help with script
« Reply #8 on: September 05, 2012, 01:37:29 am »


               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
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need some help with script
« Reply #9 on: September 05, 2012, 04:03:39 am »


               

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 .
                     
                  


            

Legacy_valasc

  • Newbie
  • *
  • Posts: 39
  • Karma: +0/-0
Need some help with script
« Reply #10 on: September 06, 2012, 02:16:11 am »


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