Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
39 lines (34 loc) · 1.57 KB
/
Copy pathmain.lua
File metadata and controls
39 lines (34 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- The script built step by step in bsx/lua/FIRST_MOD.md. It only reads the game.
-- Copy this folder to BSX/scripts/first_mod. Its lines go to BSX/bsx.log, prefixed [first_mod].
-- Settings come from settings.ini next to this file; the second value is the default.
local chord = config.string("FirstMod", "Hotkey", "ctrl+f6")
local greet = config.bool("FirstMod", "Greet", true)
-- data/ is this script's own folder for files. Count how many saves it has seen, across restarts.
local function load_count()
local ok, text = pcall(bsx.fs.read, "loads.txt")
return ok and tonumber(text) or 0
end
local loads = load_count()
-- game.player() returns the controlled character's actor, or nil and a reason.
local function describe_player()
local actor, why = game.player()
if not actor then return "no player yet (" .. why .. ")" end
local stats = game.stats(actor)
return string.format("player actor 0x%X, stat container %s", actor,
stats and string.format("0x%X", stats) or "not found")
end
bsx.on("save_loaded", function(e)
loads = loads + 1
bsx.fs.write("loads.txt", tostring(loads))
if greet then bsx.log("save loaded (" .. loads .. " so far): " .. describe_player()) end
end)
-- Keys need native BSX API 3 and [BSX] Keys=1 (the default). pcall keeps the script
-- running without the hotkey if they are unavailable.
local ok, why = pcall(bsx.hotkey, chord, function()
bsx.log(chord .. " pressed: " .. describe_player())
end)
if ok then
bsx.log("ready: press " .. chord .. " in game")
else
bsx.log("ready without a hotkey: " .. tostring(why))
end