############################# ####-- CRAWL OPTIONS #### ############################# name = Spaceman Spliff Species = Mi background = Fi weapon = flail #--tab combat settings autofight_stop = 0 autofight_caught = true autofight_hunger_stop = never explore_auto_rest = true confirm_butcher = never #--outside of brackets is shell < --inside of brackets is lua --------------------------- ---- LUA SECTION ---- --------------------------- --globals manual_mode = false --start in manual mode or naw single_step = false -- action_delay = 150 --ms between actions initted = false last_turn = -1 tries = 0 --auto_eat_chunks = false ------------------------------------------------------- ---- FUNCTIONS CALLED BY CRAWL AUTOMATICALLY ---- ------------------------------------------------------- function ready() --called by crawl when ready for user input if not manual_mode then if not initted then init_borg() end make_decision() last_turn = you.turns() --you.turns() is current turn # crawl.delay(action_delay) if single_step then manual_mode = true end end end function choose_stat_gain() --called by crawl when a stat is ready to be chosen --return 's' 'i' or 'd' return 'd' end function c_answer_prompt(prompt) --called when a teal colored prompt pops up if prompt:find("Keep eating") then return true end if prompt:find("Really walk") then return true end end --------------------------- ---- OTHER FUNCS ---- --------------------------- function init_borg() --clear_autopickup_funcs() --add_autopickup_func(autopickup) crawl.setopt("message_colour ^= mute:Unknown command") --needed for spam crawl.enable_more(false) -- disables all --more-- messages initted = true end function make_decision() --- decisions and actions --- if you.confused() then wiggle() end if you.hunger() < 4 then eat_food() end --you.hunger() if you.feel_safe() then --you.feel_safe() x,y = look_for_food() if x and y then --if see food then get it crawl.mpr('x:'..x.." y:"..y) if x == 0 and y == 0 then s = 'cc' else s = 'x' if x > 0 then c = 'l' else c = 'h' end for i = 1,math.abs(x) do s = s..c end if y > 0 then c = 'j' else c = 'k' end for i = 1,math.abs(y) do s = s..c end s = s..'\r' end send_keys(s) else send_keys('o'..string.char(27)) --spam after every input bcuz shops end else -- not feel safe send_keys('\t') end if last_turn == you.turns() then --bot is stuck wiggle() else tries = 0 end end --which items to pick up function autopickup(item,name) return true end --return true if enemy is on screen function see_enemy() local x,y for x = -7,7 do for y = -7,7 do m = monster.get_monster_at(x, y) if m and not m:is_safe() then return true end end end return false end --call this when stuck function wiggle() local keys = 'G>' if tries == 0 then keys = 'G>' elseif tries == 1 then dir = {'h','j','k','l','y','u','b','n'} i = crawl.random2(8)+1 keys = dir[i] elseif tries == 2 then keys = string.char(27) else dir = {'h','j','k','l','y','u','b','n',string.char(27)} i = crawl.random2(9)+1 keys = dir[i] end send_keys(keys) if last_turn == you.turns() then tries = tries + 1 end end function send_keys(command) crawl.flush_input() crawl.sendkeys(command) end --eat food function eat_food() l = '' for i = 0,51 do it = items.inslot(i) if it and string.find(it.name(),"chunk") then l = 'e' break elseif it and string.find(it.name(),"ration") then l = items.index_to_letter(i) end end send_keys('e'..l..string.char(27)) end --scans visible tiles for edible corpses function look_for_food() local x,y for x = -7,7 do for y = -7,7 do stack = items.get_items_at(x, y) if stack then for i = 1,#stack do if stack[i].name():find("corpse") then --crawl.mpr('x:'..x.." y:"..y) return x,y end end end end end end --toggle manual control function toggle_manual_mode() manual_mode = not manual_mode if single_step then crawl.mpr('--- step ---') else crawl.mpr('--- manual_mode is now ' .. tostring(manual_mode) ..'. ---') end end --toggle single-step function toggle_single_step() single_step = not single_step crawl.mpr('--- single_step is now ' .. tostring(single_step) ..'. ---') end >