Rochet2 / TrinityCore

Rochet2's stuff for TC
https://rochet2.github.io
89 stars 144 forks source link

Gossip on Item #148

Closed eXPeRi91 closed 1 year ago

eXPeRi91 commented 1 year ago

Hello,

It's seems the gossip on items is not working.. I tried with the patch here, but nothing works... The core is compiling without errors, but in-game whatever I do, I can't make it work. I created soo many items (custom) even used an items that exists in-game like: "Ultrasafe Transporter: Gadgetzan" but no... The code I was trying:

class custom_portable_teleporter : public ItemScript
{
public:
    custom_portable_teleporter() : ItemScript("custom_portable_teleporter") { }

    bool OnUse(Player* player, Item* item, SpellCastTargets const& targets) override
    {
        player->PlayerTalkClass->ClearMenus();
        AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Shattrath City", GOSSIP_SENDER_MAIN, 1);
        AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Dalaran", GOSSIP_SENDER_MAIN, 2);
        AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Gurubashi Arena", GOSSIP_SENDER_MAIN, 3);
        AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Stormwind", GOSSIP_SENDER_MAIN, 4);
        player->PlayerTalkClass->SendGossipMenu(DEFAULT_GOSSIP_MESSAGE, item->GetGUID());
        return true;
    }

    void OnGossipSelect(Player* player, Item* item, uint32 sender, uint32 action) override
    {
        switch (action)
        {
        case 1:
            player->TeleportTo(111, -1859.52f, 5413.44f, -12.43f, 0.0f);
            break;
        case 2:
            player->TeleportTo(571, 5804.04f, 457.57f, 651.51f, 0.0f);
            break;
        case 3:
            player->TeleportTo(0, -13216.74f, 218.56f, 41.32f, 0.0f);
            break;
        case 4:
            player->TeleportTo(0, -8915.38f, 554.73f, 93.61f, 0.0f);
            break;
        default:
            player->GetSession()->SendNotification("Invalid choice.");
            break;
        }
        player->PlayerTalkClass->SendCloseGossip();
    }
};

The debug, I never saw the call "OnUse()" call for this script (The script was registered in script loader, even placed in item_scripts.cpp , but still nothing) on every other script the call "OnUse()" was there, but for mine not worked... @Rochet2 can you check it? Thanks!

Rochet2 commented 1 year ago

Try attach the script to hearthstone. Also check your server logs (error and normal logs) for the scriptname custom_portable_teleporter and make sure it is not there.

I may be able to check it at some point, but that may not be too soon. So its best if you can try that out in the meantime.

eXPeRi91 commented 1 year ago

I did it, and the server is crashing on hearthstone and 53510 https://www.wowhead.com/wotlk/item=53510/captured-frog, on glyph and some quest items I got message like "Item cannot be found" or something like that. I tried to add the custom items in items.dbc still nothing. As I said no error about "custom_portable_teleporter" and items related problems.

eXPeRi91 commented 1 year ago

Aslo added log for the item: TC_LOG_INFO("item_portable_teleporter", "My Portable Teleporter was used by player %s.", player->GetName().c_str()); TC_LOG_DEBUG("item_portable_teleporter", "My Portable Teleporter was used by player %s.", player->GetName().c_str()); Nothing.. like dead silent ... If I don't attach the script to any item, I got message like this: "Script 'item_portable_teleporter' exists in the core, but the database does not assign it to any creature." the creature like Trinity did something to the items?.. I can't find problem with the script, if you find any, please tell me, but for me this script has to work, based of the example you placed here.

Rochet2 commented 1 year ago

The core should not crash if the script is attached to hearthstone. It sounds like either there is something wrong with the installation of the core modifications or there is some other script or mechanic that is causing the crash. Are you perhaps having the item delete itself on use? You should try get a crashlog from a debug build and see why hearthstone would crash as that is very unusual. You could also debug the core to find out what is going wrong. Try see this topic on how to get a debugger running https://talk.trinitycore.org/t/tutorial-for-debugging-crashlogs-edit-and-continue/31116.

It has come to my attention that the example script works fine on latest core. Also the script you have posted works fine. Something else is going on here.

eXPeRi91 commented 1 year ago

@Rochet2 So, the problem was kind-off my side :D But the thing is, you cannot use any, I mean ANY kind of script on custom items. You can check this:

DELETE FROM `item_template` WHERE `entry`=56809;
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`, `VerifiedBuild`) VALUES (56809, 15, 0, -1, 'Portable Teleporter', 59496, 3, 67158016, 0, 1, 0, 0, 0, -1, -1, 80, 80, 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, 0, 0, 0, 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, 0, 0, 0, 0, -1, 0, -1, 1, 'A magical device that will allow you to teleport around the world.', 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 'custom_portable_teleporter', 0, 0, 0, 0, 0, 12340);

After this, create the item inside Item.dbc like this:

56809,15,0,-1,-1,59496,0,0,

Than you will need to create MPQ with the new updated item.dbc (This is the part where I am fixing the big red "?" on item)

Test, and tell me where is the problem.. I used TrinityCreator

Rochet2 commented 1 year ago

@eXPeRi91 The reason hearthstone works is that it has a spell on use, which is hearthstone teleport spell. Any "on use" script requires a spell on use.

UPDATE `item_template` SET `spellid_1`=8690 WHERE  `entry`=56809;

Also, after making any such change, you must clear your cache. The client has a lot of authority on what happens in game, so if the client side cache holds the item data without the spell on use, it will not work.

eXPeRi91 commented 1 year ago

Thank you @Rochet2!

I really don't know what I was thinking xD