From 017fa290b4e233b6cc8fa8b95e1ddf5aa5710448 Mon Sep 17 00:00:00 2001 From: OTCv8 Date: Mon, 28 Oct 2019 02:03:53 +0100 Subject: [PATCH] Another small bot update --- modules/game_bot/executor.lua | 1 + modules/game_bot/functions.lua | 43 ++++++++++++++++++++++++++++++++++ modules/game_outfit/outfit.lua | 4 ++++ 3 files changed, 48 insertions(+) diff --git a/modules/game_bot/executor.lua b/modules/game_bot/executor.lua index 588fee7..4c223ce 100644 --- a/modules/game_bot/executor.lua +++ b/modules/game_bot/executor.lua @@ -278,6 +278,7 @@ function executeBot(config, storage, panel, msgCallback) -- listen(name, callback) -- callback = function(text, channelId, pos) context.listen = function(name, callback) + if not name then return context.error("listen: invalid name") end name = name:lower() context.onTalk(function(name2, level, mode, text, channelId, pos) if name == name2:lower() then diff --git a/modules/game_bot/functions.lua b/modules/game_bot/functions.lua index eb39033..3031ca2 100644 --- a/modules/game_bot/functions.lua +++ b/modules/game_bot/functions.lua @@ -47,6 +47,15 @@ function setupFunctions(context) context.skull = function() return context.player:getSkull() end context.outfit = function() return context.player:getOutfit() end + context.setOutfit = function(outfit) + modules.game_outfit.ignoreNextOutfitWindow = g_clock.millis() + g_game.requestOutfit() + context.schedule(100, function() + g_game.changeOutfit(outfit) + end) + end + context.changeOutfit = context.setOutfit + context.setSpeed = function(value) context.player:setSpeed(value) end context.autoWalk = function(destination) return context.player:autoWalk(destination) end context.walk = function(dir) return modules.game_walking.walk(dir) end @@ -73,6 +82,40 @@ function setupFunctions(context) -- map releated context.zoomIn = function() modules.game_interface.getMapPanel():zoomIn() end context.zoomOut = function() modules.game_interface.getMapPanel():zoomOut() end + + context.getSpectators = function(multifloor) + if multifloor ~= true then + multifloor = false + end + return g_map.getSpectators(context.player:getPosition(), multifloor) + end + + context.getCreatureByName = function(name, multifloor) + if not name then return nil end + name = name:lower() + if multifloor ~= true then + multifloor = false + end + for i, spec in ipairs(g_map.getSpectators(context.player:getPosition(), multifloor)) do + if spec:getName():lower() == name then + return spec + end + end + return nil + end + context.getPlayerByName = function(name, multifloor) + if not name then return nil end + name = name:lower() + if multifloor ~= true then + multifloor = false + end + for i, spec in ipairs(g_map.getSpectators(context.player:getPosition(), multifloor)) do + if spec:isPlayer() and spec:getName():lower() == name then + return spec + end + end + return nil + end -- tools context.encode = function(data) return json.encode(data) end diff --git a/modules/game_outfit/outfit.lua b/modules/game_outfit/outfit.lua index 2c7a5f6..6c221e0 100644 --- a/modules/game_outfit/outfit.lua +++ b/modules/game_outfit/outfit.lua @@ -23,6 +23,7 @@ mount = nil mounts = nil mountCreature = nil currentMount = 1 +ignoreNextOutfitWindow = 0 function init() connect(g_game, { @@ -51,6 +52,9 @@ function updateMount() end function create(creatureOutfit, outfitList, creatureMount, mountList) + if ignoreNextOutfitWindow and g_clock.millis() < ignoreNextOutfitWindow + 1000 then + return + end if outfitWindow and not outfitWindow:isHidden() then return end