mar173
Member
- Joined
- Aug 14, 2016
- Messages
- 34
- Reaction score
- 18
edit: can u explain, why it crashes windows?
I'm just testing stuff. PC restarted after clicking on BotSwitch in game. How should this be done right? I don't want the kind of window that evolunia_bot or game_bot have. The window should be borderless and without minimise or close icons. There should be a fixed position which the user cannot change.
bot.lua
manaPotion.otui
_____________________
FIXED, but now i have another problem, how to automatically resize a panel to its elements, and how to add border or nice background to panel?
bot_src/main.lua
I'm just testing stuff. PC restarted after clicking on BotSwitch in game. How should this be done right? I don't want the kind of window that evolunia_bot or game_bot have. The window should be borderless and without minimise or close icons. There should be a fixed position which the user cannot change.
bot.lua
Lua:
manaPotion = nil
function init()
g_ui.importStyle("core_ui/basic.otui")
g_ui.importStyle("core_ui/panels.otui")
g_ui.importStyle("core_ui/config.otui")
g_ui.importStyle("core_ui/icons.otui")
g_ui.importStyle("core_ui/container.otui")
manaPotion = g_ui.loadUI('bot_ui/manaPotion', modules.game_interface.getMapPanel())
end
function terminate()
manaPotion:destroy()
end
manaPotion.otui
Code:
BotSwitch
width: 177
id: manaPotion_switch
anchors.top: parent.top
anchors.left: parent.left
text-align: center
Post automatically merged:
_____________________
FIXED, but now i have another problem, how to automatically resize a panel to its elements, and how to add border or nice background to panel?
Lua:
local UI_Parents = {}
local UI_Childrens = {}
local function Settings()
SETTINGS = g_settings.getNode('MyBot')
if not SETTINGS then
SETTINGS = {}
end
local char = g_game.getCharacterName()
if not SETTINGS[char] then
SETTINGS[char] = {
mana_potion_switch = true,
mana_potion_textedit = '268'
}
end
SETINGS_CHAR = SETTINGS[char]
g_settings.setNode('MyBot', SETTINGS)
end
local function UI_Switch_TextEdit(id)
local path = 'bot_ui/' .. id
local panel = g_ui.loadUI(path, modules.game_interface.getMapPanel()) -- modules.game_interface.getLeftPanel())
local id_switch = id .. '_switch'
local switch = panel[id_switch]
switch:setOn(SETINGS_CHAR[id_switch])
switch.onClick = function(widget)
SETINGS_CHAR[id_switch] = not SETINGS_CHAR[id_switch]
widget:setOn(SETINGS_CHAR[id_switch])
g_settings.setNode('MyBot', SETTINGS)
end
local id_textedit = id .. '_textedit'
local textedit = panel[id_textedit]
textedit:setText(SETINGS_CHAR[id_textedit])
textedit.onTextChange = function(widget, text)
SETINGS_CHAR[id_textedit] = text
g_settings.setNode('MyBot', SETTINGS)
end
table.insert(UI_Parents, panel)
table.insert(UI_Childrens, textedit)
table.insert(UI_Childrens, switch)
end
local function UI()
UI_Switch_TextEdit('mana_potion')
end
local function RefreshPlayerInfo()
player = g_game.getLocalPlayer()
playerName = g_game.getCharacterName()
playerVocation = player:getVocation()
end
function OnTick()
if not game_started then
scheduleEvent(OnTick, 250)
return
end
BotOnTick()
scheduleEvent(OnTick, 10)
end
function OnGameLoad()
if g_game.isOnline() and g_game.getLocalPlayer() and g_game.getCharacterName() and g_game.getLocalPlayer():getPosition() then
-- settings, info and ui for different char
RefreshPlayerInfo()
Settings()
UI()
-- ^ need write new info first ^
-- then game is fully started
game_started = true
-- load bot only once, we can add reload button to see coding changes in game
if not bot_loaded then
dofile('bot_src/main.lua')
scheduleEvent(OnTick, 250)
end
bot_loaded = true
return
end
scheduleEvent(OnGameLoad, 250)
end
local function Dispose()
game_started = false
for i = #UI_Childrens, 1, -1 do
if UI_Childrens[i] then
UI_Childrens[i]:destroy()
end
table.remove(UI_Childrens, i)
end
for i = #UI_Parents, 1, -1 do
if UI_Parents[i] then
UI_Parents[i]:destroy()
end
table.remove(UI_Parents, i)
end
end
function OnLogin()
scheduleEvent(OnGameLoad, 250)
end
function OnLogout()
Dispose()
end
function init()
g_ui.importStyle("core_ui/basic.otui")
g_ui.importStyle("core_ui/panels.otui")
g_ui.importStyle("core_ui/config.otui")
g_ui.importStyle("core_ui/icons.otui")
g_ui.importStyle("core_ui/container.otui")
connect(g_game, {
onGameStart = OnLogin,
onGameEnd = OnLogout,
})
end
function terminate()
Dispose()
disconnect(g_game, {
onGameStart = OnLogin,
onGameEnd = OnLogout,
})
end
Code:
Panel
width: 400
height: 200
id: mana_potion_panel
anchors.top: game_stats.bottom
anchors.left: game_stats.left
BotSwitch
text: Mana Potion
id: mana_potion_switch
anchors.top: parent.top
anchors.left: parent.left
text-align: center
BotTextEdit
id: mana_potion_textedit
anchors.top: mana_potion_switch.bottom
anchors.left: mana_potion_switch.left
anchors.right: mana_potion_switch.right
margin-top: 4
margin-left: 2
bot_src/main.lua
Lua:
local prev_timer = 0
-- load other bot .lua files
function BotOnTick()
local timer = os.clock()
if timer >= prev_timer then
prev_timer = timer + 1
print('hello',timer)
end
end
Last edited: