From 60495174a46985fea896bbae58fa587e7d3d3120 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Wed, 25 Apr 2012 21:15:48 -0300 Subject: [PATCH] bot traceback, moveup function, chat setting default ongamestart --- modules/game/gameinterface.lua | 3 +-- modules/game_console/console.lua | 8 ++++++++ src/otclient/core/game.cpp | 11 ++++++++++- src/otclient/core/game.h | 1 + src/otclient/luafunctions.cpp | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/game/gameinterface.lua b/modules/game/gameinterface.lua index a33ea8be..b0e761e0 100644 --- a/modules/game/gameinterface.lua +++ b/modules/game/gameinterface.lua @@ -194,8 +194,7 @@ function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatu if lookThing then local parentContainer = lookThing:getParentContainer() if parentContainer and parentContainer:hasParent() then - local pos = lookThing:getPosition() - menu:addOption('Move up', function() g_game.move(lookThing, { x=pos.x, y=pos.y, z=254 }, lookThing:getCount()) end) + menu:addOption('Move up', function() g_game.moveToParentContainer(lookThing, lookThing:getCount()) end) end end diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index c61ec458..e0376fcf 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -176,6 +176,12 @@ local function onChannelList(channelList) end end +local function onGameStart() + local tab = Console.getTab('Default') + if tab then + addEvent(function() consoleTabBar:selectTab(tab) end, false) + end +end -- public functions function Console.init() @@ -185,6 +191,7 @@ function Console.init() onOpenPrivateChannel = onOpenPrivateChannel, onOpenOwnPrivateChannel = onOpenOwnPrivateChannel, onCloseChannel = onCloseChannel, + onGameStart = onGameStart, onGameEnd = Console.clear }) consolePanel = displayUI('console.otui', GameInterface.getBottomPanel()) @@ -221,6 +228,7 @@ function Console.terminate() onOpenPrivateChannel = onOpenPrivateChannel, onOpenOwnPrivateChannel = onOpenPrivateChannel, onCloseChannel = onCloseChannel, + onGameStart = onGameStart, onGameEnd = Console.clear }) for channelid, channelname in pairs(channels) do diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index b420c986..8af44c6f 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -521,6 +521,15 @@ void Game::move(const ThingPtr& thing, const Position& toPos, int count) m_protocolGame->sendMove(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count); } +void Game::moveToParentContainer(const ThingPtr& thing, int count) +{ + if(!canPerformGameAction() || !thing || count <= 0) + return; + + Position position = thing->getPosition(); + move(thing, Position(position.x, position.y, 254), count); +} + void Game::rotate(const ThingPtr& thing) { if(!canPerformGameAction() || !thing) @@ -927,7 +936,7 @@ bool Game::checkBotProtection() // accepts calls comming from a stacktrace containing only C++ functions, // if the stacktrace contains a lua function, then only accept if the engine is processing an input event if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) { - logError("caught a lua call to a bot protected game function, the call was canceled"); + logError(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled")); return false; } #endif diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index bd3f0ba2..360c95e3 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -132,6 +132,7 @@ public: // item related void look(const ThingPtr& thing); void move(const ThingPtr &thing, const Position& toPos, int count); + void moveToParentContainer(const ThingPtr& thing, int count); void rotate(const ThingPtr& thing); void use(const ThingPtr& thing); void useWith(const ItemPtr& fromThing, const ThingPtr& toThing); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 7a72e54a..a2be20ef 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -89,6 +89,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game)); g_lua.bindClassStaticFunction("g_game", "look", std::bind(&Game::look, &g_game, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_game", "move", std::bind(&Game::move, &g_game, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + g_lua.bindClassStaticFunction("g_game", "moveToParentContainer", std::bind(&Game::moveToParentContainer, &g_game, std::placeholders::_1, std::placeholders::_2)); g_lua.bindClassStaticFunction("g_game", "rotate", std::bind(&Game::rotate, &g_game, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_game", "use", std::bind(&Game::use, &g_game, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_game", "useWith", std::bind(&Game::useWith, &g_game, std::placeholders::_1, std::placeholders::_2));