Custom item to use on a mount with cooldown

Hi

I want to create a custom item with a custom c++ scripted spell that I can use on a mount. The item (or the spell) should have a cooldown.

1st problem:

When I’m mounted and use the item I get dismounted. May there is a flag to prevent this ?

2nd problem:

I couldn’t manage the cooldown of my item. If found this:

http://www.trinitycore.org/f/topic/4914-item-script-cooldown

There they is a dummy spell (18282) with a cooldown. If I do that than the client tells me the spell is not ready to use. But the c++ script is starting anyway. May I can check in the script if there is a cooldown running ?

On a quick look I didnt see dismounting on item use, so it can be the spell.

Try using TRIGGERED_IGNORE_CASTER_MOUNTED_OR_ON_VEHICLE on the spell.

The cooldown is set for the spell I guess, so as the code is like this;

// Note: If script stop casting it must send appropriate data to client to prevent stuck item in gray state.
if (!sScriptMgr->OnItemUse(pUser, pItem, targets))
{
// no script or script not process request by self
pUser->CastItemUseSpell(pItem, targets, castCount, glyphIndex);
}

It does script before casting, so the cast fails while script runs.

Try using Player::HasSpellCooldown(uint32 spell_id) to check the cooldown for the spell casted.

May I didn’t described well what I’m doing. In fact I’m not using a custom spell instead I’m using a custom script :wink:

INSERT INTO item_template
(entry, class, subclass, SoundOverrideSubclass, 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
(200016, 7, 11, -1, ‘MY_ITEM’, 41682, 2, 0, 0, 1, ‘1600’, 400, 0, -1, -1, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 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, 0, 0, 0, 18282, 0, 0, -1, 60000, 0, -1, 0, 0, 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, 3, ‘’, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1224, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 7200, 0, 0, ‘custom_item_test’, 0, 0, 0, 0, 0, 12340);

And this is the script:

class custom_item_test : public ItemScript
{
public:
custom_item_test() : ItemScript(“custom_item_test”)
{
}

    bool OnUse(Player* player, Item* /*item*/, SpellCastTargets const& /*targets*/) OVERRIDE
    {
	if (!player->HasSpellCooldown(18282))
	{
		float Speed = 5.0f;
		player->SetSpeed(MOVE_RUN, Speed, true);
	}
        return false;
    }

};

I could manage the cooldown problem with the dummy spell. However there is no visual cooldown feedback in the icon, but this is maybe a client/dbc problem.

But don’t know why I get dismounted by using this item. I also get dismounted if I don’t use spells for this item.

So, I can’t use an item while I’m mounted ?