• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Possible function?

Status
Not open for further replies.

Blazeqts

Enthusiast
I'm working on my own script, Item template similar to the one on AT which will equip you with enchants, glyphs and items with 1 click if you preffer not to customize your character.

So, I currently have an ApplyGlyph function in my script, however I really want a similar one for items, for example ApplyItem

Here's my script: http://pastebin.com/q3HvuBV9

I think it's very similar, just need to change a bit of code. I have an ApplyEnchant function and it looks like the ApplyGlyph.


Appreciate your help! :)

ApplyGlyph Function
Code:
void ApplyGlyph(Player* player, uint8 slot, uint32 glyphID)
    {
        if (GlyphPropertiesEntry const* gp = sGlyphPropertiesStore.LookupEntry(glyphID))
        {
            if (uint32 oldGlyph = player->GetGlyph(slot))
            player->RemoveAurasDueToSpell(sGlyphPropertiesStore.LookupEntry(oldGlyph)->SpellId);
            player->CastSpell(player, gp->SpellId, true);
            player->SetGlyph(slot, glyphID);
            player->SendTalentsInfoData(false);
        }
    }

ApplyEnchant Function
Code:
void Enchant(Player* player, Item* item, uint32 enchantid)
{
    player->ApplyEnchantment(item, PERM_ENCHANTMENT_SLOT, false);
    item->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchantid, 0, 0);
    player->ApplyEnchantment(item, PERM_ENCHANTMENT_SLOT, true);
    player->GetSession()->SendNotification("|cff800080%s |cffFF0000 Successfully enchanted!", item->GetTemplate()->Name1.c_str());
}
 
Last edited:

Rochet2

Moderator / Eluna Dev
So you are requesting the ApplyItem function?
You should be asking for help with some issue you are having instead of requesting scripts.
http://emudevs.com/misc.php?do=vsarules Section: 1E, 19.

What is the issue you are having with coding the ApplyItem function?
Can you tell what it should do?
And yes, it is possible.
 

Blazeqts

Enthusiast
Hey Rochet, I'm aware of requesting being against the ToS.

I don't feel like this is a request. I want help and information about a function. Doesn't have to be a complete code.

Now to your question:
I want it to equip the player with the item(s) OnGossipSelect.
 

Rochet2

Moderator / Eluna Dev
So what is the problem with it?
Are you stuck on some part of the code or is there some error?
Dont you know where to begin?

What is it that you dont know how to do or have an issue with?
 

Blazeqts

Enthusiast
Don't know where to begin.

I'm trying to learn C++, however writing a function from the bottom seems hard as hell.
 
Last edited:

Rochet2

Moderator / Eluna Dev
Alright.
So you want to equip new items on the player.
I assume you know how to make a gossip script or add the code to the existing gossip code you have there.

I looked it quickly from Eluna where it was coded already:
https://github.com/ElunaLuaEngine/Eluna/blob/master/PlayerMethods.h#L2528

From that code you can take out the parts that are relevant:
Code:
// Equips a new item to the given slot. Returns true or false depending on success
bool EquipNewItem(Player* player, uint32 entry, uint32 slot)
{
    if (slot >= INVENTORY_SLOT_BAG_END)
        return false;

    // Make the item
    uint16 dest = 0;
    Item* item = Item::CreateItem(entry, 1, player);
    if (!item)
        return false;

    // Set the random prop if needed
    if (int32 randomPropertyId = Item::GenerateItemRandomPropertyId(entry))
        item->SetItemRandomProperties(randomPropertyId);

    // Check that it can be equipped
    InventoryResult result = player->CanEquipItem(slot, dest, item, false);
    if (result != EQUIP_ERR_OK)
    {
        delete item;
        return false;
    }

    // Add quest and achievement checks and equip the item
    player->ItemAddedQuestCheck(entry, 1);
    player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, entry, 1);
    player->EquipItem(dest, item, true);
    return true;
}

// Equips an existing item to the given slot. Returns true or false depending on success
bool EquipExistingItem(Player* player, Item* item, uint32 slot)
{
    if (slot >= INVENTORY_SLOT_BAG_END)
        return false;

    // Check that slot is free / can equip item
    uint16 dest = 0;
    InventoryResult result = player->CanEquipItem(slot, dest, item, false);
    if (result != EQUIP_ERR_OK)
        return false;

    // Remove item from old position
    player->RemoveItem(item->GetBagSlot(), item->GetSlot(), true);
    // Equip to character
    player->EquipItem(dest, item, true);
    return true;
}

With the first function you should be able to do what you want.
However players could possibly use it to spam items and sell them or similar, depending on how you use it.
Also you should decide what to do if there is gear already equipped in the slot.
 

Blazeqts

Enthusiast
Rochet2 said:
Also you should decide what to do if there is gear already equipped in the slot.


Code:
// Check that slot is free / can equip item
    uint16 dest = 0;
    InventoryResult result = player->CanEquipItem(slot, dest, item, false);
    if (result != EQUIP_ERR_OK)
        return false;

    // Remove item from old position
    player->RemoveItem(item->GetBagSlot(), item->GetSlot(), true);
    // Equip to character
    player->EquipItem(dest, item, true);
    return true;

Thank you!

Also, what does "return true" and "return false" mean? :)
 

Blazeqts

Enthusiast
Means that if the item was equipped, the function returns true.
Otherwise if there was an item already equipped in the slot or the item was not created etc. it returns false.

So..

Return false = It doesn't proceed
Return true = It proceeds
?
 

Rochet2

Moderator / Eluna Dev
So..

Return false = It doesn't proceed
Return true = It proceeds
?
I guess so ..
Not sure what mean with a function proceeding though..
But when it returns false it does NOT equip the item. (due to some problem like item already in the slot or cant equip the item since cant use..)
If it returns true it has equipped the item.
 
Status
Not open for further replies.
Top