I want to change what happens when a quest item is used, but my script isn’t being triggered and I can’t figure out why.
The following was just an attempt to do something simple. When I get this working, I’ll do something more interesting.
I don’t think it’s even triggering OnUse when I use the item. I don’t see anything in the log and when I use the item in the game it starts its cooldown, but it doesn’t do anything else.
What am I doing wrong?
#include “ScriptMgr.h”
#include “Player.h”
#include “Log.h”
class warsong_flare_gun: public ItemScript
{
public:
warsong_flare_gun() : ItemScript(“warsong_flare_gun”) {}
bool OnUse(Player* player, Item* item) OVERRIDE
{
TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "%lu using Warsong Flare Gun", player->GetGUID());
if (player->GetQuestStatus(11711) == QUEST_STATUS_INCOMPLETE)
{
player->Say("I have the Quest!!", LANG_UNIVERSAL);
}
player->Say("Valiance Keep Officer... Come Here!!", LANG_UNIVERSAL);
return true;
}
};
void AddSC_warsong_flare_gun()
{
new warsong_flare_gun();
}
I’ve been reading tutorials and examples that say I need to add my script name to the item_template.ScriptName field. In my current version of the database, item_template doesn’t have a ScriptName field, but I did find the item_script_names table that looks like it serves the same purpose.
INSERT INTO `item_script_names` (`id`, `ScriptName`)
VALUES(34971, 'warsong_flare_gun');
At first, I tried it without adding an entry to item_template at all. That didn’t work. This isn’t a new item, so I found a db2 file editor that allowed me to see the properties of the item in both Item.db2 and Item-sparse.db2. I cross-referenced that with the structs for ItemEntry and ItemSparseEntry in src/server/game/DataStores/DB2Structure.h.
-- Note that the Item-sparse.db2 file shows the spell in the 4th spell id column, but the first one seemed more logical.
INSERT INTO `item_template`(`entry`,`class`,`subclass`,`name`,`displayid`,
`Quality`,`Flags`,`delay`,`spellid_1`,`spellcategory_1`,
`spellcategorycooldown_1`,`bonding`
)
VALUES(
34971, -- Warsong Flare Gun
12, -- class : 12 = Quest
0, -- subclass : always 0 for quest items
"Warsong Flare Gun",
39435, -- displayid
1, -- quality : 1 = common
64, -- Flags : 64 = "UNK2" (read from Item-sparse.db2)
0, -- delay : 0 (read from Item-sparse.db2) differs from column default (1000)
45958, -- spellid_1 : 45958 = [Signal Alliance]
1167, -- spellcategory_1 : ?? (read from Item-sparse.db2)
100000, -- spellcategorycooldown_1 : ?? (read from Item-sparse.db2)
4 -- "bonding" (binding) : 4 = Quest item (Item-sparse.db2 says -1)
);
Please forgive the excessive comments. They help me remember stuff. The fields that I didn’t specify had reasonable defaults that either matched or made more sense than the equivalent fields in the db2 file.
I’ve made the necessary changes to CMakeLists.txt and ScriptLoader.cpp and I can confirm that my code is compiled when I watch the make output.
I’m using commit # 14d80d269dd7f9624983bc5a610e511f31ed33f0 of the 4.3.4 branch on Linux.
My database is TrinityCore_4.3.4_DB_Alpha commit # e07faffe7ade24cab124fc8dd1ad672673d1f2fa .
Thank you.