• 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!

Feature Auto Loot [TFS 1.3]

  • registerMethod("Player", "AddAutoLootItem", LuaScriptInterface::luaPlayerAddAutoLootItem);
  • registerMethod("Player", "RemoveAutoLootItem", LuaScriptInterface::luaPlayerRemoveAutoLootItem);
  • registerMethod("Playe

After this, i have:


luascript.cpp:48:62: error: no ‘int LuaScriptInterface: :luaPlayerAddAutoLootItem(lua_State*)’ member function declared in class ‘LuaScr iptInterface’
int LuaScriptInterface::luaPlayerAddAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface: :luaPlayerRemoveAutoLootItem(lua_State*)’ member function declared in class ‘Lua ScriptInterface’
int LuaScriptInterface::luaPlayerRemoveAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface: :luaPlayerGetAutoLootItem(lua_State*)’ member function declared in class ‘LuaScr iptInterface’
int LuaScriptInterface::luaPlayerGetAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface ::luaPlayerGetAutoLootList(lua_State*)’ member function declared in class ‘LuaSc riptInterface’
int LuaScriptInterface::luaPlayerGetAutoLootList(lua_State* L)
^
luascript.cpp: In member function ‘void LuaScriptInterf ace::registerFunctions()’:
luascript.cpp:2578:46: error: ‘luaPlayerAddAutoLootIte ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "AddAutoLootItem", LuaScriptInterface::luaPlayerAddAu
^
/luascript.cpp:2579:52: error: ‘luaPlayerRemoveAutoLootI tem’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "RemoveAutoLootItem", LuaScriptInterface::luaPlaye
^
luascript.cpp:2580:49: error: ‘luaPlayerGetAutoLootIte ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "GetAutoLootItem", LuaScriptInterface::luaPlayerGe
^
luascript.cpp:2581:49: error: ‘luaPlayerGetAutoLootLis ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "GetAutoLootList", LuaScriptInterface::luaPlayerGe
 
After this, i have:


luascript.cpp:48:62: error: no ‘int LuaScriptInterface: :luaPlayerAddAutoLootItem(lua_State*)’ member function declared in class ‘LuaScr iptInterface’
int LuaScriptInterface::luaPlayerAddAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface: :luaPlayerRemoveAutoLootItem(lua_State*)’ member function declared in class ‘Lua ScriptInterface’
int LuaScriptInterface::luaPlayerRemoveAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface: :luaPlayerGetAutoLootItem(lua_State*)’ member function declared in class ‘LuaScr iptInterface’
int LuaScriptInterface::luaPlayerGetAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface ::luaPlayerGetAutoLootList(lua_State*)’ member function declared in class ‘LuaSc riptInterface’
int LuaScriptInterface::luaPlayerGetAutoLootList(lua_State* L)
^
luascript.cpp: In member function ‘void LuaScriptInterf ace::registerFunctions()’:
luascript.cpp:2578:46: error: ‘luaPlayerAddAutoLootIte ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "AddAutoLootItem", LuaScriptInterface::luaPlayerAddAu
^
/luascript.cpp:2579:52: error: ‘luaPlayerRemoveAutoLootI tem’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "RemoveAutoLootItem", LuaScriptInterface::luaPlaye
^
luascript.cpp:2580:49: error: ‘luaPlayerGetAutoLootIte ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "GetAutoLootItem", LuaScriptInterface::luaPlayerGe
^
luascript.cpp:2581:49: error: ‘luaPlayerGetAutoLootLis ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "GetAutoLootList", LuaScriptInterface::luaPlayerGe
check it out, man, something you did wrong ...
 
After this, i have:


luascript.cpp:48:62: error: no ‘int LuaScriptInterface: :luaPlayerAddAutoLootItem(lua_State*)’ member function declared in class ‘LuaScr iptInterface’
int LuaScriptInterface::luaPlayerAddAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface: :luaPlayerRemoveAutoLootItem(lua_State*)’ member function declared in class ‘Lua ScriptInterface’
int LuaScriptInterface::luaPlayerRemoveAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface: :luaPlayerGetAutoLootItem(lua_State*)’ member function declared in class ‘LuaScr iptInterface’
int LuaScriptInterface::luaPlayerGetAutoLootItem(lua_State* L)
^
error: no ‘int LuaScriptInterface ::luaPlayerGetAutoLootList(lua_State*)’ member function declared in class ‘LuaSc riptInterface’
int LuaScriptInterface::luaPlayerGetAutoLootList(lua_State* L)
^
luascript.cpp: In member function ‘void LuaScriptInterf ace::registerFunctions()’:
luascript.cpp:2578:46: error: ‘luaPlayerAddAutoLootIte ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "AddAutoLootItem", LuaScriptInterface::luaPlayerAddAu
^
/luascript.cpp:2579:52: error: ‘luaPlayerRemoveAutoLootI tem’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "RemoveAutoLootItem", LuaScriptInterface::luaPlaye
^
luascript.cpp:2580:49: error: ‘luaPlayerGetAutoLootIte ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "GetAutoLootItem", LuaScriptInterface::luaPlayerGe
^
luascript.cpp:2581:49: error: ‘luaPlayerGetAutoLootLis ’ is not a member of ‘LuaScriptInterface’
registerMethod("Player", "GetAutoLootList", LuaScriptInterface::luaPlayerGe

check it out, man, something you did wrong ...

I think is it

luascript.h

Code:
        static int luaPlayerAddAutoLootItem(lua_State* L);
        static int luaPlayerRemoveAutoLootItem(lua_State* L);
        static int luaPlayerGetAutoLootItem(lua_State* L);
        static int luaPlayerGetAutoLootList(lua_State* L);
[/B]
 
I think is it

luascript.h

Code:
        static int luaPlayerAddAutoLootItem(lua_State* L);
        static int luaPlayerRemoveAutoLootItem(lua_State* L);
        static int luaPlayerGetAutoLootItem(lua_State* L);
        static int luaPlayerGetAutoLootList(lua_State* L);
[/B]
Omg, i don't see this! haha
You're right! thanks for observation ! :oops:
 
I think is it

luascript.h

Code:
        static int luaPlayerAddAutoLootItem(lua_State* L);
        static int luaPlayerRemoveAutoLootItem(lua_State* L);
        static int luaPlayerGetAutoLootItem(lua_State* L);
        static int luaPlayerGetAutoLootList(lua_State* L);
[/B]


sorry, I was confused, just add this line in luascript.h or all the code that was quoted?
 
  • static int luaPlayerAddAutoLootItem(lua_State* L);
  • static int luaPlayerRemoveAutoLootItem(lua_State* L);
  • static int luaPlayerGetAutoLootItem(lua_State* L);
  • static int luaPlayerGetAutoLootList(lua_State* L);

error: ‘int luaPlayerAddAutoLootItem(lua_State* ’ declared ‘static’ but never defined [-Werror=unused-function]
static int luaPlayerAddAutoLootItem(lua_State* L);

oh god, i dont know what is wrong.. i use tfs 1.3
 
you have to define the function in luascript.cpp
C++:
int LuaScriptInterface::luaPlayerAddAutoLootItem(lua_State* L)
{
    // player:addAutoLootItem(itemId)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint16_t itemId;
    if (isNumber(L, 2)) {
        itemId = getNumber<uint16_t>(L, 2);
    } else {
        itemId = Item::items.getItemIdByName(getString(L, 2));
        if (itemId == 0) {
            lua_pushnil(L);
            return 1;
        }
    }
    player->addAutoLootItem(itemId);
    pushBoolean(L, true);
    return 1;
}
 
you have to define the function in luascript.cpp


this part I did, but still generates that informed error. I've done everything again and there's still a mistake when it comes to copying

  • int LuaScriptInterface::luaPlayerAddAutoLootItem(lua_State* L)
  • {
  • // player:addAutoLootItem(itemId)
  • Player* player = getUserdata<Player>(L, 1);
  • if (!player) {
  • lua_pushnil(L);
  • return 1;
  • }
  • uint16_t itemId;
  • if (isNumber(L, 2)) {
  • itemId = getNumber<uint16_t>(L, 2);
  • } else {
  • itemId = Item::items.getItemIdByName(getString(L, 2));
  • if (itemId == 0) {
  • lua_pushnil(L);
  • return 1;
  • }
  • }
  • player->addAutoLootItem(itemId);
  • pushBoolean(L, true);
  • return 1;
  • }

help-me ? i made it: static void luascript(){ and this script } or dont is it ?
 
Last edited by a moderator:
Post luascript.cpp and luascript.h in pastebin.com and paste link here...
Code:
        static int luaPlayerGetAutoLootList(lua_State* L);
{
    // player:getAutoLootList()
    Player* player = getUserdata<Player>(L, 1);

    if (player) {
        std::set<uint32_t> value = player->autoLootList;
   
        if (value.size() == 0) {
          lua_pushnil(L);
          return 1;
        }

        int index = 0;
        lua_createtable(L, value.size(), 0);
        for(auto i : value) {
            lua_pushnumber(L, i);
            lua_rawseti(L, -2, ++index);
        }
   
    } else {
        lua_pushnil(L);
    }

    return 1;
}
error: expected unqualified-id before ‘{’ token
{

error: ‘int luaPlayerAddAutoLootItem(lua_State*)’ declared ‘static’ but never defined [-Werror=unused-function]
static int luaPlayerAddAutoLootItem(lua_State* L);
 
remove the static from that in luascript.cpp, keep it in luascript.h

also remove the ;
result should be this:

C++:
int luaPlayerGetAutoLootList(lua_State* L)
{
    // player:getAutoLootList()
    Player* player = getUserdata<Player>(L, 1);

    if (player) {
        std::set<uint32_t> value = player->autoLootList;
   
        if (value.size() == 0) {
          lua_pushnil(L);
          return 1;
        }

        int index = 0;
        lua_createtable(L, value.size(), 0);
        for(auto i : value) {
            lua_pushnumber(L, i);
            lua_rawseti(L, -2, ++index);
        }
   
    } else {
        lua_pushnil(L);
    }

    return 1;
}
 
Last edited by a moderator:
also remove the ;
result should be this:

C++:
int luaPlayerGetAutoLootList(lua_State* L)
{
    // player:getAutoLootList()
    Player* player = getUserdata<Player>(L, 1);

    if (player) {
        std::set<uint32_t> value = player->autoLootList;
  
        if (value.size() == 0) {
          lua_pushnil(L);
          return 1;
        }

        int index = 0;
        lua_createtable(L, value.size(), 0);
        for(auto i : value) {
            lua_pushnumber(L, i);
            lua_rawseti(L, -2, ++index);
        }
  
    } else {
        lua_pushnil(L);
    }

    return 1;
}

Code:
/src/luascript.h: In function ‘int luaPlayerAddAutoLootItem(lua_State*)’:
/src/luascript.h:186:22: error: ‘getUserdata’ was not declared in this scope
     Player* player = getUserdata<Player>(L, 1);
                      ^
/src/luascript.h:186:40: error: expected primary-expression before ‘>’ token
     Player* player = getUserdata<Player>(L, 1);
                                        ^
/src/luascript.h:186:45: error: left operand of comma operator has no effect [-Werror=unused-value]
     Player* player = getUserdata<Player>(L, 1);
                                             ^
/src/luascript.h:193:22: error: ‘isNumber’ was not declared in this scope
     if (isNumber(L, 2)) {
                      ^
/src/luascript.h:194:18: error: ‘getNumber’ was not declared in this scope
         itemId = getNumber<uint16_t>(L, 2);
                  ^
/src/luascript.h:194:36: error: expected primary-expression before ‘>’ token
         itemId = getNumber<uint16_t>(L, 2);
                                    ^
/src/luascript.h:194:41: error: left operand of comma operator has no effect [-Werror=unused-value]
         itemId = getNumber<uint16_t>(L, 2);
                                         ^
/src/luascript.h:196:18: error: incomplete type ‘Item’ used in nested name specifier
         itemId = Item::items.getItemIdByName(getString(L, 2));
                  ^
/src/luascript.h:196:60: error: ‘getString’ was not declared in this scope
         itemId = Item::items.getItemIdByName(getString(L, 2));
                                                            ^
/src/luascript.h:202:11: error: invalid use of incomplete type ‘class Player’
     player->addAutoLootItem(itemId);
           ^
/src/luascript.h:41:7: error: forward declaration of ‘class Player’
 class Player;
       ^
/src/luascript.h:203:24: error: ‘pushBoolean’ was not declared in this scope
     pushBoolean(L, true);
                        ^
/src/luascript.h: In function ‘int luaPlayerRemoveAutoLootItem(lua_State*)’:
/src/luascript.h:210:22: error: ‘getUserdata’ was not declared in this scope
     Player* player = getUserdata<Player>(L, 1);
                      ^
/src/luascript.h:210:40: error: expected primary-expression before ‘>’ token
     Player* player = getUserdata<Player>(L, 1);
                                        ^
/src/luascript.h:210:45: error: left operand of comma operator has no effect [-Werror=unused-value]
     Player* player = getUserdata<Player>(L, 1);
                                             ^
/src/luascript.h:217:22: error: ‘isNumber’ was not declared in this scope
     if (isNumber(L, 2)) {
                      ^
/src/luascript.h:218:18: error: ‘getNumber’ was not declared in this scope
         itemId = getNumber<uint16_t>(L, 2);
                  ^
/src/luascript.h:218:36: error: expected primary-expression before ‘>’ token
         itemId = getNumber<uint16_t>(L, 2);
                                    ^
/src/luascript.h:218:41: error: left operand of comma operator has no effect [-Werror=unused-value]
         itemId = getNumber<uint16_t>(L, 2);
                                         ^
/src/luascript.h:220:18: error: incomplete type ‘Item’ used in nested name specifier
         itemId = Item::items.getItemIdByName(getString(L, 2));
                  ^
/src/luascript.h:220:60: error: ‘getString’ was not declared in this scope
         itemId = Item::items.getItemIdByName(getString(L, 2));
                                                            ^
/src/luascript.h:227:11: error: invalid use of incomplete type ‘class Player’
     player->removeAutoLootItem(itemId);
           ^
/src/luascript.h:41:7: error: forward declaration of ‘class Player’
 class Player;
       ^
/src/luascript.h:228:24: error: ‘pushBoolean’ was not declared in this scope
     pushBoolean(L, true);
                        ^
/src/luascript.h: In function ‘int luaPlayerGetAutoLootItem(lua_State*)’:
/src/luascript.h:236:22: error: ‘getUserdata’ was not declared in this scope
     Player* player = getUserdata<Player>(L, 1);
                      ^
/src/luascript.h:236:40: error: expected primary-expression before ‘>’ token
     Player* player = getUserdata<Player>(L, 1);
                                        ^
/src/luascript.h:236:45: error: left operand of comma operator has no effect [-Werror=unused-value]
     Player* player = getUserdata<Player>(L, 1);
                                             ^
/src/luascript.h:243:22: error: ‘isNumber’ was not declared in this scope
     if (isNumber(L, 2)) {
                      ^
/src/luascript.h:244:18: error: ‘getNumber’ was not declared in this scope
         itemId = getNumber<uint16_t>(L, 2);
                  ^
/src/luascript.h:244:36: error: expected primary-expression before ‘>’ token
         itemId = getNumber<uint16_t>(L, 2);
                                    ^
/src/luascript.h:244:41: error: left operand of comma operator has no effect [-Werror=unused-value]
         itemId = getNumber<uint16_t>(L, 2);
                                         ^
/src/luascript.h:246:18: error: incomplete type ‘Item’ used in nested name specifier
         itemId = Item::items.getItemIdByName(getString(L, 2));
                  ^
/src/luascript.h:246:60: error: ‘getString’ was not declared in this scope
         itemId = Item::items.getItemIdByName(getString(L, 2));
                                                            ^
/src/luascript.h:253:15: error: invalid use of incomplete type ‘class Player’
     if (player->getAutoLootItem(itemId)) {
               ^
/src/luascript.h:41:7: error: forward declaration of ‘class Player’
 class Player;
       ^
/src/luascript.h:254:28: error: ‘pushBoolean’ was not declared in this scope
         pushBoolean(L, true);
                            ^
/src/luascript.h:256:29: error: ‘pushBoolean’ was not declared in this scope
         pushBoolean(L, false);
                             ^
/src/luascript.h: In function ‘int luaPlayerGetAutoLootList(lua_State*)’:
/src/luascript.h:266:22: error: ‘getUserdata’ was not declared in this scope
     Player* player = getUserdata<Player>(L, 1);
                      ^
/src/luascript.h:266:40: error: expected primary-expression before ‘>’ token
     Player* player = getUserdata<Player>(L, 1);
                                        ^
/src/luascript.h:266:45: error: left operand of comma operator has no effect [-Werror=unused-value]
     Player* player = getUserdata<Player>(L, 1);
                                             ^
/src/luascript.h:269:9: error: ‘set’ is not a member of ‘std’
         std::set<uint32_t> value = player->autoLootList;
         ^
/src/luascript.h:269:9: note: suggested alternative:
In file included from /usr/include/boost/lexical_cast.hpp:170:0,
                 from /root/Otxserver-New/src/database.h:23,
                 from /root/Otxserver-New/src/luascript.h:35,
                 from /root/Otxserver-New/src/baseevents.h:23,
                 from /root/Otxserver-New/src/actions.h:23,
                 from /root/Otxserver-New/src/actions.cpp:22:
/usr/include/boost/container/container_fwd.hpp:79:7: note:   ‘boost::container::set’
 class set;
       ^
In file included from /root/Otxserver-New/src/baseevents.h:23:0,
                 from /root/Otxserver-New/src/actions.h:23,
                 from /root/Otxserver-New/src/actions.cpp:22:
/src/luascript.h:269:26: error: expected primary-expression before ‘>’ token
         std::set<uint32_t> value = player->autoLootList;
                          ^
/src/luascript.h:269:28: error: ‘value’ was not declared in this scope
         std::set<uint32_t> value = player->autoLootList;
                            ^
/src/luascript.h:269:42: error: invalid use of incomplete type ‘class Player’
         std::set<uint32_t> value = player->autoLootList;
                                          ^
/src/luascript.h:41:7: error: forward declaration of ‘class Player’
 class Player;
       ^
/src/luascript.h:278:22: error: unable to deduce ‘auto&&’ from ‘value’
         for(auto i : value) {
                      ^
 
PANIC: unprotected error in call to Lua API (attempt to index a nil value)
Aborted (core dumped)

:C
 
also remove the ;
result should be this:

C++:
int luaPlayerGetAutoLootList(lua_State* L)
{
    // player:getAutoLootList()
    Player* player = getUserdata<Player>(L, 1);

    if (player) {
        std::set<uint32_t> value = player->autoLootList;
  
        if (value.size() == 0) {
          lua_pushnil(L);
          return 1;
        }

        int index = 0;
        lua_createtable(L, value.size(), 0);
        for(auto i : value) {
            lua_pushnumber(L, i);
            lua_rawseti(L, -2, ++index);
        }
  
    } else {
        lua_pushnil(L);
    }

    return 1;
}
Code:
root@vps164667:~/Otxserver-New/cmake# screen -r
/root/Otxserver-New/src/luascript.cpp:119:22: error: ‘getUserdata’ was not declared in this scope
     Player* player = getUserdata<Player>(L, 1);
                      ^
/root/Otxserver-New/src/luascript.cpp:119:40: error: expected primary-expression before ‘>’ token
     Player* player = getUserdata<Player>(L, 1);
                                        ^
/root/Otxserver-New/src/luascript.cpp:119:45: error: left operand of comma operator has no effect [-Werror=unused-value]
     Player* player = getUserdata<Player>(L, 1);
                                             ^
/root/Otxserver-New/src/luascript.cpp:126:22: error: ‘isNumber’ was not declared in this scope
     if (isNumber(L, 2)) {
                      ^
/root/Otxserver-New/src/luascript.cpp:127:18: error: ‘getNumber’ was not declared in this scope
         itemId = getNumber<uint16_t>(L, 2);
                  ^
/root/Otxserver-New/src/luascript.cpp:127:36: error: expected primary-expression before ‘>’ token
         itemId = getNumber<uint16_t>(L, 2);
                                    ^
/root/Otxserver-New/src/luascript.cpp:127:41: error: left operand of comma operator has no effect [-Werror=unused-value]
         itemId = getNumber<uint16_t>(L, 2);
                                         ^
/root/Otxserver-New/src/luascript.cpp:129:60: error: ‘getString’ was not declared in this scope
         itemId = Item::items.getItemIdByName(getString(L, 2));
                                                            ^
/root/Otxserver-New/src/luascript.cpp:137:28: error: ‘pushBoolean’ was not declared in this scope
         pushBoolean(L, true);
                            ^
/root/Otxserver-New/src/luascript.cpp:139:29: error: ‘pushBoolean’ was not declared in this scope
         pushBoolean(L, false);
                             ^
/root/Otxserver-New/src/luascript.cpp: In function ‘int luaPlayerGetAutoLootList(lua_State*)’:
/root/Otxserver-New/src/luascript.cpp:149:22: error: ‘getUserdata’ was not declared in this scope
     Player* player = getUserdata<Player>(L, 1);
                      ^
/root/Otxserver-New/src/luascript.cpp:149:40: error: expected primary-expression before ‘>’ token
     Player* player = getUserdata<Player>(L, 1);
                                        ^
/root/Otxserver-New/src/luascript.cpp:149:45: error: left operand of comma operator has no effect [-Werror=unused-value]
     Player* player = getUserdata<Player>(L, 1);
                                             ^
In file included from /root/Otxserver-New/src/luascript.cpp:26:0:
/root/Otxserver-New/src/player.h:1380:22: error: ‘std::set<unsigned int> Player::autoLootList’ is protected
   std::set<uint32_t> autoLootList;
                      ^
/root/Otxserver-New/src/luascript.cpp:152:44: error: within this context
         std::set<uint32_t> value = player->autoLootList;
                                            ^
 
Back
Top