Author Topic: VFX additions  (Read 322 times)

Legacy_Jenna WSI

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
VFX additions
« on: July 11, 2012, 07:28:13 pm »


               Trying to add new vfx to this script, what do I need to do?

// Visual Effect constants

const int HEAD_EFFECTS_HELM     = 0;
const int HEAD_EFFECTS_EYES     = 1;
const int HEAD_EFFECTS_HORNS    = 2;
const int HEAD_EFFECTS_ALL      = 3;

// Helms:
const int HELM_05 = 0;
const int HELM_08 = 1;
const int HELM_09 = 2;
const int HELM_12 = 3;
const int HELM_13 = 4;
const int HELM_14 = 5;
const int HELM_16 = 6;
const int HELM_17 = 7;
const int HELM_20 = 8;
const int HELM_24 = 9;
const int HELM_28 = 10;
const int HELM_29 = 11;
const int HELM_30 = 12;
const int HELM_32 = 13;

// Eyes:
const int EYES_RED      = 14;
const int EYES_BLUE     = 15;
const int EYES_PURPLE   = 16;
const int EYES_GREEN    = 17;
const int EYES_YELLOW   = 18;
const int EYES_WHITE    = 19;
const int EYES_ORANGE   = 20;

// Horns:
const int HORNS_MEPH    = 21;
const int HORNS_OX      = 22;
const int HORNS_ROTHE   = 23;
const int HORNS_BALOR   = 24;
const int HORNS_ANTLERS = 25;
const int HORNS_DRAGON  = 26;
const int HORNS_RAM     = 27;


int getEffectIndex(object oTarget);
void applyHeadEffectToObject(int effectNum, object oTarget);
void restoreHeadEffects(object oTarget);
void removeHeadEffectsFromObject(object oTarget, int effectType = HEAD_EFFECTS_ALL);


// Use with GetGenderModifier() to locate the index
// in visualeffects.2da of the effect to apply
// Locate the index in visualeffects.2da of the effect to apply
int getEffectIndex(object oTarget)
{
    int PCRace = GetRacialType(oTarget);
    int PCGender = GetGender(oTarget);

    int raceMod, genderMod;

    switch (PCRace)
    {
    case RACIAL_TYPE_HUMAN:
        raceMod = 8192;
        break;
    case RACIAL_TYPE_ELF:
        raceMod = 8220;
        break;
    case RACIAL_TYPE_DWARF:
        raceMod = 8248;
        break;
    case RACIAL_TYPE_HALFLING:
        raceMod = 8276;
        break;
    case RACIAL_TYPE_GNOME:
        raceMod = 8304;
        break;
    case RACIAL_TYPE_HALFELF:
        raceMod = 8192;
        break;
    case RACIAL_TYPE_HALFORC:
        raceMod = 8332;
        break;
    default:
        SendMessageToPC(oTarget, "Warning: you are not a supported race. Only human, elf, dwarf, halfling, gnome, half-elf and half-orc characters are supported.");
        raceMod = 567;
        break;
    }

    switch (PCGender)
    {
    case GENDER_FEMALE:
        genderMod = 28;
        break;
    case GENDER_MALE:
        genderMod = 0;
        break;
    default:
        SendMessageToPC(oTarget, "Warning: you are not a supported gender. Only female and male characters are supported.");
        genderMod = 0;
        break;
    }
    int effectIndex = raceMod + genderMod;
    return effectIndex;
}


// Applies the head effect to the target object and assigns a local int
// to the target object to store the current effect
void applyHeadEffectToObject(int effectNum, object oTarget)
{
    string effectType;

    if (effectNum <= HELM_32)
        effectType = "HelmEffect";
    else if (effectNum <= EYES_ORANGE)
        effectType = "EyeEffect";
    else if (effectNum <= HORNS_RAM)
        effectType = "HornEffect";
    else effectType = "ERROR";

    if (effectType == "ERROR") {
        SendMessageToPC(oTarget, "Warning: you are attempting to assign an undefined head effect. Check the values you are passing to applyHeadEffectToObject().");
    } else {
        effectNum += getEffectIndex(oTarget);
        effect eEffect = EffectVisualEffect(effectNum);
        eEffect = SupernaturalEffect(eEffect);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oTarget);
        SetLocalInt(oTarget, effectType, effectNum);
    }
}


// Restores head effects after an object's visual effects are removed
// Called by module's rest and respawn scripts
void restoreHeadEffects(object oTarget)
{
    int indexMod;
    int helmToRestore = GetLocalInt(oTarget, "HelmEffect");
    int eyesToRestore = GetLocalInt(oTarget, "EyeEffect");
    int hornsToRestore = GetLocalInt(oTarget, "HornEffect");

    effect effectToRestore;

    indexMod = getEffectIndex(oTarget);

    if (helmToRestore >= HELM_05 + indexMod && helmToRestore <= HELM_32 + indexMod) {
        effectToRestore = EffectVisualEffect(helmToRestore);
        effectToRestore = SupernaturalEffect(effectToRestore);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, effectToRestore, oTarget);
    }
    if (eyesToRestore >= EYES_RED + indexMod && eyesToRestore <= EYES_ORANGE + indexMod) {
        effectToRestore = EffectVisualEffect(eyesToRestore);
        effectToRestore = SupernaturalEffect(effectToRestore);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, effectToRestore, oTarget);
    }
    if (hornsToRestore >= HORNS_MEPH + indexMod && hornsToRestore <= HORNS_RAM + indexMod) {
        effectToRestore = EffectVisualEffect(hornsToRestore);
        effectToRestore = SupernaturalEffect(effectToRestore);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, effectToRestore, oTarget);
    }
}

// This function removes head effects from the target object
// Pass HEAD_EFFECTS_HELM to this function to remove the helmet effect
// Pass HEAD_EFFECTS_EYES to remove the eyes effect
// Pass HEAD_EFFECTS_HORNS to remove the horns effect
// Pass HEAD_EFFECTS_ALL to remove all head effects
void removeHeadEffectsFromObject(object oTarget, int effectType = HEAD_EFFECTS_ALL)
{
    string effectTypeToRemove;
    int effectToPreserve;
    int effectToRemove;
    int indexMod;

    indexMod = getEffectIndex(oTarget);
    effect eLoop=GetFirstEffect(oTarget);

    while (GetIsEffectValid(eLoop)) {
         if (GetEffectType(eLoop) == EFFECT_TYPE_VISUALEFFECT)
            RemoveEffect(oTarget, eLoop);
        eLoop=GetNextEffect(oTarget);
    }

    switch (effectType) {

    case HEAD_EFFECTS_HELM:
        DeleteLocalInt(oTarget, "HelmEffect");
        restoreHeadEffects(oTarget);
        break;

    case HEAD_EFFECTS_EYES:
        DeleteLocalInt(oTarget, "EyeEffect");
        restoreHeadEffects(oTarget);
        break;

    case HEAD_EFFECTS_HORNS:
        DeleteLocalInt(oTarget, "HornEffect");
        restoreHeadEffects(oTarget);
        break;

    default:
        DeleteLocalInt(oTarget, "HelmEffect");
        DeleteLocalInt(oTarget, "EyeEffect");
        DeleteLocalInt(oTarget, "HornEffect");
        break;
    }

}



4968 VFX_DUR_GLASSES_MA                       D       0                vfx_glasses_ma   ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4969 VFX_DUR_GLASSES_MD                       D       0                vfx_glasses_md   ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4970 VFX_DUR_GLASSES_ME                       D       0                vfx_glasses_me   ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4971 VFX_DUR_GLASSES_MG                       D       0                vfx_glasses_mg   ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4972 VFX_DUR_GLASSES_MH                       D       0                vfx_glasses_mh   ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4973 VFX_DUR_GLASSES_MO                       D       0                vfx_glasses_mo   ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4974 VFX_DUR_SHADES_MA                        D       0                vfx_shades_ma    ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4975 VFX_DUR_SHADES_MD                        D       0                vfx_shades_md    ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4976 VFX_DUR_SHADES_ME                        D       0                vfx_shades_me    ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4977 VFX_DUR_SHADES_MG                        D       0                vfx_shades_mg    ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4978 VFX_DUR_SHADES_MH                        D       0                vfx_shades_mh    ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            
4979 VFX_DUR_SHADES_MO                        D       0                vfx_shades_mo    ****             ****            ****              ****             ****             ****          ****             ****            ****             ****             ****            ****             ****            ****            ****            ****            ****            ****      ****       ****          ****        ****             ****            

               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
VFX additions
« Reply #1 on: July 12, 2012, 06:32:11 am »


               Well I suppose I could take a stab at this.

I'm assuming that the chunk of 2da that you posted on the bottom is for glasses & shades FX for MALEs of each race?
And I'm also assuming that these added effects are not in the same sequential order as the effects for the horns, helms and eyes?

If I thought things out correctly perhaps something like the following might work. I had to tweak it quite a bit since the effects are not in sequential order in the 2da. So it got a bit tricky with the "getEffectIndex" function. Hopefully I thought things out correctly. A second or third pair of scripting eyes on this would be nice just to make sure.


// Visual Effect constants

const int HEAD_EFFECTS_HELM     = 0;
const int HEAD_EFFECTS_EYES     = 1;
const int HEAD_EFFECTS_HORNS    = 2;
const int HEAD_EFFECTS_GLASSES  = 3;
const int HEAD_EFFECTS_ALL      = 4;

// Helms:
const int HELM_05 = 0;
const int HELM_08 = 1;
const int HELM_09 = 2;
const int HELM_12 = 3;
const int HELM_13 = 4;
const int HELM_14 = 5;
const int HELM_16 = 6;
const int HELM_17 = 7;
const int HELM_20 = 8;
const int HELM_24 = 9;
const int HELM_28 = 10;
const int HELM_29 = 11;
const int HELM_30 = 12;
const int HELM_32 = 13;

// Eyes:
const int EYES_RED      = 14;
const int EYES_BLUE     = 15;
const int EYES_PURPLE   = 16;
const int EYES_GREEN    = 17;
const int EYES_YELLOW   = 18;
const int EYES_WHITE    = 19;
const int EYES_ORANGE   = 20;

// Horns:
const int HORNS_MEPH    = 21;
const int HORNS_OX      = 22;
const int HORNS_ROTHE   = 23;
const int HORNS_BALOR   = 24;
const int HORNS_ANTLERS = 25;
const int HORNS_DRAGON  = 26;
const int HORNS_RAM     = 27;

//ADDED!!
// Glasses & Shades:
const int GLASSES_M_1   = 28;
const int GLASSES_M_2   = 29;
const int GLASSES_M_3   = 30;
const int GLASSES_M_4   = 31;
const int GLASSES_M_5   = 32;
const int GLASSES_M_6   = 33;
const int GLASSES_M_7   = 34;
const int GLASSES_M_8   = 35;
const int GLASSES_M_9   = 36;
const int GLASSES_M_10  = 37;
const int GLASSES_M_11  = 38;
const int GLASSES_M_12  = 39;


int getEffectIndex(object oTarget, string sString);//ADDED NEW PERAMETER!!
void applyHeadEffectToObject(int effectNum, object oTarget);
void restoreHeadEffects(object oTarget);
void removeHeadEffectsFromObject(object oTarget, int effectType = HEAD_EFFECTS_ALL);


// Use with GetGenderModifier() to locate the index
// in visualeffects.2da of the effect to apply
// Locate the index in visualeffects.2da of the effect to apply
int getEffectIndex(object oTarget, string effectType)
{
    int PCRace = GetRacialType(oTarget);
    int PCGender = GetGender(oTarget);

    int raceMod, genderMod, effectIndex;

    if (effectType == "HelmEffect" ||
        effectType == "EyeEffect"  ||
        effectType == "HornEffect")
    {
        switch (PCRace)
        {
            case RACIAL_TYPE_HUMAN:    raceMod = 8192; break;
            case RACIAL_TYPE_ELF:      raceMod = 8220; break;
            case RACIAL_TYPE_DWARF:    raceMod = 8248; break;
            case RACIAL_TYPE_HALFLING: raceMod = 8276; break;
            case RACIAL_TYPE_GNOME:    raceMod = 8304; break;
            case RACIAL_TYPE_HALFELF:  raceMod = 8192; break;
            case RACIAL_TYPE_HALFORC:  raceMod = 8332; break;
            default:
            SendMessageToPC(oTarget, "Warning: you are not a supported race. Only human, elf, dwarf, halfling, gnome, half-elf and half-orc characters are supported.");
            raceMod = 567;
            break;
        }

        switch (PCGender)
        {
            case GENDER_FEMALE: genderMod = 28; break;
            case GENDER_MALE:   genderMod = 0;  break;
            default:
            SendMessageToPC(oTarget, "Warning: you are not a supported gender. Only female and male characters are supported.");
            genderMod = 0;
            break;
        }
        effectIndex = raceMod + genderMod;
    }

    if (effectType == "GlassesEffect")
    {
        switch (PCRace)
        {
            case RACIAL_TYPE_HUMAN:    raceMod = 4940; break;
            case RACIAL_TYPE_ELF:      raceMod = 4942; break;
            case RACIAL_TYPE_DWARF:    raceMod = 4941; break;
            case RACIAL_TYPE_HALFLING: raceMod = 4944; break;
            case RACIAL_TYPE_GNOME:    raceMod = 4943; break;
            case RACIAL_TYPE_HALFELF:  raceMod = 4940; break;
            case RACIAL_TYPE_HALFORC:  raceMod = 4945; break;
            default:
            SendMessageToPC(oTarget, "Warning: you are not a supported race. Only human, elf, dwarf, halfling, gnome, half-elf and half-orc characters are supported.");
            raceMod = 567;
            break;
        }

        switch (PCGender)
        {
            case GENDER_FEMALE: genderMod = 12; break;
            case GENDER_MALE:   genderMod = 0;  break;
            default:
            SendMessageToPC(oTarget, "Warning: you are not a supported gender. Only female and male characters are supported.");
            genderMod = 0;
            break;
        }
        effectIndex = raceMod + genderMod;
    }
    return effectIndex;
}


// Applies the head effect to the target object and assigns a local int
// to the target object to store the current effect
void applyHeadEffectToObject(int effectNum, object oTarget)
{
    string effectType;

    if (effectNum <= HELM_32)
        effectType = "HelmEffect";
    else if (effectNum <= EYES_ORANGE)
        effectType = "EyeEffect";
    else if (effectNum <= HORNS_RAM)
        effectType = "HornEffect";
    else if (effectNum <= GLASSES_M_12)//ADDED!!
        effectType = "GlassesEffect";//ADDED!!
    else effectType = "ERROR";

    if (effectType == "ERROR") {
        SendMessageToPC(oTarget, "Warning: you are attempting to assign an undefined head effect. Check the values you are passing to applyHeadEffectToObject().");
    } else {
        effectNum += getEffectIndex(oTarget, effectType);
        effect eEffect = EffectVisualEffect(effectNum);
        eEffect = SupernaturalEffect(eEffect);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oTarget);
        SetLocalInt(oTarget, effectType, effectNum);
    }
}


// Restores head effects after an object's visual effects are removed
// Called by module's rest and respawn scripts
void restoreHeadEffects(object oTarget)
{
    string effectType;
    int indexMod;
    effect effectToRestore;

    int helmToRestore = GetLocalInt(oTarget, "HelmEffect");
    indexMod = getEffectIndex(oTarget, "HelmEffect");
    if (helmToRestore >= HELM_05 + indexMod && helmToRestore <= HELM_32 + indexMod) {
        effectToRestore = EffectVisualEffect(helmToRestore);
        effectToRestore = SupernaturalEffect(effectToRestore);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, effectToRestore, oTarget);
    }

    int eyesToRestore = GetLocalInt(oTarget, "EyeEffect");
    indexMod = getEffectIndex(oTarget, "EyeEffect");
    if (eyesToRestore >= EYES_RED + indexMod && eyesToRestore <= EYES_ORANGE + indexMod) {
        effectToRestore = EffectVisualEffect(eyesToRestore);
        effectToRestore = SupernaturalEffect(effectToRestore);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, effectToRestore, oTarget);
    }

    int hornsToRestore = GetLocalInt(oTarget, "HornEffect");
    indexMod = getEffectIndex(oTarget, "HornEffect");
    if (hornsToRestore >= HORNS_MEPH + indexMod && hornsToRestore <= HORNS_RAM + indexMod) {
        effectToRestore = EffectVisualEffect(hornsToRestore);
        effectToRestore = SupernaturalEffect(effectToRestore);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, effectToRestore, oTarget);
    }

    int shadesToRestore = GetLocalInt(oTarget, "GlassesEffect");//ADDED!!
    indexMod = getEffectIndex(oTarget, "GlassesEffect");//ADDED!!
    //ADDED!!
    if (shadesToRestore >= GLASSES_M_1 + indexMod && shadesToRestore <= GLASSES_M_12 + indexMod) {
        effectToRestore = EffectVisualEffect(shadesToRestore);
        effectToRestore = SupernaturalEffect(effectToRestore);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, effectToRestore, oTarget);
    }
}

// This function removes head effects from the target object
// Pass HEAD_EFFECTS_HELM to this function to remove the helmet effect
// Pass HEAD_EFFECTS_EYES to remove the eyes effect
// Pass HEAD_EFFECTS_HORNS to remove the horns effect
// Pass HEAD_EFFECTS_GLASSES to remove the glasses effect //ADDED!
// Pass HEAD_EFFECTS_ALL to remove all head effects
void removeHeadEffectsFromObject(object oTarget, int effectType = HEAD_EFFECTS_ALL)
{
    effect eLoop = GetFirstEffect(oTarget);

    while (GetIsEffectValid(eLoop)) {
         if (GetEffectType(eLoop) == EFFECT_TYPE_VISUALEFFECT)
            RemoveEffect(oTarget, eLoop);
        eLoop=GetNextEffect(oTarget);
    }

    switch (effectType) {

    case HEAD_EFFECTS_HELM:
        DeleteLocalInt(oTarget, "HelmEffect");
        restoreHeadEffects(oTarget);
        break;

    case HEAD_EFFECTS_EYES:
        DeleteLocalInt(oTarget, "EyeEffect");
        restoreHeadEffects(oTarget);
        break;

    case HEAD_EFFECTS_HORNS:
        DeleteLocalInt(oTarget, "HornEffect");
        restoreHeadEffects(oTarget);
        break;
    //ADDED!!
    case HEAD_EFFECTS_GLASSES:
        DeleteLocalInt(oTarget, "GlassesEffect");
        restoreHeadEffects(oTarget);
        break;

    default:
        DeleteLocalInt(oTarget, "HelmEffect");
        DeleteLocalInt(oTarget, "EyeEffect");
        DeleteLocalInt(oTarget, "HornEffect");
        DeleteLocalInt(oTarget, "GlassesEffect");//ADDED!!
        break;
    }

}



I added functionality for future female models as well. The way I altered it would also make it a bit easier to add future head FX.

In that last function I took out some declared (but not assigned) variables. You might want to think about using a specific effect creator for these particular type of effects. Maybe a different object for each type. Then just check for GetEffectCreator when you want to remove specific ones. Just a thought. As it is now the function to remove the effects will remove all visual effects even if they have nothing to do with these.

Hopefully this works out for ya.
               
               

               


                     Modifié par GhostOfGod, 12 juillet 2012 - 07:13 .
                     
                  


            

Legacy_Jenna WSI

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
VFX additions
« Reply #2 on: July 12, 2012, 03:23:11 pm »


               I think I see what you did there, okay!

"In that last function I took out some declared (but not assigned) variables. You might want to think about using a specific effect creator for these particular type of effects. Maybe a different object for each type. Then just check for GetEffectCreator when you want to remove specific ones. Just a thought. As it is now the function to remove the effects will remove all visual effects even if they have nothing to do with these"

Have no idea what this means. I can't script, I'm only able to look at scripts and tweak them.. and they sometimes do what I want. '<img'>