diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 0481cbaa..277a9103 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -24,10 +24,11 @@ #include "localplayer.h" #include "map.h" #include "tile.h" +#include "creature.h" +#include "statictext.h" #include #include #include -#include #include Game g_game; @@ -261,9 +262,20 @@ void Game::useWith(const ThingPtr& fromThing, const ThingPtr& toThing) if(!m_online || !fromThing || !toThing || !checkBotProtection()) return; - int fromStackpos = getThingStackpos(fromThing), toStackpos = getThingStackpos(toThing); - if(fromStackpos != -1 && toStackpos != -1) - m_protocolGame->sendUseItemEx(fromThing->getPos(), fromThing->getId(), fromStackpos, toThing->getPos(), toThing->getId(), toStackpos); + Position pos = fromThing->getPos(); + int fromStackpos = getThingStackpos(fromThing); + if(fromStackpos == -1) + return; + + if(CreaturePtr creature = toThing->asCreature()) { + m_protocolGame->sendUseOnCreature(pos, fromThing->getId(), fromStackpos, creature->getId()); + } else { + int toStackpos = getThingStackpos(toThing); + if(toStackpos == -1) + return; + + m_protocolGame->sendUseItemEx(pos, fromThing->getId(), fromStackpos, toThing->getPos(), toThing->getId(), toStackpos); + } } void Game::useHotkey(int itemId, const ThingPtr& toThing) @@ -271,15 +283,16 @@ void Game::useHotkey(int itemId, const ThingPtr& toThing) if(!m_online || !toThing || !checkBotProtection()) return; - m_protocolGame->sendUseItemEx(Position(0xFFFF, 0, 0), itemId, 0, toThing->getPos(), toThing->getId(), getThingStackpos(toThing)); -} - -void Game::useOnCreature(const ThingPtr& thing, const CreaturePtr& creature) -{ - if(!m_online || !thing || !checkBotProtection()) + Position pos = Position(0xFFFF, 0, 0); // means that is a hotkey use + int toStackpos = getThingStackpos(toThing); + if(toStackpos == -1) return; - m_protocolGame->sendUseOnCreature(thing->getPos(), thing->getId(), getThingStackpos(thing), creature->getId()); + if(CreaturePtr creature = toThing->asCreature()) { + m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId()); + } else { + m_protocolGame->sendUseItemEx(pos, itemId, 0, toThing->getPos(), toThing->getId(), toStackpos); + } } void Game::attack(const CreaturePtr& creature) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index ebdd6961..878fc222 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -65,7 +65,6 @@ public: void use(const ThingPtr& thing); void useWith(const ThingPtr& fromThing, const ThingPtr& toThing); void useHotkey(int itemId, const ThingPtr& toThing); - void useOnCreature(const ThingPtr& thing, const CreaturePtr& creature); // attack/follow related void attack(const CreaturePtr& creature); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index c094936b..f0df3b01 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -198,7 +198,6 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("use", std::bind(&Game::use, &g_game, _1)); g_lua.bindClassStaticFunction("useWith", std::bind(&Game::useWith, &g_game, _1, _2)); g_lua.bindClassStaticFunction("useHotkey", std::bind(&Game::useHotkey, &g_game, _1, _2)); - g_lua.bindClassStaticFunction("useOnCreature", std::bind(&Game::useOnCreature, &g_game, _1, _2)); g_lua.bindClassStaticFunction("walk", std::bind(&Game::walk, &g_game, _1)); g_lua.bindClassStaticFunction("forceWalk", std::bind(&Game::forceWalk, &g_game, _1)); g_lua.bindClassStaticFunction("attack", std::bind(&Game::attack, &g_game, _1));