• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ New equipment slot don't work

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
58
What am I doing wrong?
I am trying to create new Slots, I followed this steps:

distance slot was added · EvilHero90/otclient@aff23ec · GitHub

and they are not working..

The inventory don't appears.

Inventory.lua

Lua:
InventorySlotStyles = {
  [InventorySlotHead] = "HeadSlot",
  [InventorySlotNeck] = "NeckSlot",
  [InventorySlotBack] = "BackSlot",
  [InventorySlotBody] = "BodySlot",
  [InventorySlotRight] = "RightSlot",
  [InventorySlotLeft] = "LeftSlot",
  [InventorySlotLeg] = "LegSlot",
  [InventorySlotFeet] = "FeetSlot",
  [InventorySlotFinger] = "FingerSlot",
  [InventorySlotAmmo] = "AmmoSlot",
  [InventorySlotBracers] = "BracersSlot",
  [InventorySlotGauntlets] = "GauntletsSlot"
}

Inventory.otui
Code:
InventoryItem < Item
  $on:
    image-source: /images/ui/item-blessed

HeadSlot < InventoryItem
  id: slot1
  image-source: /images/game/slots/head
  &position: {x=65535, y=1, z=0}
  $on:
    image-source: /images/game/slots/head-blessed

BodySlot < InventoryItem
  id: slot4
  image-source: /images/game/slots/body
  &position: {x=65535, y=4, z=0}
  $on:
    image-source: /images/game/slots/body-blessed

LegSlot < InventoryItem
  id: slot7
  image-source: /images/game/slots/legs
  &position: {x=65535, y=7, z=0}
  $on:
    image-source: /images/game/slots/legs-blessed

FeetSlot < InventoryItem
  id: slot8
  image-source: /images/game/slots/feet
  &position: {x=65535, y=8, z=0}
  $on:
    image-source: /images/game/slots/feet-blessed

NeckSlot < InventoryItem
  id: slot2
  image-source: /images/game/slots/neck
  &position: {x=65535, y=2, z=0}
  $on:
    image-source: /images/game/slots/neck-blessed

LeftSlot < InventoryItem
  id: slot6
  image-source: /images/game/slots/left-hand
  &position: {x=65535, y=6, z=0}
  $on:
    image-source: /images/game/slots/left-hand-blessed

FingerSlot < InventoryItem
  id: slot9
  image-source: /images/game/slots/finger
  &position: {x=65535, y=9, z=0}
  $on:
    image-source: /images/game/slots/finger-blessed

BackSlot < InventoryItem
  id: slot3
  image-source: /images/game/slots/back
  &position: {x=65535, y=3, z=0}
  $on:
    image-source: /images/game/slots/back-blessed

RightSlot < InventoryItem
  id: slot5
  image-source: /images/game/slots/right-hand
  &position: {x=65535, y=5, z=0}
  $on:
    image-source: /images/game/slots/right-hand-blessed

AmmoSlot < InventoryItem
  id: slot10
  image-source: /images/game/slots/ammo
  &position: {x=65535, y=10, z=0}
  $on:
    image-source: /images/game/slots/ammo-blessed
 
BracersSlot < InventoryItem
  id: slot11
  image-source: /images/game/slots/bracers
  &position: {x=65535, y=10, z=0}
  $on:
    image-source: /images/game/slots/bracers-blessed

GauntletsSlot < InventoryItem
  id: slot12
  image-source: /images/game/slots/gauntlets
  &position: {x=65535, y=10, z=0}
  $on:
    image-source: /images/game/slots/gauntlets-blessed
 

PurseButton < Button
  id: purseButton
  size: 26 26
  !tooltip: tr('Open purse')
  icon-source: /images/game/slots/purse
  icon-size: 24 24
  icon-offset: 1 1

MiniWindow
  id: inventoryWindow
  !text: tr('Inventory')
  icon: /images/topbuttons/inventory
  height: 175
  @onClose: modules.game_inventory.onMiniWindowClose()
  &save: true

  MiniWindowContents
    HeadSlot
      anchors.top: parent.top
      anchors.horizontalCenter: parent.horizontalCenter
      margin-top: 3

    BodySlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3

    LegSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3

    FeetSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3

    NeckSlot
      anchors.top: slot1.top
      anchors.right: slot1.left
      margin-top: 10
      margin-right: 5

    LeftSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3

    FingerSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3

    BackSlot
      anchors.top: slot1.top
      anchors.left: slot1.right
      margin-top: 10
      margin-left: 5

    RightSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3

    AmmoSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3
   
    BracersSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3

    GauntletsSlot
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter
      margin-top: 3   

    PurseButton
      margin-top: 3
      anchors.top: prev.bottom
      anchors.horizontalCenter: prev.horizontalCenter

Player.lua
Lua:
InventorySlotOther = 0
InventorySlotHead = 1
InventorySlotNeck = 2
InventorySlotBack = 3
InventorySlotBody = 4
InventorySlotRight = 5
InventorySlotLeft = 6
InventorySlotLeg = 7
InventorySlotFeet = 8
InventorySlotFinger = 9
InventorySlotAmmo = 10
InventorySlotBracers = 11
InventorySlotGauntlets = 12
InventorySlotPurse = 13

InventorySlotFirst = InventorySlotHead
InventorySlotLast = InventorySlotPurse

Bump
 
Last edited:
if you dont made any change in otclient source and fucked it up than the problem is on server side. Search in server source files player.cpp and iologindata.cpp all of " intentory[ " and check the loop is pointed to SLOT_LAST or number, while it is number add 2 to it ex.
Code:
    for(int32_t slotId = 1; slotId < 12; ++slotId)
to
Code:
    for(int32_t slotId = 1; slotId < 14; ++slotId)
also player.h
Code:
        bool inventoryAbilities[13];
        Item* inventory[13];

Thanks, I think you are right!

My iologindata.cpp, I think need put 12, or its 14 ? Because I only add 2 Slots, and how it's 10, the right is add +2 ? Or 14 how you said ?
C++:
    ItemBlockList itemList;
    for (int32_t slotId = 1; slotId <= 10; ++slotId) {
        Item* item = player->inventory[slotId];
        if (item) {
            itemList.emplace_back(slotId, item);
        }
    }
 
as i said already,
also remember to check all loops becouse there was few

Yes, I compiled with this changes, checked everything, and nothing works.. :(

The error in OtClient don't appear anymore.

But have a new error, when try to load the module

Code:
ERROR: Unable to load module 'game_inventory': LUA ERROR:
/game_inventory/inventory.lua:12: table index is nil
stack traceback:
    [C]: in function '__newindex'
    /game_inventory/inventory.lua:12: in main chunk
    [C]: in function 'ensureModuleLoaded'
    /init.lua:46: in main chunk
 
Last edited:
Yes, I compiled with this changes, checked everything, and nothing works.. :(

The error in OtClient don't appear anymore.

But have a new error, when try to load the module

Code:
ERROR: Unable to load module 'game_inventory': LUA ERROR:
/game_inventory/inventory.lua:12: table index is nil
stack traceback:
    [C]: in function '__newindex'
    /game_inventory/inventory.lua:12: in main chunk
    [C]: in function 'ensureModuleLoaded'
    /init.lua:46: in main chunk
probably you dont change all, as i checked the newer server source is builded something different. Check you change in iologindata.cpp loading and saving item database in player.cpp the begin of file read variables of inventory and inventoryabilites than Player::~Player(), addThing,internalAddThin, getThing, updateThing, replaceThing i dont know it will be all just check twice by all file the phrase of "inventory" and be sure all numbers were changed

Edit
Try to add slots in data/lib/000-constant.lua
 
Last edited:
probably you dont change all, as i checked the newer server source is builded something different. Check you change in iologindata.cpp loading and saving item database in player.cpp the begin of file read variables of inventory and inventoryabilites than Player::~Player(), addThing,internalAddThin, getThing, updateThing, replaceThing i dont know it will be all just check twice by all file the phrase of "inventory" and be sure all numbers were changed

Edit
Try to add slots in data/lib/000-constant.lua

I changed the constant.lua, and nothing :(

I'm using OTX3,
This is my iologindata.cpp
[C++] The Last Empire - Pastebin.com

This is my player.cpp
[C++] The Last Empire - Player.cpp - Pastebin.com
 
Last edited:
i write what you should check man...
Code:
  //load inventory items
    ItemMap itemMap;
    query.str(std::string());
    query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
    if ((result = db.storeQuery(query.str()))) {
        loadItems(itemMap, result);
        for (ItemMap::const_reverse_iterator it = itemMap.rbegin(), end = itemMap.rend(); it != end; ++it) {
            const std::pair<Item*, int32_t>& pair = it->second;
            Item* item = pair.first;
            int32_t pid = pair.second;
            if (pid >= 1 && pid <= 12) {

Code:
[LIST=1]
[*]void Player::internalAddThing(uint32_t index, Thing* thing)
[*]{
[*]    Item* item = thing->getItem();
[*]    if (!item) {
[*]        return;
[*]    }
[*]

[*]    //index == 0 means we should equip this item at the most appropiate slot (no action required here)
[*]    if (index > 0 && index < 13) {
[*]
[/LIST]
 
i write what you should check man...
Code:
  //load inventory items
    ItemMap itemMap;
    query.str(std::string());
    query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
    if ((result = db.storeQuery(query.str()))) {
        loadItems(itemMap, result);
        for (ItemMap::const_reverse_iterator it = itemMap.rbegin(), end = itemMap.rend(); it != end; ++it) {
            const std::pair<Item*, int32_t>& pair = it->second;
            Item* item = pair.first;
            int32_t pid = pair.second;
            if (pid >= 1 && pid <= 12) {

Code:
[LIST=1]
[*]void Player::internalAddThing(uint32_t index, Thing* thing)
[*]{
[*]    Item* item = thing->getItem();
[*]    if (!item) {
[*]        return;
[*]    }
[*]

[*]    //index == 0 means we should equip this item at the most appropiate slot (no action required here)
[*]    if (index > 0 && index < 13) {
[*]
[/LIST]

Sorry,

I changed now for this, but nothing happens, the same errors
 
I said before about CONST_SLOT_LAST, do you change it?

Yes, you said, the number or const_slot_last,

Player.Cpp
C++:
    if (index > 0 && index < 13) {
        if (inventory[index]) {
            return;
        }

Iologindata.Cpp

C++:
ItemBlockList itemList;
    for (int32_t slotId = 1; slotId <= 12; ++slotId) {
        Item* item = player->inventory[slotId];
        if (item) {
            itemList.emplace_back(slotId, item);
        }
    }

C++:
            if (pid >= 1 && pid <= 12) {
                player->internalAddThing(pid, item);
 
Yes, you said, the number or const_slot_last,

Player.Cpp
C++:
    if (index > 0 && index < 13) {
        if (inventory[index]) {
            return;
        }

Iologindata.Cpp

C++:
ItemBlockList itemList;
    for (int32_t slotId = 1; slotId <= 12; ++slotId) {
        Item* item = player->inventory[slotId];
        if (item) {
            itemList.emplace_back(slotId, item);
        }
    }

C++:
            if (pid >= 1 && pid <= 12) {
                player->internalAddThing(pid, item);
yeah but your source works mostly on CONST_SLOT_LAST but as i see you dont write about it probably there is still CONST_SLOT_LAST = CONST_SLOT_AMMO
 
yeah but your source works mostly on CONST_SLOT_LAST but as i see you dont write about it probably there is still CONST_SLOT_LAST = CONST_SLOT_AMMO

Player.Cpp
Code:
    //index == 0 means we should equip this item at the most appropiate slot (no action required here)
    if (index > CONST_SLOT_FIRST && index < CONST_SLOT_LAST) {
        if (inventory[index]) {
            return;
        }

Iologindata.Cpp
C++:
            if (pid >= CONST_SLOT_FIRST && pid <= CONST_SLOT_LAST) {
                player->internalAddThing(pid, item);

C++:
    ItemBlockList itemList;
    for (int32_t slotId = CONST_SLOT_FIRST; slotId <= CONST_SLOT_LAST; ++slotId) {
        Item* item = player->inventory[slotId];
        if (item) {
            itemList.emplace_back(slotId, item);
        }
    }

Nothing again

yoQ6APEhQ1aNTe-8AGW0CQ.png
 
Last edited:
Bro, u have so patience, thanks for helping me!!

But it already right, and don't works

C++:
enum slots_t : uint8_t {
    CONST_SLOT_WHEREEVER = 0,
    CONST_SLOT_HEAD = 1,
    CONST_SLOT_NECKLACE = 2,
    CONST_SLOT_BACKPACK = 3,
    CONST_SLOT_ARMOR = 4,
    CONST_SLOT_RIGHT = 5,
    CONST_SLOT_LEFT = 6,
    CONST_SLOT_LEGS = 7,
    CONST_SLOT_FEET = 8,
    CONST_SLOT_RING = 9,
    CONST_SLOT_AMMO = 10,
    CONST_SLOT_BRACERS = 11,
    CONST_SLOT_GAUNTLETS = 12,

    CONST_SLOT_FIRST = CONST_SLOT_HEAD,
    CONST_SLOT_LAST = CONST_SLOT_GAUNTLETS,
};

Bump
 
Last edited by a moderator:
Back
Top