Forum > Serverside Modding

[QUESTION] [WotLk] [ELUNA/LUA] Event for item purchase.

<< < (2/2)

Kaev:

--- Quote from: "ruben381" ---But, it looks like its not really possible.
--- End quote ---
It's serverside only so this is 100% possible. Just add the missing hook to your core. It's nearly only copy and paste for new hooks.

Grymskvll:
If I'm not mistaken, you'd want to trigger the event from TrinityCore's Player::BuyItemFromVendorSlot. Instead of using SendBuyError, you could just use Eluna's Player:SendNotification method to show the player the red error text (or add a Player:SendBuyError method to Eluna if you really want to, but from what I understand its only purpose is to show the error message).

I'm not sure if it really matters where in Player::BuyItemFromVendorSlot you trigger the event. I'd personally put it above all the other checks, since the custom condition is probably less trivial than something like a gold check.

The event trigger (inside Player::BuyItemFromVendorSlot) should look something like this. The arguments are just the player ("this" refers to the player since it's a player method), followed by all the parameters of Player::BuyItemFromVendorSlot (in case any script wants to use any of it):

--- Code: ---// Run all event handlers. If any of them return false then...
if (!sEluna->OnBuyFromVendor(this, vendorguid, vendorslot, item, count, bag, slot))
{
// ...abort the purchase!
return false;
}

--- End code ---

Just for clarity, OnBuyFromVendor doesn't exist (yet). You'd have to add/request it.

Like Kaev said, you can just look at existing hooks to see how to implement a new one. Be sure to look at hooks that can return false, since you want to be able to abort the purchase.

schlumpf:

--- Quote from: "Grymskvll" ---If I'm not mistaken, you'd want to trigger the event from TrinityCore's Player::BuyItemFromVendorSlot. Instead of using SendBuyError, you could just use Eluna's Player:SendNotification method to show the player the red error text (or add a Player:SendBuyError method to Eluna if you really want to, but from what I understand its only purpose is to show the error message).

--- End quote ---

Please always prefer to use specialized packets: They are localized. Keeping semantics help for good user experience. There have been a lot of english-only errors in emulators for various things (summoning pets, buying stuff, …) in the past which could just be avoided by sending the correct packet.

Grymskvll:

--- Quote from: "schlumpf" ---Please always prefer to use specialized packets: They are localized. Keeping semantics help for good user experience. There have been a lot of english-only errors in emulators for various things (summoning pets, buying stuff, …) in the past which could just be avoided by sending the correct packet.
--- End quote ---

Ah yeah, good point. In that case I guess a new Player:SendBuyError Eluna method would be preferable, so that you don't hardcode a specific BuyError in the event trigger.

In the case of the custom rep check, you could have the script send BuyResult BUY_ERR_REPUTATION_REQUIRE. If there's no BuyResult that suits your purpose, maybe you could have the script resort to checking the player's locale with (Eluna's) Player:GetDbLocaleIndex or Player:GetDbcLocale and use Player:SendNotification with a localized string.

Edit:
Here's how the locales are defined in TrinityCore's Common.h (and returned by Eluna's player methods above):

--- Code: ---enum LocaleConstant
{
    LOCALE_enUS = 0,
    LOCALE_koKR = 1,
    LOCALE_frFR = 2,
    LOCALE_deDE = 3,
    LOCALE_zhCN = 4,
    LOCALE_zhTW = 5,
    LOCALE_esES = 6,
    LOCALE_esMX = 7,
    LOCALE_ruRU = 8,

    TOTAL_LOCALES
};

--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version