Author Topic: Spell Spamming  (Read 692 times)

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Spell Spamming
« Reply #15 on: June 24, 2011, 03:20:47 am »


               Here's the merged code. I used the GetIsNonHostileSpell to limit the timestamping - no idea how well it'll work, since it's in an include I don't have.

I'll let Baaleos add the ActionCast if he wanst - it's a little more involved than he's making out. You'd have to allow cheat casting to save the spell use, which comes with its own set of issues. My normal recommendation would be to simply return the spell use to the player before aborting the spell, but that'd require NWNX.

The modload code works fine. I'm guessing you only put the function in, and never the actual function call to start the delaycommand sequence.



#include "x2_inc_switches"
#include "nw_i0_spells"
#include "check_host_spell"

const int SECONDS_BETWEEN_SPELLS = 9;
void main()
{
    int nSpell=GetSpellId();
    int nNonHostile = GetIsNonHostileSpell(nSpell);
    int nNonHostileItem;
    int nCastLevel = GetCasterLevel(OBJECT_SELF);
    int zInt;

    object sTarget = GetSpellTargetObject();
    object sItem = GetSpellCastItem();
    object oArea = GetArea(oCaster);
    int nJail = GetLocalInt(oArea, "JAIL");
    int nPVP = GetLocalInt(oArea, "PVP");
    location sLocation = GetSpellTargetLocation();
    int sclass = GetLastSpellCastclass();
    string sTN = GetTag(sItem);
    int nType;
    int a;

    //Manual override...
    if(GetLocalInt(oCaster, "OVERRIDE_SPELL")==1) {
        //Stop them cold!
        AssignCommand(oCaster, ClearAllActions());
        //Though the player may show animation, nothing happens! :)
        SetModuleOverrideSpellScriptFinished();
        FloatingTextStringOnCreature("That item is too powerful for you to use!", oCaster, FALSE);
        return;
    }

    if(!GetIsPC(OBJECT_SELF) || GetIsDM(OBJECT_SELF) || GetIsDMPossessed(OBJECT_SELF))
        return; //Stop the script here..

    if (!nNonHostile) {
        int nTime = GetLocalInt(OBJECT_SELF, "LastCastTime");
        int nUptime = GetLocalInt(GetModule(), "Uptime");
        if (nTime) {
            /* because LastCastTime was set, they've cast a spell, and we need to check how long ago that was */
            int nDiff = nUptime-nTime;
            if (nDiff < SECONDS_BETWEEN_SPELLS) {
                DelayCommand(IntToFloat(nDiff),ActionCastSpellAtLocation(nSpellID, lSpell, METAMAGIC_ANY, TRUE));
                SetModuleOverrideSpellScriptFinished();
                SendMessageToPC(OBJECT_SELF, "Spells must be cast at least " +
                    IntToString(SECONDS_BETWEEN_SPELLS) + " seconds apart. Wait " +
                    IntToString(SECONDS_BETWEEN_SPELLS-nDiff) + "more seconds.");
            } else
                SetLocalInt(OBJECT_SELF, "LastCastTime", nUptime);
        } else
            SetLocalInt(OBJECT_SELF, "LastCastTime", nUptime);
    }


    //Handle Jail...
    //NOTHING WORK IN JAIL!!!
    if(nJail==1) {

        //If it's an item!
        if(sItem!=OBJECT_INVALID) {
            AssignCommand(oCaster, ClearAllActions());
            //Though the player may show animation, nothing happens! :)
            SetModuleOverrideSpellScriptFinished();
            return;
        }

        //Otherwise stop the spell COLD!
        else {
            AssignCommand(oCaster, ClearAllActions());
            //Though the player may show animation, nothing happens! :)
            SetModuleOverrideSpellScriptFinished();
            return;
        }
    }

    //////////////////No Spells Allowed In Area///////////////////////////////////
    //If the PC is in a no casting area, no spell will be cast (even from items!)
    //To set up see the above outline
    if(GetLocalInt(GetArea(OBJECT_SELF), "NOCAST")==2) {

        a = 0;

        //If the spell is NOT Hostile then don't stop the spell!
        //Note this code allows the rest of the spell hook to run on the
        //non-hostile spell being cast (in town!)
        if(nNonHostile!=1) {
            a = 1;
        }

        if(a==1) {
            //If using a special power or spell from an item...

            //If it's not the listed special item..
            //& it is in fact a valid object!
            if(sItem!=OBJECT_INVALID &&
                sTN != "ammo_maker"  &&
                sTN != "namingtool" && sTN != "colorwand") {
                nType = GetBaseItemType(GetSpellCastItem());

                if(nType != BASE_ITEM_POTIONS &&
                    nType != BASE_ITEM_ENCHANTED_POTION) {
                    AssignCommand(oCaster, ClearAllActions());
                    //Though the player may show animation, nothing happens! :)
                    SetModuleOverrideSpellScriptFinished();
                    FloatingTextStringOnCreature("All spells fizzle in town.", oCaster);
                    return;
                }
            }

            //Make them stop what they are doing instantly!
            AssignCommand(oCaster, ClearAllActions());
            //Though the player may show animation, nothing happens! :)
            SetModuleOverrideSpellScriptFinished();
            FloatingTextStringOnCreature("You cannot cast that spell in this area.", oCaster);
            return;

        }
    }

    //This is what will happen if the spell was cast from an item..
    if(GetSpellCastItem()!=OBJECT_INVALID) {
        //If the PC uses an item on a PC, and it's one of the following spells
        //Then the spell will not work on the PC, note you can add other effects
        //like if you don't like the spell level restriction of a spell on an item
        //you could add aditional changes to the spell here to boost power. Or, if you
        //don't like some aspect of a spell and don't want players abusing it, you could
        //modify the spell here to run your edited version instead. (copy/paste original)
        //Don't forget to add SetModuleOverrideSpellScriptFinished(); at the end
        //to stop the original script from running.

        //NO ITEMS WORK IN JAIL!!!
        if(GetLocalInt(GetArea(oCaster), "JAIL")==1) {
            AssignCommand(oCaster, ClearAllActions());
            //Though the player may show animation, nothing happens! :)
            SetModuleOverrideSpellScriptFinished();
            return;
        }

        ////////////////////////////////////////////////////////////////////////////
        //Main Script for handling spells
        if(GetIsPC(sTarget)) {
            switch (nSpell) {
                case SPELL_EPIC_RUIN:
                case SPELL_HARM:
                case SPELL_DROWN:
                    if(GetIsPC(sTarget)) {
                        //Don't Cast the original spell
                        AssignCommand(oCaster, ClearAllActions());
                        SetModuleOverrideSpellScriptFinished();
                    }
                break;
            }
        }
    } //End if statment for items

///////////Modifications For All Individual Spells////////////////////////
    switch(nSpell) {
        case SPELL_ETHEREALNESS:
        case SPELL_SANCTUARY:
            if(nPVP>0) {
                SetModuleOverrideSpellScriptFinished();
                FloatingTextStringOnCreature("Sanctuary is an illegal spell in PVP Areas.", oCaster);
            }
        break;
        case SPELL_TIME_STOP:
            if(nPVP>=1) {
                FloatingTextStringOnCreature("Timestop is not allowed in PVP Areas.", OBJECT_SELF, TRUE);
                SetModuleOverrideSpellScriptFinished();
            }
        break;
    }
}

               
               

               
            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Spell Spamming
« Reply #16 on: June 24, 2011, 12:54:15 pm »


               Funky,
This does not compile getting error ERROR: PARSING VARIABLE LIST
 
If it helps I am using NWNX2
               
               

               


                     Modifié par Madasahatter, 24 juin 2011 - 11:55 .
                     
                  


            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Spell Spamming
« Reply #17 on: June 24, 2011, 01:07:14 pm »


               hear is the include file - check_host_spell


//PROTOTYPE DEFINED
int GetIsNonHostileSpell(int nSpell)
{
int nNonHostile = 0;

//Spells that will not be allowed to target other players..
switch (nSpell)
{
case SPELL_ACTIVATE_ITEM_SELF2: {  nNonHostile = 1; }break;
case SPELL_AID: {  nNonHostile = 1; }break;
case SPELL_AMPLIFY: {  nNonHostile = 1; }break;
case SPELL_AURA_OF_VITALITY: {  nNonHostile = 1; }break;
case SPELL_AWAKEN: {  nNonHostile = 1; }break;
case SPELL_AURAOFGLORY: {  nNonHostile = 1; }break;
case SPELL_BARKSKIN: {  nNonHostile = 1; }break;
case SPELL_BATTLETIDE: {  nNonHostile = 1; }break;
case SPELL_BLESS: {  nNonHostile = 1; }break;
case SPELL_BLESS_WEAPON: {  nNonHostile = 1; }break;
case SPELL_BLOOD_FRENZY: {  nNonHostile = 1; }break;
case SPELL_BULLS_STRENGTH: {  nNonHostile = 1; }break;
case SPELL_CAMOFLAGE: {  nNonHostile = 1; }break;
case SPELL_CATS_GRACE: {  nNonHostile = 1; }break;
case SPELL_CLAIRAUDIENCE_AND_CLAIRVOYANCE: {  nNonHostile = 1; }break;
case SPELL_CLARITY: {  nNonHostile = 1; }break;
case SPELL_CONTINUAL_FLAME: {  nNonHostile = 1; }break;
case SPELL_CRAFT_ADD_ITEM_PROPERTY: {  nNonHostile = 1; }break;
case SPELL_CRAFT_HARPER_ITEM: {  nNonHostile = 1; }break;
case SPELL_CURE_CRITICAL_WOUNDS: {  nNonHostile = 1; }break;
case SPELL_CURE_LIGHT_WOUNDS: {  nNonHostile = 1; }break;
case SPELL_CURE_MINOR_WOUNDS: {  nNonHostile = 1; }break;
case SPELL_CURE_MODERATE_WOUNDS: {  nNonHostile = 1; }break;
case SPELL_CURE_SERIOUS_WOUNDS: {  nNonHostile = 1; }break;
case SPELL_DARKFIRE: {  nNonHostile = 1; }break;
case SPELL_DARKVISION: {  nNonHostile = 1; }break;
case SPELL_DEATH_ARMOR: {  nNonHostile = 1; }break;
case SPELL_DEATH_WARD: {  nNonHostile = 1; }break;
case SPELL_DISPLACEMENT: {  nNonHostile = 1; }break;
case SPELL_DIVINE_FAVOR: {  nNonHostile = 1; }break;
case SPELL_DIVINE_MIGHT: {  nNonHostile = 1; }break;
case SPELL_DIVINE_POWER: {  nNonHostile = 1; }break;
case SPELL_DIVINE_SHIELD: {  nNonHostile = 1; }break;
case SPELL_EAGLE_SPLEDOR: {  nNonHostile = 1; }break;
case SPELL_ELEMENTAL_SHIELD: {  nNonHostile = 1; }break;
case SPELL_ENDURANCE: {  nNonHostile = 1; }break;
case SPELL_ENDURE_ELEMENTS: {  nNonHostile = 1; }break;
case SPELL_ENERGY_BUFFER: {  nNonHostile = 1; }break;
case SPELL_ENTROPIC_SHIELD: {  nNonHostile = 1; }break;
case SPELL_EPIC_MAGE_ARMOR: {  nNonHostile = 1; }break;
case SPELL_ETHEREAL_VISAGE: {  nNonHostile = 1; }break;
case SPELL_ETHEREALNESS: {  nNonHostile = 1; }break;
case SPELL_EXPEDITIOUS_RETREAT: {  nNonHostile = 1; }break;
case SPELL_FLAME_WEAPON: {  nNonHostile = 1; }break;
case SPELL_FOXS_CUNNING: {  nNonHostile = 1; }break;
case SPELL_FREEDOM_OF_MOVEMENT: {  nNonHostile = 1; }break;
case SPELL_GHOSTLY_VISAGE: {  nNonHostile = 1; }break;
case SPELL_GLOBE_OF_INVULNERABILITY: {  nNonHostile = 1; }break;
case SPELL_GREATER_BULLS_STRENGTH: {  nNonHostile = 1; }break;
case SPELL_GREATER_CATS_GRACE: {  nNonHostile = 1; }break;
case SPELL_GREATER_EAGLE_SPLENDOR: {  nNonHostile = 1; }break;
case SPELL_GREATER_ENDURANCE: {  nNonHostile = 1; }break;
case SPELL_GREATER_FOXS_CUNNING: {  nNonHostile = 1; }break;
case SPELL_GREATER_MAGIC_FANG: {  nNonHostile = 1; }break;
case SPELL_GREATER_MAGIC_WEAPON: {  nNonHostile = 1; }break;
case SPELL_GREATER_OWLS_WISDOM: {  nNonHostile = 1; }break;
case SPELL_GREATER_RESTORATION: {  nNonHostile = 1; }break;
case SPELL_GREATER_SPELL_MANTLE: {  nNonHostile = 1; }break;
case SPELL_GREATER_STONESKIN: {  nNonHostile = 1; }break;
case SPELL_HASTE: {  nNonHostile = 1; }break;
case SPELL_HEAL: {  nNonHostile = 1; }break;
case SPELL_HEALING_CIRCLE: {  nNonHostile = 1; }break;
case SPELL_HEALING_STING: {  nNonHostile = 1; }break;
case SPELL_HEALINGKIT: {  nNonHostile = 1; }break;
case SPELL_HOLY_AURA: {  nNonHostile = 1; }break;
case SPELL_HOLY_SWORD: {  nNonHostile = 1; }break;
case SPELL_IDENTIFY: {  nNonHostile = 1; }break;
case SPELL_IMPROVED_INVISIBILITY: {  nNonHostile = 1; }break;
case SPELL_INVISIBILITY: {  nNonHostile = 1; }break;
case SPELL_INVISIBILITY_PURGE: {  nNonHostile = 1; }break;
case SPELL_INVISIBILITY_SPHERE: {  nNonHostile = 1; }break;
case SPELL_IRONGUTS: {  nNonHostile = 1; }break;
case SPELL_KEEN_EDGE: {  nNonHostile = 1; }break;
case SPELL_LEGEND_LORE: {  nNonHostile = 1; }break;
case SPELL_LESSER_MIND_BLANK: {  nNonHostile = 1; }break;
case SPELL_LESSER_RESTORATION: {  nNonHostile = 1; }break;
case SPELL_LESSER_SPELL_MANTLE: {  nNonHostile = 1; }break;
case SPELL_LIGHT: {  nNonHostile = 1; }break;
case SPELL_MAGE_ARMOR: {  nNonHostile = 1; }break;
case SPELL_MAGIC_CIRCLE_AGAINST_CHAOS: {  nNonHostile = 1; }break;
case SPELL_MAGIC_CIRCLE_AGAINST_EVIL: {  nNonHostile = 1; }break;
case SPELL_MAGIC_CIRCLE_AGAINST_GOOD: {  nNonHostile = 1; }break;
case SPELL_MAGIC_CIRCLE_AGAINST_LAW: {  nNonHostile = 1; }break;
case SPELL_MAGIC_FANG: {  nNonHostile = 1; }break;
case SPELL_MAGIC_VESTMENT: {  nNonHostile = 1; }break;
case SPELL_MASS_CAMOFLAGE: {  nNonHostile = 1; }break;
case SPELL_MASS_HASTE: {  nNonHostile = 1; }break;
case SPELL_MASS_HEAL: {  nNonHostile = 1; }break;
case SPELL_MESTILS_ACID_SHEATH: {  nNonHostile = 1; }break;
case SPELL_MIND_BLANK: {  nNonHostile = 1; }break;
case SPELL_MINOR_GLOBE_OF_INVULNERABILITY: {  nNonHostile = 1; }break;
case SPELL_MONSTROUS_REGENERATION: {  nNonHostile = 1; }break;
case SPELL_NEGATIVE_ENERGY_PROTECTION: {  nNonHostile = 1; }break;
case SPELL_NEUTRALIZE_POISON: {  nNonHostile = 1; }break;
case SPELL_ONE_WITH_THE_LAND: {  nNonHostile = 1; }break;
case SPELL_OWLS_INSIGHT: {  nNonHostile = 1; }break;
case SPELL_OWLS_WISDOM: {  nNonHostile = 1; }break;
case SPELL_PRAYER: {  nNonHostile = 1; }break;
case SPELL_PREMONITION: {  nNonHostile = 1; }break;
case SPELL_PROTECTION__FROM_CHAOS: {  nNonHostile = 1; }break;
case SPELL_PROTECTION_FROM_ELEMENTS: {  nNonHostile = 1; }break;
case SPELL_PROTECTION_FROM_EVIL: {  nNonHostile = 1; }break;
case SPELL_PROTECTION_FROM_GOOD: {  nNonHostile = 1; }break;
case SPELL_PROTECTION_FROM_LAW: {  nNonHostile = 1; }break;
case SPELL_PROTECTION_FROM_SPELLS: {  nNonHostile = 1; }break;
case SPELL_RAISE_DEAD: {  nNonHostile = 1; }break;
case SPELL_REGENERATE: {  nNonHostile = 1; }break;
case SPELL_REMOVE_BLINDNESS_AND_DEAFNESS: {  nNonHostile = 1; }break;
case SPELL_REMOVE_CURSE: {  nNonHostile = 1; }break;
case SPELL_REMOVE_DISEASE: {  nNonHostile = 1; }break;
case SPELL_REMOVE_FEAR: {  nNonHostile = 1; }break;
case SPELL_REMOVE_PARALYSIS: {  nNonHostile = 1; }break;
case SPELL_RESIST_ELEMENTS: {  nNonHostile = 1; }break;
case SPELL_RESISTANCE: {  nNonHostile = 1; }break;
case SPELL_RESTORATION: {  nNonHostile = 1; }break;
case SPELL_RESURRECTION: {  nNonHostile = 1; }break;
case SPELL_SANCTUARY: {  nNonHostile = 1; }break;
case SPELL_SEE_INVISIBILITY: {  nNonHostile = 1; }break;
case SPELL_SHADES_STONESKIN: {  nNonHostile = 1; }break;
case SPELL_SHADOW_CONJURATION_INIVSIBILITY: {  nNonHostile = 1; }break;
case SPELL_SHADOW_CONJURATION_MAGE_ARMOR: {  nNonHostile = 1; }break;
case SPELL_SHADOW_EVADE: {  nNonHostile = 1; }break;
case SPELL_SHADOW_SHIELD: {  nNonHostile = 1; }break;
case SPELL_SHIELD: {  nNonHostile = 1; }break;
case SPELL_SHIELD_OF_FAITH: {  nNonHostile = 1; }break;
case SPELL_SHIELD_OF_LAW: {  nNonHostile = 1; }break;
case SPELL_SPELL_MANTLE: {  nNonHostile = 1; }break;
case SPELL_SPELL_RESISTANCE: {  nNonHostile = 1; }break;
case SPELL_SPELLSTAFF: {  nNonHostile = 1; }break;
case SPELL_STONE_BONES: {  nNonHostile = 1; }break;
case SPELL_STONE_TO_FLESH: {  nNonHostile = 1; }break;
case SPELL_STONESKIN: {  nNonHostile = 1; }break;
case SPELL_TRUE_SEEING: {  nNonHostile = 1; }break;
case SPELL_TRUE_STRIKE: {  nNonHostile = 1; }break;
case SPELL_TYMORAS_SMILE: {  nNonHostile = 1; }break;
case SPELL_UNDEATHS_ETERNAL_FOE: {  nNonHostile = 1; }break;
case SPELL_UNHOLY_AURA: {  nNonHostile = 1; }break;
case SPELL_VINE_MINE_CAMOUFLAGE: {  nNonHostile = 1; }break;
case SPELL_VIRTUE: {  nNonHostile = 1; }break;
case SPELL_WOUNDING_WHISPERS: {  nNonHostile = 1; }break;

//End switch statement
}
//Debugging (It worked fine!)
//WriteTimestampedLogEntry("***NON-HOSTILE-SPELL-CHECK*** = " + IntToString(nNonHostile) +
//" / " + IntToString(nSpell));

return nNonHostile;

//END PROTOTYPE
}
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Spell Spamming
« Reply #18 on: June 24, 2011, 03:59:00 pm »


               Unless you give me the whole check_host_spell include and any other scripts that one includes, you'll have to compile this yourself, by reading the errors and fixing them accordingly. It's likely a missing semicolon, double quote, paren, or something of the like.

Funky
               
               

               


                     Modifié par FunkySwerve, 24 juin 2011 - 03:00 .
                     
                  


            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Spell Spamming
« Reply #19 on: June 24, 2011, 10:50:12 pm »


               I seem to have this working through Modload and all compiled, I will test for a bit and let you all know how I get on. Had to change sclass to sCalss and comment out DelayCommand(IntToFloat(nDiff),ActionCastSpellAtLocation(nSpellID, to get it to compile. seems to be working so far.

Thanks Funky
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Spell Spamming
« Reply #20 on: June 24, 2011, 11:19:14 pm »


               Oh, sorry, I forgot to mention, I put that in as a partial example of Baaleos' idea, but accidentally removed some of the needed vars during cleanup and indenting of the function.

To make it fully work, you would need to distinguish first whether the spell had an object target, and CastAtObject, otherwise at Location. You would also have to decide how to handle items, deal with any Cheat casting issues, and various other minutiae.

Whoever gave you that sample spellhook...eh. It had, shall we say, some issues. I cleaned it up as best I could - having a ton of switches you aren't using makes no sense - just add them as you need them. If I was doing it for my mod, I would've taken a lot more time and restructured it. The way he treats item casting at present is fairly poor from a flow-control perspective, even after my minor restructuring. More specifically, it makes handling item casting with respect to cast-blocking awkward, as well as potential future modifications.

Funky
               
               

               


                     Modifié par FunkySwerve, 24 juin 2011 - 10:21 .