Help with a Creature Script

Hello. I am looking for a bit of help with a script. I’ve enabled Flying everywhere with a sql to give players a mount:

Spell 31700 Black Qiraji Battle Tank

SQL:

DELETE FROM item_template WHERE entry = 987654;

INSERT INTO item_template (entry, class, subclass, name, displayid, Quality, Flags, FlagsExtra, BuyCount, BuyPrice, SellPrice, InventoryType, AllowableClass, AllowableRace, ItemLevel, RequiredLevel, RequiredSkill, RequiredSkillRank, requiredspell, requiredhonorrank, RequiredCityRank, RequiredReputationFaction, RequiredReputationRank, maxcount, stackable, ContainerSlots, StatsCount, stat_type1, stat_value1, stat_type2, stat_value2, stat_type3, stat_value3, stat_type4, stat_value4, stat_type5, stat_value5, stat_type6, stat_value6, stat_type7, stat_value7, stat_type8, stat_value8, stat_type9, stat_value9, stat_type10, stat_value10, ScalingStatDistribution, ScalingStatValue, dmg_min1, dmg_max1, dmg_type1, dmg_min2, dmg_max2, dmg_type2, armor, holy_res, fire_res, nature_res, frost_res, shadow_res, arcane_res, delay, ammo_type, RangedModRange, spellid_1, spelltrigger_1, spellcharges_1, spellppmRate_1, spellcooldown_1, spellcategory_1, spellcategorycooldown_1, spellid_2, spelltrigger_2, spellcharges_2, spellppmRate_2, spellcooldown_2, spellcategory_2, spellcategorycooldown_2, spellid_3, spelltrigger_3, spellcharges_3, spellppmRate_3, spellcooldown_3, spellcategory_3, spellcategorycooldown_3, spellid_4, spelltrigger_4, spellcharges_4, spellppmRate_4, spellcooldown_4, spellcategory_4, spellcategorycooldown_4, spellid_5, spelltrigger_5, spellcharges_5, spellppmRate_5, spellcooldown_5, spellcategory_5, spellcategorycooldown_5, bonding, description, PageText, LanguageID, PageMaterial, startquest, lockid, Material, sheath, RandomProperty, RandomSuffix, block, itemset, MaxDurability, area, Map, BagFamily, TotemCategory, socketColor_1, socketContent_1, socketColor_2, socketContent_2, socketColor_3, socketContent_3, socketBonus, GemProperties, RequiredDisenchantSkill, ArmorDamageModifier, duration, ItemLimitCategory, HolidayId, ScriptName, DisenchantID, FoodType, minMoneyLoot, maxMoneyLoot, flagsCustom, WDBVerified) VALUES

(987654, 9, 0, ‘Tome of World Flying’, 61330, 7, 134217792, 0, 1, 2500000, 500000, 0, -1, -1, 80, 45, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000, 0, 0, 483, 0, -1, 0, -1, 0, -1, 31700, 6, 0, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, -1, 0, ‘Learn to fly everywhere’, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, ‘’, 0, 0, 0, 0, 0, 1);

UPDATE creature_template SET modelid1 = 31803 WHERE entry = 32568;

UPDATE creature_template SET modelid2 = 17722 WHERE entry = 32568;

UPDATE creature_template SET modelid3 = 31958 WHERE entry = 32568;

UPDATE creature_template SET modelid4 = 28040 WHERE entry = 32568;

INSERT INTO npc_vendor (entry, slot, item, maxcount, incrtime, ExtendedCost) VALUES

(‘384’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘35101’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘4731’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘35099’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘32216’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘3362’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘3685’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘7952’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘16264’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘1261’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘7955’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘4730’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘17584’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘35131’,‘0’,‘987654’,‘0’,‘0’,‘0’),

(‘35132’,‘0’,‘987654’,‘0’,‘0’,‘0’);

It summons at random 4 different flying mounts. (Or rather the same mount with 4 diff Displays).

I don’t want it useable in BG’s though… So I’m trying to make a public creature script to find players withing a certain distance and remove the aura.

Script: Commented Sections are prior attempts…

/* No Fly In BG */

/*

TODO: Make it work!

In Game .unaura 31700 dismounts player

*/

#include “ScriptMgr.h”

#include “ScriptedCreature.h”

#include “ScriptedGossip.h”

#include “Player.h”

#include “Unit.h”

#include “SpellAuraDefines.h”

enum NoFlyAura

{

AURA_FLY_EVERYWHERE  = 31700, // http://www.wowhead.com/spell=31700/black-qiraji-battle-tank

};

class npc_nofly_trigger : public CreatureScript

{

public:

    npc_nofly_trigger() : CreatureScript("npc_nofly_trigger") { }



    struct npc_nofly_triggerAI : public ScriptedAI

    {

        npc_nofly_triggerAI(Creature* creature) : ScriptedAI(creature) { }



        void MoveInLineOfSight(Unit* who)

        {

            Player* player = who ? who->ToPlayer() : NULL;



            if (!player || !player->HasAura(AURA_FLY_EVERYWHERE))

                return;



            if (me->IsWithinDistInMap(player, 500.0f) && player->HasAura(AURA_FLY_EVERYWHERE))

            {

                player->CastSpell(player, AURA_FLY_EVERYWHERE, false);

                //player->RemoveAurasDueToSpell(AURA_FLY_EVERYWHERE, true); // As Defined Above -> Not Working

                //player->RemoveAura(AURA_FLY_EVERYWHERE, true); // As Defined Above -> Not Working

                //player->CastSpell(player, SPELL_AURA_NONE, true); // SPELL_AURA_NONE as defined in "SpellAuraDefines.h" -> Not Working

                me->MonsterTextEmote("You cannot fly in BattleGrounds!!!", LANG_UNIVERSAL);

            }

        }

    };



CreatureAI* GetAI(Creature* creature) const

{

    return new npc_nofly_triggerAI(creature);

}

};

void AddSC_npc_nofly_trigger()

{

new npc_nofly_trigger();

}

I made a npc that only Gm’s can see and linked the script to him…

NPC SQL:

REPLACE INTO creature_template (entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, modelid1, modelid2, modelid3, modelid4, name, subname, IconName, gossip_menu_id, minlevel, maxlevel, exp, faction_A, faction_H, npcflag, speed_walk, speed_run, scale, rank, mindmg, maxdmg, dmgschool, attackpower, dmg_multiplier, baseattacktime, rangeattacktime, unit_class, unit_flags, unit_flags2, dynamicflags, family, trainer_type, trainer_spell, trainer_class, trainer_race, minrangedmg, maxrangedmg, rangedattackpower, type, type_flags, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, PetSpellDataId, VehicleId, mingold, maxgold, AIName, MovementType, InhabitType, HoverHeight, Health_mod, Mana_mod, Armor_mod, RacialLeader, questItem1, questItem2, questItem3, questItem4, questItem5, questItem6, movementId, RegenHealth, mechanic_immune_mask, flags_extra, ScriptName, WDBVerified) VALUES (129999, 0, 0, 0, 0, 0, 17519, 11686, 0, 0, ‘World Invisible Trigger’, ‘’, ‘’, 0, 80, 80, 0, 114, 114, 0, 1, 1.14286, 1, 0, 104, 138, 0, 252, 1, 2000, 0, 1, 33587968, 2048, 8, 0, 0, 0, 0, 0, 72, 106, 26, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ‘’, 0, 4, 1, 1.35, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 130, ‘npc_nofly_trigger’, 12340);

Been stuck a little bit on this, and could really use some help.

Why not initiate as playerscript ?

You are thinking wrong about this… It’s the spell, which shouldn’t even be casted, if you’re in Battleground. So write a Spell- Script and check if player is in PVP Area → If not: Cast Spell, apply aura…

I’m not sure how that would help… if it’s creature, player, or areatrigger script, wouldn’t it have the same problem of removing the aura…

if (me->IsWithinDistInMap(player, 500.0f) && player->HasAura(AURA_FLY_EVERYWHERE))
is working, throwing a debug message after it, triggers the message. It is the mess under that that is failing…

{

                player->CastSpell(player, AURA_FLY_EVERYWHERE, false);

                //player->RemoveAurasDueToSpell(AURA_FLY_EVERYWHERE, true); // As Defined Above -> Not Working

                //player->RemoveAura(AURA_FLY_EVERYWHERE, true); // As Defined Above -> Not Working

                //player->CastSpell(player, SPELL_AURA_NONE, true); // SPELL_AURA_NONE as defined in "SpellAuraDefines.h" -> Not Working

                me->MonsterTextEmote("You cannot fly in BattleGrounds!!!", LANG_UNIVERSAL);

            }

At least I think so… I am still pretty green at all this.

So trash using it as a learned mount, and just make a custom spell script for it? I guess so… or even make a .flyeverwhere command checking if in PVP area would work too…

–update–

I’ll try all of these ideas… if nothing else, I might learn something else while writing them. Thanks for the advice guys.

–update–

Okay… So I decided on a commandscript…

#include “Chat.h”
#include “Config.h”
#include “Group.h”
#include “Language.h”
#include “Player.h”
#include “ScriptedGossip.h”
#include “ScriptMgr.h”
#include “Unit.h”
#include “RBAC.h”

class script_fly_everywhere_commands : public CommandScript
{
public:
script_fly_everywhere_commands() : CommandScript(“script_fly_everywhere_commands”) { }

ChatCommand* GetCommands() const
{
    static ChatCommand flyallCommandTable[] =
    {
        { "on",        rbac::RBAC_PERM_COMMAND_FLYALL_ON,  false, &HandleFlyAllOnCommand,  "", NULL },
        { "off",    rbac::RBAC_PERM_COMMAND_FLYALL_OFF, false, &HandleFlyAllOffCommand, "", NULL },
        { NULL, 0, false, NULL, "", NULL }    
    };
    static ChatCommand commandTable[] =
    {
        { "flyall",    rbac::RBAC_PERM_COMMAND_FLYALL,        false, NULL,                    "", flyallCommandTable },
        { NULL, 0, false, NULL, "", NULL }
    };

    return commandTable;
}

static bool HandleFlyAllOnCommand(ChatHandler* handler, const char* /*args*/)
{
    Player* player = handler->GetSession()->GetPlayer();
    handler->SetSentErrorMessage(true);
    if (player->IsInCombat() ||
        player->IsInFlight() ||
        player->IsCharmed() ||
        player->isAttackingPlayer() ||
        player->isFeared() ||
        player->isFrozen() ||
        player->IsOutdoorPvPActive() ||
        player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
        {
        handler->SendSysMessage("You cannot summon your mount right now");
        return false;
        }    
        else
        {
            player->CastSpell(player, 31700, true);
        }
        return true;
}

static bool HandleFlyAllOffCommand(ChatHandler* handler, const char* /*args*/)
{
    Player* player = handler->GetSession()->GetPlayer();
    handler->SetSentErrorMessage(true);
    if (player->IsInCombat() ||
        player->IsInFlight() ||
        player->IsCharmed()  ||
        player->IsFlying())
    {
        handler->SendSysMessage("You cannot dismount here!");
        return false;
        }    
        else
        {
            player->RemoveAura(31700);
        }
        return true;
}

};

void AddSC_script_fly_everywhere_commands()
{
new script_fly_everywhere_commands();
}

then made a macro:

#showtooltip Black Qiraji Battle Tank
.flyall on
/in 3 /s .flyall off

So that it mimics the original pet summoning.

Initial testing is going good.

Well that’s a solution, but visually it’s shit… ^^ Let the Player learn the spell and add a spell script to the spell, so the player can call it from his Mount- Inventory, like normal. In Spell script just check player position i.e. hasflag pvp ore battleground and if not cast the Spell…

Btw: You can make a custom flying mount to, easily by creating a mountable npc, with a spellclick spell and then just give it a script to fly ^^