Jump to content
  • 0

Custom scripting help


JPlady42

Question

3 answers to this question

Recommended Posts

Its a bit more complicated than that.

You need to create the item object, see if the player can equip it and then equip it and handle the usual things on item receive and equip.
Not sure if there is an easier way.

 

// copied from Eluna

        uint32 slot = INVENTORY_SLOT_HEAD;
        uint32 entry = 123123;

            item = Item::CreateItem(entry, 1, player);
            if (!item)
                return;

        uint16 dest = 0;
            InventoryResult result = player->CanEquipItem(slot, dest, item, false);
            if (result != EQUIP_ERR_OK)
            {
                delete item;
                return;
            }
            player->ItemAddedQuestCheck(entry, 1);
#if (!defined(TBC) && !defined(CLASSIC))
            player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, entry, 1);
#endif

        Item* equippedItem = player->EquipItem(dest, item, true));
        player->AutoUnequipOffhandIfNeed();

 

Link to comment
Share on other sites

Look at existing scripts. You can see them in SD3 submodule.

Here is an example I created from a script in SD3:
 

#include "precompiled.h"

struct MyNPC : public CreatureScript
{
    MyNPC() : CreatureScript("MyNPC") {}

    bool OnGossipHello(Player* pPlayer, Creature* pCreature) override
    {
        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Do stuff", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Close menu", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
        pPlayer->SEND_GOSSIP_MENU(100, pCreature->GetObjectGuid());
        return true;
    }

    bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 uiAction) override
    {
        pPlayer->PlayerTalkClass->ClearMenus();
        switch (uiAction)
        {
        case GOSSIP_ACTION_INFO_DEF + 1:
            // stuff
            break;
        case GOSSIP_ACTION_INFO_DEF + 2:
            pPlayer->CLOSE_GOSSIP_MENU();
            break;
        }
        return true;
    }
};

void AddSC_MyNPC()
{
    Script* s = new MyNPC();
    s->RegisterSelf(false);
}

Doesnt look so different to TC, does it?
All files in the existing folders are automatically added to the solution by cmake looks to me.
And if you want your own folder you would probably need to add it to the cmakelists.txt (did not test).
You also need to add the AddSC_MyNPC function declaration and call to the scriptloader in SD3 https://github.com/mangos/ScriptDev3/blob/5fc8db14109576fa4922f05836b25a61ca73ecd2/system/ScriptLoader.cpp as usual in most cores (like TC too)

Take a look at the SD3 scripts folder for your core:
https://github.com/mangoszero/server/tree/master/src/modules

Link to comment
Share on other sites

On 6/10/2017 at 5:01 AM, Rochet2 said:

Look at existing scripts. You can see them in SD3 submodule.

Here is an example I created from a script in SD3:
 


#include "precompiled.h"

struct MyNPC : public CreatureScript
{
    MyNPC() : CreatureScript("MyNPC") {}

    bool OnGossipHello(Player* pPlayer, Creature* pCreature) override
    {
        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Do stuff", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Close menu", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
        pPlayer->SEND_GOSSIP_MENU(100, pCreature->GetObjectGuid());
        return true;
    }

    bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 uiAction) override
    {
        pPlayer->PlayerTalkClass->ClearMenus();
        switch (uiAction)
        {
        case GOSSIP_ACTION_INFO_DEF + 1:
            // stuff
            break;
        case GOSSIP_ACTION_INFO_DEF + 2:
            pPlayer->CLOSE_GOSSIP_MENU();
            break;
        }
        return true;
    }
};

void AddSC_MyNPC()
{
    Script* s = new MyNPC();
    s->RegisterSelf(false);
}

Doesnt look so different to TC, does it?
All files in the existing folders are automatically added to the solution by cmake looks to me.
And if you want your own folder you would probably need to add it to the cmakelists.txt (did not test).
You also need to add the AddSC_MyNPC function declaration and call to the scriptloader in SD3 https://github.com/mangos/ScriptDev3/blob/5fc8db14109576fa4922f05836b25a61ca73ecd2/system/ScriptLoader.cpp as usual in most cores (like TC too)

Take a look at the SD3 scripts folder for your core:
https://github.com/mangoszero/server/tree/master/src/modules

whats the function to add items to player equipped items? pplayer->equipitem gives me an error, says items cant be integers

 

Severity    Code    Description    Project    File    Line    Suppression State
Error (active)    E0167    argument of type "int" is incompatible with parameter of type "Item *"    mangosscript    d:\FivePlayerbuild\src\modules\SD3\LevelUpNPC.cpp    27    

 

same issue for pplayer->AddMItem
 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use