RynthSuite as of 2026-10-04 (internal c94715f): RynthOracle (based on Oracle of Dereth by Advis Eveldan) and RynthInventory, RynthAi patrol doorways and rooms, healing priority, strict monster priority, finish the wounded target, slayer weapons, arcs when clear, blasts like rings, learn unknown spells, looting fixes, release 2026.10.4.6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c33e24a610
commit
12ca25f911
426 changed files with 108239 additions and 7521 deletions
19
Plugins/RynthCore.Plugin.RynthLua/Examples/README.md
Normal file
19
Plugins/RynthCore.Plugin.RynthLua/Examples/README.md
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# RynthLua examples
|
||||
|
||||
Copy a file into `C:\Games\RynthSuite\RynthLua\Scripts\` (or make a folder `<name>\` and
|
||||
save it there as `index.lua`), then `/lua start <name>` or press Start in the Lua panel.
|
||||
Scripts that listen for events keep running until you stop them (`/lua stop <name>`).
|
||||
|
||||
- `world-demo.lua`: game.World and WorldObject: what's around you and in your packs, filters (class, name, function), the selection, and the object, tell, selection and chat events.
|
||||
- `character-demo.lua`: game.Character: identity, vitals, skills, attributes, burden, inventory and equipment, enchantments, the spellbook, then every character event.
|
||||
- `actions-demo.lua`: the action queue: using an item on yourself with `await`, a failure as a value, a callback, a spell cast with retries, and `RunAllOrdered`. It really acts: set `KIT_NAME` and `SPELL_ID` first.
|
||||
- `library-demo.lua`: the modules: enums, `json`, `storage` (per script and per character), `filesystem`, `rynth.ai` and `rynthlua`.
|
||||
- `hud-demo.lua`: a small script window (`require("views")`, `require("imgui")`): a counter button, a checkbox and a running time; `/hud` shows or hides it. `/lua hud bench <n>` opens a test window with n widgets for measurements.
|
||||
- `xp-tracker.lua`: a tracker window: XP gained and per hour, kills, a health bar, and Reset with a tooltip; the first size set in `OnPreRender`.
|
||||
- `hunt-settings.lua`: a settings form saved with `storage` (checkbox, slider, 0-based combo, text box) and a button that sets your combat mode; `/hunt` shows or hides it.
|
||||
- `salvage-list.lua`: a list with buttons: your salvage, gathered in a spawned loop, a filter box, a scrolling region with `PushID` rows, and Use / Give buttons (Give waits for its result in a thread of its own). The buttons really act.
|
||||
- `item-icons.lua`: an item list with icons: your pack items drawn with their AC icons (`views.Huds.GetObjectIconTexture`, `ImGui.ImageButton`, `ImGui.Image`), an `InputInt` for how many rows and a `DragFloat` for the icon size. Nothing acts on the game. Needs an engine from 2026-09-30 or later.
|
||||
|
||||
The window examples need RynthCore API v71 with ImGui on; see "Script windows" in the reference.
|
||||
|
||||
The API reference is `docs/RYNTHLUA.md` in RynthSuite; `Types/` has editor completion for VS Code.
|
||||
64
Plugins/RynthCore.Plugin.RynthLua/Examples/actions-demo.lua
Normal file
64
Plugins/RynthCore.Plugin.RynthLua/Examples/actions-demo.lua
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
-- actions-demo.lua: the action queue (game.Actions).
|
||||
--
|
||||
-- AC does one use / cast / move at a time. Every game.Actions call (and every WorldObject
|
||||
-- action method: obj.Use(), obj.Give(npc), ...) queues an action and returns it at once;
|
||||
-- await(action) waits until it has finished and returns it. Then:
|
||||
-- action.Success true / false
|
||||
-- action.Error "None", "TooBusy", "TimedOut", "InvalidSourceObject", ... (ActionError.X)
|
||||
-- action.ErrorDetails what happened, in words
|
||||
-- action.Result what it made (the new stack of a split, the appraised object, ...)
|
||||
-- Options go in a table after the arguments: { Priority, TimeoutMilliseconds, MaxRetryCount,
|
||||
-- SkipChecks, Name }; a callback function, too, gets the action when it finishes.
|
||||
|
||||
local KIT_NAME = "Healing Kit" -- something in your pack you can use on yourself
|
||||
local SPELL_ID = 2 -- Strength Self I
|
||||
|
||||
local function report(a)
|
||||
if a.Success then
|
||||
print(("%s: done in %d ms"):format(a.Name, a.FinishedAt - a.StartedAt))
|
||||
else
|
||||
print(("%s failed: %s (%s)"):format(a.Name, a.Error, a.ErrorDetails))
|
||||
end
|
||||
end
|
||||
|
||||
-- 1. Use an item on yourself and wait for the server to finish it.
|
||||
local kit = game.World.GetInventory(KIT_NAME)[1]
|
||||
if kit then
|
||||
report(await(kit.UseOn(game.CharacterId))) -- same as game.Actions.ObjectUseOn(kit, game.CharacterId)
|
||||
else
|
||||
print("No " .. KIT_NAME .. " in your pack; skipping the use.")
|
||||
end
|
||||
|
||||
-- 2. Failures are values, not errors: check Success / Error.
|
||||
local bad = await(game.Actions.ObjectUse(0x7FFFFFF0)) -- no such object
|
||||
if bad.Error == ActionError.InvalidSourceObject then
|
||||
print("As expected: " .. bad.ErrorDetails)
|
||||
end
|
||||
|
||||
-- 3. A callback instead of await: the script carries on, the function runs when it's done.
|
||||
local target = game.World.Selected or game.Character.Weenie
|
||||
if target then
|
||||
game.Actions.ObjectAppraise(target, function(a)
|
||||
if a.Success then print("Appraised " .. a.Result.Name) else report(a) end
|
||||
end)
|
||||
end
|
||||
|
||||
-- 4. A cast. Fizzles and "You're too busy!" are retried (MaxRetryCount, 3 by default).
|
||||
local mode = await(game.Actions.SetCombatMode("Magic"))
|
||||
if mode.Success then
|
||||
local cast = await(game.Actions.CastSpell(SPELL_ID, 0, { MaxRetryCount = 2, TimeoutMilliseconds = 8000 }))
|
||||
report(cast)
|
||||
if cast.CurrentRetryCount > 0 then print(" (took " .. (cast.CurrentRetryCount + 1) .. " tries)") end
|
||||
else
|
||||
report(mode)
|
||||
end
|
||||
await(game.Actions.SetCombatMode("NonCombat"))
|
||||
|
||||
-- 5. Several steps as one queue entry, in order; stops at the first failure.
|
||||
local steps = await(game.Actions.RunAllOrdered({
|
||||
game.Actions.Sleep(500),
|
||||
game.Actions.InvokeChat("/e stretches."),
|
||||
}))
|
||||
report(steps)
|
||||
|
||||
print("Queue now: " .. tostring(game.ActionQueue))
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
-- character-demo.lua: a tour of game.Character (RynthLua v2).
|
||||
-- Prints who you are, your vitals, a few skills and attributes, burden, what you carry and
|
||||
-- wear, your enchantments, then watches the character events until you stop the script.
|
||||
|
||||
local C = game.Character
|
||||
|
||||
-- ── Who and what ────────────────────────────────────────────────────────────
|
||||
print(tostring(C))
|
||||
print(("%s, level %d, %s mode%s"):format(C.Name, C.Level, C.CombatModeName,
|
||||
C.InPortalSpace and " (in portal space)" or ""))
|
||||
print(("Vitae %.0f%% Busy: %s"):format(C.Vitae * 100, tostring(C.Busy)))
|
||||
print(("XP %d (unassigned %d) Luminance %d / %d"):format(C.TotalExperience, C.UnassignedExperience,
|
||||
C.AvailableLuminance, C.MaximumLuminance))
|
||||
|
||||
-- ── Vitals: shortcuts, by name, or by VitalId ───────────────────────────────
|
||||
print(("Health %d/%d Stamina %d/%d Mana %d/%d"):format(C.Health, C.MaxHealth,
|
||||
C.Stamina, C.MaxStamina, C.Mana, C.MaxMana))
|
||||
print(tostring(C.Vitals))
|
||||
local hp = C.Vitals.Health -- same object as C.Vitals[1] or C.Vital("Health")
|
||||
print(("Health: %d of %d (unbuffed max %d)"):format(hp.Current, hp.Max, hp.Base))
|
||||
|
||||
-- ── Skills and attributes: a SkillId number or a name ───────────────────────
|
||||
for _, name in ipairs({ "WarMagic", "LifeMagic", "MeleeDefense", "Healing" }) do
|
||||
local sk = C.Skill(name)
|
||||
print((" %-14s %4d (base %d) %s"):format(sk.Name, sk.Current, sk.Base, sk.TrainingName))
|
||||
end
|
||||
print("Trained skills:")
|
||||
for id, sk in pairs(C.Skills) do -- every skill, keyed by SkillId
|
||||
if sk.Training >= 2 then print((" %s %d"):format(sk.Name, sk.Current)) end
|
||||
end
|
||||
local str = C.Attribute("Strength")
|
||||
print(("Strength %d (base %d), Self %d"):format(str.Current, str.Base, C.Attributes.Self.Current))
|
||||
|
||||
-- ── Burden ──────────────────────────────────────────────────────────────────
|
||||
print(("Burden %d / %d (%.0f%%)"):format(C.BurdenUnits, C.MaxBurdenUnits, C.Burden))
|
||||
|
||||
-- ── Inventory and equipment (WorldObjects; filters: name, ObjectClass, function) ──
|
||||
local inv = C.Inventory()
|
||||
print(("Carrying %d items in %d side packs"):format(#inv, #C.Containers()))
|
||||
for _, wo in ipairs(C.Equipment()) do print(" wearing/wielding: " .. tostring(wo.Name)) end
|
||||
print("Pyreals: " .. C.InventoryCount("Pyreal"))
|
||||
print("Mana stones: " .. #C.Inventory(function(wo) return (wo.Name or ""):find("Mana Stone") ~= nil end))
|
||||
|
||||
-- ── Enchantments and the spellbook ──────────────────────────────────────────
|
||||
local enchantments = C.Enchantments()
|
||||
print(("%d enchantments:"):format(#enchantments))
|
||||
for _, e in ipairs(enchantments) do
|
||||
local left = e.Permanent and "permanent" or (e.Remaining and ("%ds left"):format(math.floor(e.Remaining)) or "?")
|
||||
print((" %s (%d): %s"):format(e.Name or "spell", e.SpellId, left))
|
||||
end
|
||||
print("Strength Self I active: " .. tostring(C.HasEnchantment(2)))
|
||||
print(("Spellbook: %d spells; knows Strength Self I: %s"):format(C.SpellBook.Count, tostring(C.KnowsSpell(2))))
|
||||
|
||||
-- ── Events ──────────────────────────────────────────────────────────────────
|
||||
C.OnVitalChanged.Add(function(e)
|
||||
if e.Type == VitalId.Health and e.Value < e.OldValue then
|
||||
print(("Ouch: health %d -> %d"):format(e.OldValue, e.Value))
|
||||
end
|
||||
end)
|
||||
C.OnCombatModeChanged.Add(function(e) print(("Combat mode %s -> %s"):format(e.OldModeName, e.NewModeName)) end)
|
||||
C.OnPortalSpaceEntered.Add(function() print("Entered portal space") end)
|
||||
C.OnPortalSpaceExited.Add(function() print("Left portal space") end)
|
||||
C.OnEnchantmentsChanged.Add(function(e)
|
||||
print(("Enchantment %s%s: %s (%d)"):format(e.TypeName, e.Refreshed and " (refreshed)" or "",
|
||||
e.Name or "spell", e.SpellId))
|
||||
end)
|
||||
C.OnDeath.Add(function(e) print("You died. " .. e.Text) end)
|
||||
C.OnLevelChanged.Add(function(e) print(("Level %d -> %d!"):format(e.OldLevel, e.Level)) end)
|
||||
C.OnVitaeChanged.Add(function(e) print(("Vitae %.0f%% -> %.0f%%"):format(e.OldVitae * 100, e.Vitae * 100)) end)
|
||||
|
||||
print("Watching character events; /lua stop character-demo to end.")
|
||||
56
Plugins/RynthCore.Plugin.RynthLua/Examples/hud-demo.lua
Normal file
56
Plugins/RynthCore.Plugin.RynthLua/Examples/hud-demo.lua
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
-- hud-demo.lua: a small window (script windows): a counter button, a checkbox and a
|
||||
-- running time.
|
||||
-- Needs RynthCore API v71 (engine) with ImGui on. Start it with /lua start hud-demo,
|
||||
-- close the window with its X, bring it back with /hud (or the bar's Scripts button).
|
||||
--
|
||||
-- OnRender runs about 20 times a second on the plugin thread and records what to draw;
|
||||
-- the engine draws it every frame. A click shows up as ImGui.Button returning true on the
|
||||
-- next pass (one pass late), and ImGui.Checkbox returns (changed, newValue).
|
||||
-- The full list of ImGui functions is in docs/RYNTHLUA.md ("Script windows"); see also
|
||||
-- xp-tracker.lua, hunt-settings.lua and salvage-list.lua.
|
||||
|
||||
local views = require("views")
|
||||
local ImGui = require("imgui")
|
||||
|
||||
if not views.Available then
|
||||
print("Script windows aren't available here (engine older than API v71, or ImGui is off).")
|
||||
end
|
||||
|
||||
local hud = views.Huds.CreateHud("Tracker")
|
||||
hud.Title = "Tracker demo"
|
||||
hud.Visible = true
|
||||
|
||||
local startedAt = clock()
|
||||
local clicks = 0
|
||||
local showTime = true
|
||||
|
||||
hud.OnRender.Add(function()
|
||||
ImGui.Text("Hello, " .. (game.Character.Name or "?"))
|
||||
ImGui.Separator()
|
||||
|
||||
if ImGui.Button("Count") then
|
||||
clicks = clicks + 1
|
||||
end
|
||||
ImGui.SameLine()
|
||||
ImGui.Text("clicked " .. clicks .. " time(s)")
|
||||
|
||||
local changed
|
||||
changed, showTime = ImGui.Checkbox("Show running time", showTime)
|
||||
if changed then print("Show running time: " .. tostring(showTime)) end
|
||||
|
||||
if showTime then
|
||||
local s = math.floor((clock() - startedAt) / 1000)
|
||||
ImGui.Text(("Running for %d:%02d"):format(math.floor(s / 60), s % 60))
|
||||
end
|
||||
|
||||
if ImGui.SmallButton("Reset") then
|
||||
clicks, startedAt = 0, clock()
|
||||
end
|
||||
end)
|
||||
|
||||
-- The player's X sets hud.Visible to false; /hud shows it again.
|
||||
game.RegisterCommand("/hud", function()
|
||||
hud.Visible = not hud.Visible
|
||||
end)
|
||||
|
||||
print("Tracker hud open. /hud toggles it; /lua stop hud-demo closes it.")
|
||||
37
Plugins/RynthCore.Plugin.RynthLua/Examples/hunt-settings.lua
Normal file
37
Plugins/RynthCore.Plugin.RynthLua/Examples/hunt-settings.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
-- hunt-settings.lua: a settings form (script windows) saved with storage: a checkbox, a
|
||||
-- slider, a drop-down and a text box, plus a button that sets your combat mode.
|
||||
-- Needs RynthCore API v71 (engine) with ImGui on. Start it with /lua start hunt-settings,
|
||||
-- then type /hunt to show or hide the window.
|
||||
--
|
||||
-- The settings are only an example: nothing reads them but this form, and they are kept
|
||||
-- in the script's storage (Data\hunt-settings\storage.json). The "Apply combat mode"
|
||||
-- button really changes your combat mode.
|
||||
--
|
||||
-- Value widgets return two values, (changed, newValue): keep the new value, and save when
|
||||
-- it changed. Combo's index is 0-based, as in ImGui.NET; the Lua list is 1-based.
|
||||
-- The window isn't shown at start, so the player's last choice decides: it opens again
|
||||
-- after a restart only if it was left open on this character.
|
||||
|
||||
local views, ImGui, storage = require("views"), require("imgui"), require("storage")
|
||||
|
||||
local s = storage.Get("settings", { enabled = true, range = 30, mode = 0, note = "" })
|
||||
local modes = { "Melee", "Missile", "Magic" }
|
||||
local function save() storage.Set("settings", s) end -- storage debounces the file write
|
||||
|
||||
local hud = views.Huds.CreateHud("Hunt Settings")
|
||||
|
||||
hud.OnRender.Add(function()
|
||||
local ch
|
||||
ch, s.enabled = ImGui.Checkbox("Enabled", s.enabled); if ch then save() end
|
||||
ch, s.range = ImGui.SliderInt("Range (m)", s.range, 5, 60); if ch then save() end
|
||||
ch, s.mode = ImGui.Combo("Mode", s.mode, modes); if ch then save() end -- 0-based, like UB
|
||||
ch, s.note = ImGui.InputText("Note", s.note, 128); if ch then save() end
|
||||
ImGui.Separator()
|
||||
if ImGui.Button("Apply combat mode") then
|
||||
game.Actions.SetCombatMode(modes[s.mode + 1])
|
||||
end
|
||||
end)
|
||||
|
||||
game.RegisterCommand("/hunt", function() hud.Visible = not hud.Visible end)
|
||||
|
||||
print("Hunt Settings ready: /hunt shows or hides the window.")
|
||||
63
Plugins/RynthCore.Plugin.RynthLua/Examples/item-icons.lua
Normal file
63
Plugins/RynthCore.Plugin.RynthLua/Examples/item-icons.lua
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
-- item-icons.lua: an item list with icons (script windows): your pack items with their
|
||||
-- AC icons, an InputInt for how many rows to show and a DragFloat for the icon size.
|
||||
-- Needs a RynthCore engine from 2026-09-30 or later (script windows "op level 2": icons
|
||||
-- and number inputs) with ImGui on. Start it with /lua start item-icons.
|
||||
--
|
||||
-- Nothing here acts on the game: clicking an icon only picks that row.
|
||||
--
|
||||
-- views.Huds.GetObjectIconTexture(id) is the item as AC draws it (underlay, icon,
|
||||
-- overlay). UB's way, views.Huds.GetIconTexture(iconId) + ImGui.Image(tex.TexturePtr, size),
|
||||
-- works too. Until the engine has decoded a picture (a frame or two), or when it can't find
|
||||
-- one, a dim square stands in: a missing icon is never an error.
|
||||
|
||||
local views, ImGui = require("views"), require("imgui")
|
||||
|
||||
local hud = views.Huds.CreateHud("Item Icons")
|
||||
hud.Visible = true
|
||||
hud.DefaultSize = Vector2.new(320, 360)
|
||||
|
||||
local rows, maxRows, iconSize, picked = {}, 25, 24, nil
|
||||
|
||||
spawn(function() -- gather the list once a second, not in every pass
|
||||
while true do
|
||||
local list = {}
|
||||
for _, wo in ipairs(game.Character.Inventory()) do
|
||||
list[#list + 1] = { id = wo.Id, name = wo.Name }
|
||||
end
|
||||
table.sort(list, function(a, b) return a.name < b.name end)
|
||||
rows = list
|
||||
sleep(1000)
|
||||
end
|
||||
end)
|
||||
|
||||
hud.OnRender.Add(function()
|
||||
local changed
|
||||
changed, maxRows = ImGui.InputInt("Rows", maxRows, 5, 25)
|
||||
if changed then maxRows = math.max(1, math.min(maxRows, 200)) end
|
||||
changed, iconSize = ImGui.DragFloat("Icon size", iconSize, 0.25, 16, 48, "%.0f px")
|
||||
ImGui.Separator()
|
||||
|
||||
if ImGui.BeginChild("items", Vector2.new(0, -ImGui.GetFrameHeight() - 6), true) then
|
||||
for i = 1, math.min(#rows, maxRows) do
|
||||
local r = rows[i]
|
||||
ImGui.PushID(r.id)
|
||||
local tex = views.Huds.GetObjectIconTexture(r.id)
|
||||
if ImGui.ImageButton("icon", tex, Vector2.new(iconSize, iconSize)) then picked = r end
|
||||
ImGui.SetItemTooltip(r.name)
|
||||
ImGui.SameLine()
|
||||
ImGui.Text(r.name)
|
||||
ImGui.PopID()
|
||||
end
|
||||
end
|
||||
ImGui.EndChild()
|
||||
|
||||
if picked then
|
||||
ImGui.Image(views.Huds.GetObjectIconTexture(picked.id), Vector2.new(16, 16))
|
||||
ImGui.SameLine()
|
||||
ImGui.Text("Picked: " .. picked.name)
|
||||
else
|
||||
ImGui.TextDisabled(#rows .. " items; click an icon to pick one")
|
||||
end
|
||||
end)
|
||||
|
||||
print("Item icons open. /lua stop item-icons closes it.")
|
||||
54
Plugins/RynthCore.Plugin.RynthLua/Examples/library-demo.lua
Normal file
54
Plugins/RynthCore.Plugin.RynthLua/Examples/library-demo.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
-- library-demo.lua: the RynthLua library modules in one script.
|
||||
-- Copy to C:\Games\RynthSuite\RynthLua\Scripts\library-demo.lua (or a folder
|
||||
-- library-demo\index.lua) and start it with /lua start library-demo.
|
||||
|
||||
local json = require("json")
|
||||
local storage = require("storage")
|
||||
local ai = require("rynth.ai")
|
||||
local fs = require("filesystem").GetData()
|
||||
|
||||
-- ── enums: globals, both ways ───────────────────────────────────────────────
|
||||
print("SkillId.MeleeDefense = " .. SkillId.MeleeDefense) -- 6
|
||||
print("ObjectClass[5] = " .. ObjectClass[5]) -- "Monster"
|
||||
print("ChatType.Tell = " .. ChatType.Tell .. ", IntId.Value = " .. IntId.Value)
|
||||
|
||||
-- ── json ───────────────────────────────────────────────────────────────────
|
||||
local snapshot = { script = game.ScriptName, when = os.time(), list = { 1, 2, 3 }, nested = { ok = true } }
|
||||
local text = json.encode(snapshot)
|
||||
print("json: " .. text)
|
||||
local back = json.decode(text)
|
||||
print("decoded list[3] = " .. back.list[3] .. ", nested.ok = " .. tostring(back.nested.ok))
|
||||
local ok, err = pcall(json.encode, { fn = print })
|
||||
print("encoding a function fails: " .. tostring(err))
|
||||
|
||||
-- ── storage: survives restarts, per script and per character ────────────────
|
||||
local runs = storage.Get("runs", 0) + 1
|
||||
storage.Set("runs", runs)
|
||||
storage.Set("lastRun", snapshot)
|
||||
print(("storage: this script has run %d time(s); keys: %s"):format(runs, table.concat(storage.Keys(), ", ")))
|
||||
if game.State == "InGame" then
|
||||
local mine = storage.Character.Get("runs", 0) + 1
|
||||
storage.Character.Set("runs", mine)
|
||||
print(("storage.Character: %d run(s) on this character"):format(mine))
|
||||
end
|
||||
|
||||
-- ── filesystem: your own files in the data folder ───────────────────────────
|
||||
fs.AppendText("log.txt", os.date("%Y-%m-%d %H:%M:%S") .. " run " .. runs .. "\n")
|
||||
local lines = fs.ReadLines("log.txt")
|
||||
print("filesystem: log.txt has " .. #lines .. " line(s), last: " .. lines[#lines])
|
||||
local refused, why = fs.WriteText("../outside.txt", "nope")
|
||||
print("writing outside the folder is refused: " .. tostring(why))
|
||||
|
||||
-- ── rynth.ai: only when RynthAi is loaded ───────────────────────────────────
|
||||
if ai.Available then
|
||||
print("RynthAi: macro " .. (ai.MacroRunning and "running" or "stopped"))
|
||||
print("expression getcharvital_current[1] = " .. tostring(ai.Evaluate("getcharvital_current[1]")))
|
||||
local portal, distance = ai.FindNearest("Portal", true)
|
||||
if portal then print(("nearest portal: %s (%d) at %.1f m"):format(portal.Name or "?", portal.Id, distance)) end
|
||||
else
|
||||
print("RynthAi isn't loaded; rynth.ai calls would raise an error")
|
||||
end
|
||||
|
||||
-- ── rynthlua: the plugin's own info ─────────────────────────────────────────
|
||||
local info = require("rynthlua")
|
||||
print(("RynthLua %s, data folder %s"):format(info.Version, info.DataFolder))
|
||||
57
Plugins/RynthCore.Plugin.RynthLua/Examples/salvage-list.lua
Normal file
57
Plugins/RynthCore.Plugin.RynthLua/Examples/salvage-list.lua
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
-- salvage-list.lua: a list with buttons (script windows): your salvage bags, a filter box,
|
||||
-- and Use / Give buttons on each row.
|
||||
-- Needs RynthCore API v71 (engine) with ImGui on. Start it with /lua start salvage-list.
|
||||
--
|
||||
-- The buttons really act: Use uses the bag, "Give to selected" gives it to whatever you
|
||||
-- have selected.
|
||||
--
|
||||
-- The list is gathered in a spawned thread once a second, not in every pass: OnRender only
|
||||
-- draws what it has. OnRender can't sleep or await, so the Give button starts a thread of
|
||||
-- its own to wait for the result. PushID(r.id) gives each row's buttons their own IDs, so
|
||||
-- every row can have a "Use" button.
|
||||
|
||||
local views, ImGui = require("views"), require("imgui")
|
||||
|
||||
local hud = views.Huds.CreateHud("Salvage")
|
||||
hud.Visible = true
|
||||
local rows, filter = {}, ""
|
||||
|
||||
spawn(function() -- refresh the data once a second, not in every pass
|
||||
while true do
|
||||
rows = {}
|
||||
for _, wo in ipairs(game.Character.Inventory(ObjectClass.Salvage)) do
|
||||
rows[#rows + 1] = { id = wo.Id, name = wo.Name, obj = wo }
|
||||
end
|
||||
sleep(1000)
|
||||
end
|
||||
end)
|
||||
|
||||
local function give(r)
|
||||
local target = game.World.Selected
|
||||
if not target then print("Select someone to give to first.") return end
|
||||
spawn(function() -- OnRender can't await; a spawned thread can
|
||||
local a = await(r.obj.Give(target))
|
||||
if not a.Success then print("give failed: " .. a.Error .. " " .. (a.ErrorDetails or "")) end
|
||||
end)
|
||||
end
|
||||
|
||||
hud.OnRender.Add(function()
|
||||
local _
|
||||
_, filter = ImGui.InputText("Filter", filter, 64)
|
||||
if ImGui.BeginChild("rows", Vector2.new(0, 0), true) then
|
||||
for _, r in ipairs(rows) do
|
||||
if filter == "" or r.name:lower():find(filter:lower(), 1, true) then
|
||||
ImGui.PushID(r.id)
|
||||
ImGui.Text(r.name)
|
||||
ImGui.SameLine(220)
|
||||
if ImGui.SmallButton("Use") then r.obj.Use() end
|
||||
ImGui.SameLine()
|
||||
if ImGui.SmallButton("Give to selected") then give(r) end
|
||||
ImGui.PopID()
|
||||
end
|
||||
end
|
||||
end
|
||||
ImGui.EndChild()
|
||||
end)
|
||||
|
||||
print("Salvage list open. /lua stop salvage-list closes it.")
|
||||
348
Plugins/RynthCore.Plugin.RynthLua/Examples/smoke-test.lua
Normal file
348
Plugins/RynthCore.Plugin.RynthLua/Examples/smoke-test.lua
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
-- RynthLua smoke test: exercises the v2 API in game and reports PASS / FAIL / INFO.
|
||||
--
|
||||
-- Run it somewhere safe (it switches combat mode and back, selects and appraises things;
|
||||
-- it never uses, moves, drops or gives anything):
|
||||
-- /lua run smoke-test
|
||||
-- Results go to this script's console and to
|
||||
-- C:\Games\RynthSuite\RynthLua\Data\smoke-test\results.txt
|
||||
-- Afterwards it stays running for its chat command:
|
||||
-- /smoketest hello -> answers "pong: hello" (tests script commands)
|
||||
-- /smoketest stop -> stops the script via stop() (tests game.OnScriptEnd)
|
||||
-- Run it again afterwards (or after /rc rl): the "persist" checks compare with the last run.
|
||||
|
||||
local json = require("json")
|
||||
local storage = require("storage")
|
||||
local fs = require("filesystem").GetData()
|
||||
local ai = require("rynth.ai")
|
||||
local info_m = require("rynthlua")
|
||||
|
||||
local C, W, A, Q = game.Character, game.World, game.Actions, game.ActionQueue
|
||||
local lines, counts = {}, { PASS = 0, FAIL = 0, INFO = 0 }
|
||||
|
||||
local function out(kind, name, detail)
|
||||
counts[kind] = counts[kind] + 1
|
||||
local line = kind .. " " .. name
|
||||
if detail ~= nil and detail ~= "" then line = line .. ": " .. tostring(detail) end
|
||||
lines[#lines + 1] = line
|
||||
print(line)
|
||||
end
|
||||
|
||||
-- check(name, fn): fn returns ok [, detail]; an error is a FAIL with the message.
|
||||
local function check(name, fn)
|
||||
local ok, r, d = pcall(fn)
|
||||
if not ok then out("FAIL", name, r)
|
||||
elseif r then out("PASS", name, d)
|
||||
else out("FAIL", name, d) end
|
||||
end
|
||||
|
||||
-- note(name, fn): fn returns a value to report; never a failure unless it errors.
|
||||
local function note(name, fn)
|
||||
local ok, r = pcall(fn)
|
||||
if ok then out("INFO", name, r) else out("FAIL", name, r) end
|
||||
end
|
||||
|
||||
local function section(title)
|
||||
lines[#lines + 1] = ""
|
||||
lines[#lines + 1] = "== " .. title
|
||||
print("== " .. title)
|
||||
end
|
||||
|
||||
local function count(t) local n = 0; for _ in pairs(t or {}) do n = n + 1 end; return n end
|
||||
|
||||
local runStarted = os.time()
|
||||
out("INFO", "started", os.date("%Y-%m-%d %H:%M:%S") .. " on " .. game.ServerName .. " as " .. C.Name)
|
||||
|
||||
-- ── Environment ───────────────────────────────────────────────────────────
|
||||
section("Environment")
|
||||
check("game.State is InGame", function() return game.State == "InGame", game.State end)
|
||||
check("game.CharacterId", function() return game.CharacterId ~= 0, string.format("0x%08X", game.CharacterId) end)
|
||||
check("game.ServerName", function() return game.ServerName ~= "", game.ServerName end)
|
||||
check("game.ScriptName", function() return game.ScriptName == "smoke-test", game.ScriptName end)
|
||||
check("rynthlua module", function() return info_m.Name == "RynthLua", tostring(info_m.Version) .. ", data " .. tostring(info_m.DataFolder) end)
|
||||
check("clock() advances", function() local a = clock(); sleep(50); local b = clock(); return b - a >= 40, (b - a) .. " ms" end)
|
||||
|
||||
-- ── Persistence from the last run ─────────────────────────────────────────
|
||||
section("Persistence (last run)")
|
||||
local runs = storage.Get("runs", 0)
|
||||
local lastStart, lastEnd = storage.Get("lastStart"), storage.Get("lastEnd")
|
||||
if runs == 0 then
|
||||
out("INFO", "first run", "run again after /smoketest stop (or /rc rl) to check persistence")
|
||||
else
|
||||
out("PASS", "storage kept the run count", "run #" .. (runs + 1))
|
||||
check("game.OnScriptEnd saved on the last stop", function()
|
||||
return lastEnd ~= nil and lastStart ~= nil and lastEnd >= lastStart,
|
||||
"lastStart " .. tostring(lastStart) .. ", lastEnd " .. tostring(lastEnd)
|
||||
end)
|
||||
check("storage.Character kept its value", function()
|
||||
local v = storage.Character.Get("seen")
|
||||
return v == C.Name, tostring(v)
|
||||
end)
|
||||
end
|
||||
storage.Set("runs", runs + 1)
|
||||
storage.Set("lastStart", runStarted)
|
||||
storage.Character.Set("seen", C.Name)
|
||||
check("storage.Save()", function() return storage.Save() == true end)
|
||||
|
||||
game.OnScriptEnd.Add(function()
|
||||
storage.Set("lastEnd", os.time())
|
||||
storage.Save()
|
||||
end)
|
||||
|
||||
-- ── Enums, json ───────────────────────────────────────────────────────────
|
||||
section("Enums and json")
|
||||
check("SkillId both ways", function() return SkillId.WarMagic == 34 and SkillId[34] == "WarMagic" end)
|
||||
check("SkillId any case", function() return SkillId.warmagic == 34 end)
|
||||
check("ObjectClass.Portal", function() return ObjectClass.Portal == 14 and ObjectClass[14] == "Portal" end)
|
||||
check("CombatMode.Magic", function() return CombatMode.Magic == 8 end)
|
||||
check("IntId.StackSize", function() return IntId.StackSize == 12 end)
|
||||
check("ActionError.TooBusy", function() return ActionError.TooBusy == "TooBusy" end)
|
||||
check("require('enums') == globals", function() return require("enums").VitalId.Mana == VitalId.Mana end)
|
||||
check("json round trip", function()
|
||||
local t = json.decode(json.encode({ a = 1, b = { 1, 2, 3 }, c = "x", d = true }))
|
||||
return t.a == 1 and #t.b == 3 and t.c == "x" and t.d == true
|
||||
end)
|
||||
check("json empty table is []", function() return json.encode({}) == "[]", json.encode({}) end)
|
||||
check("global json is RynthLua's", function() return type(json.encode) == "function" and _G.json.encode ~= nil end)
|
||||
check("json error on a function", function() return not pcall(json.encode, { f = print }) end)
|
||||
|
||||
-- ── Character ─────────────────────────────────────────────────────────────
|
||||
section("game.Character")
|
||||
check("Name / Level", function() return C.Name ~= "" and C.Level > 0, C.Name .. ", level " .. C.Level end)
|
||||
check("Id matches game.CharacterId", function() return C.Id == game.CharacterId end)
|
||||
check("Weenie is you", function() local w = C.Weenie; return w ~= nil and w.Id == C.Id, tostring(w) end)
|
||||
check("Health within Max", function() return C.Health > 0 and C.Health <= C.MaxHealth, C.Health .. "/" .. C.MaxHealth end)
|
||||
check("Stamina / Mana", function() return C.MaxStamina > 0 and C.MaxMana >= 0, C.Stamina .. "/" .. C.MaxStamina .. ", " .. C.Mana .. "/" .. C.MaxMana end)
|
||||
check("Vitals.Health matches", function() local v = C.Vitals.Health; return v.Current == C.Health and v.Max == C.MaxHealth, "base " .. tostring(v.Base) end)
|
||||
check("Vitals[VitalId.Mana]", function() return C.Vitals[VitalId.Mana].Max == C.MaxMana end)
|
||||
check("Vital('stamina')", function() return C.Vital("stamina").Max == C.MaxStamina end)
|
||||
check("Skills has entries", function() local n = count(C.Skills); return n >= 30, n .. " skills" end)
|
||||
check("Skill('war magic')", function()
|
||||
local s = C.Skill("war magic")
|
||||
return s.Id == 34 and type(s.Training) == "number" and type(s.TrainingName) == "string",
|
||||
s.Name .. " " .. s.Current .. " (base " .. s.Base .. ", " .. s.TrainingName .. ")"
|
||||
end)
|
||||
check("Skill trained flag", function()
|
||||
local s = C.Skills[SkillId.MeleeDefense]
|
||||
return s.IsTrained == (s.Training >= 2), "Melee Defense " .. s.Current .. " " .. s.TrainingName
|
||||
end)
|
||||
check("Attributes", function()
|
||||
local a = C.Attributes.Strength
|
||||
return a.Current > 0 and C.Attribute(AttributeId.Self).Current > 0, "Str " .. a.Current .. " (base " .. a.Base .. ")"
|
||||
end)
|
||||
check("CombatMode is a number", function() return type(C.CombatMode) == "number" and C.CombatModeName ~= "", C.CombatModeName end)
|
||||
check("Burden", function() return C.MaxBurdenUnits > 0, C.BurdenUnits .. "/" .. C.MaxBurdenUnits .. " (" .. string.format("%.0f", C.Burden) .. "%)" end)
|
||||
note("Vitae", function() return C.Vitae end)
|
||||
note("Busy / InPortalSpace", function() return tostring(C.Busy) .. " / " .. tostring(C.InPortalSpace) end)
|
||||
note("Experience", function() return "total " .. C.TotalExperience .. ", unassigned " .. C.UnassignedExperience end)
|
||||
check("SpellBook loads", function()
|
||||
local ok = waitfor(function() return C.SpellBook.Count > 0 end, 6000)
|
||||
return ok, C.SpellBook.Count .. " spells"
|
||||
end)
|
||||
check("KnowsSpell(first known)", function()
|
||||
local ids = C.SpellBook.KnownSpellIds()
|
||||
if #ids == 0 then return false, "spellbook empty" end
|
||||
return C.KnowsSpell(ids[1]) and not C.KnowsSpell(65000), "spell " .. ids[1] .. " (" .. tostring(C.SpellBook.Name(ids[1])) .. ")"
|
||||
end)
|
||||
check("Enchantments()", function()
|
||||
local e = C.Enchantments()
|
||||
local sample = e[1] and (tostring(e[1].Name or e[1].SpellId) .. ", " .. tostring(e[1].Remaining) .. " s left") or "none active"
|
||||
return type(e) == "table", #e .. " active; " .. sample
|
||||
end)
|
||||
local inv = {}
|
||||
check("Inventory()", function() inv = C.Inventory(); return #inv > 0, #inv .. " items" end)
|
||||
local equip = {}
|
||||
check("Equipment()", function() equip = C.Equipment(); return #equip > 0, #equip .. " worn/wielded" end)
|
||||
check("Equipment is inside Inventory", function()
|
||||
local ids = {}
|
||||
for _, wo in ipairs(inv) do ids[wo.Id] = true end
|
||||
for _, wo in ipairs(equip) do if not ids[wo.Id] then return false, tostring(wo) .. " missing" end end
|
||||
return true
|
||||
end)
|
||||
check("Equipment wielded by you", function()
|
||||
for _, wo in ipairs(equip) do if wo.WielderId ~= C.Id then return false, tostring(wo) .. " wielder " .. wo.WielderId end end
|
||||
return true
|
||||
end)
|
||||
note("Containers()", function() local c = C.Containers(); return #c .. " side packs" end)
|
||||
note("InventoryCount('Pyreal')", function() return C.InventoryCount("Pyreal") end)
|
||||
check("Inventory filter by function", function()
|
||||
local packs = C.Inventory(function(wo) return wo.ObjectClass == ObjectClass.Container end)
|
||||
return #packs == #C.Containers(), #packs .. " containers"
|
||||
end)
|
||||
|
||||
-- ── World ─────────────────────────────────────────────────────────────────
|
||||
section("game.World")
|
||||
check("Get(me)", function() local wo = W.Get(C.Id); return wo ~= nil and wo.Name == C.Name, tostring(wo) end)
|
||||
check("World[id] / Exists", function() return W[C.Id] ~= nil and W.Exists(C.Id) and not W.Exists(1) end)
|
||||
check("Get('0x...') string id", function() return W.Get(string.format("0x%08X", C.Id)) ~= nil end)
|
||||
local all, land = {}, {}
|
||||
check("GetAll()", function() all = W.GetAll(); return #all > #inv, #all .. " known objects" end)
|
||||
check("GetLandscape()", function() land = W.GetLandscape(); return #land > 0, #land .. " on the landscape" end)
|
||||
check("GetInventory() matches Character.Inventory()", function()
|
||||
local wi = W.GetInventory()
|
||||
return #wi == #inv, "World " .. #wi .. ", Character " .. #inv
|
||||
end)
|
||||
check("Landscape has no carried items", function()
|
||||
for _, wo in ipairs(land) do
|
||||
if wo.ContainerId ~= 0 or wo.WielderId ~= 0 or wo.Id == C.Id then return false, tostring(wo) end
|
||||
end
|
||||
return true
|
||||
end)
|
||||
check("class name filter == class number filter", function()
|
||||
local a, b = #W.GetAll("Monster"), #W.GetAll(ObjectClass.Monster)
|
||||
return a == b, a .. " monsters"
|
||||
end)
|
||||
note("portals nearby", function() return #W.GetLandscape(ObjectClass.Portal) end)
|
||||
note("players nearby", function() return #W.GetLandscape(ObjectClass.Player) end)
|
||||
local near
|
||||
check("GetNearest(function)", function()
|
||||
near = W.GetNearest(function(wo) return wo.Name ~= "" end)
|
||||
return near ~= nil, near and (tostring(near) .. " at " .. string.format("%.1f", near.DistanceTo(C.Weenie)) .. " m") or "nothing"
|
||||
end)
|
||||
if near then
|
||||
check("WorldObject basics", function()
|
||||
return type(near.ObjectClass) == "number" and type(near.ObjectClassName) == "string" and near.WeenieClassId > 0,
|
||||
near.ObjectClassName .. ", wcid " .. near.WeenieClassId
|
||||
end)
|
||||
check("WorldObject Position", function()
|
||||
local p = near.Position
|
||||
return p ~= nil and p.Landcell ~= 0, p and string.format("%.2f%s %.2f%s, z %.1f, cell 0x%08X",
|
||||
math.abs(p.NS), p.NS >= 0 and "N" or "S", math.abs(p.EW), p.EW >= 0 and "E" or "W", p.Z, p.Landcell) or "nil"
|
||||
end)
|
||||
check("tostring / equality", function()
|
||||
local again = W.Get(near.Id)
|
||||
return again == near and tostring(near):find("0x") ~= nil, tostring(near)
|
||||
end)
|
||||
end
|
||||
local item = inv[1]
|
||||
for _, wo in ipairs(inv) do if wo.ObjectClass ~= ObjectClass.Container and wo.WielderId == 0 then item = wo; break end end
|
||||
if item then
|
||||
check("inventory item properties", function()
|
||||
return item.ContainerId ~= 0 and item.StackSize >= 1,
|
||||
tostring(item) .. " in " .. tostring(item.Container) .. ", stack " .. item.StackSize .. ", value " .. item:Value(IntId.Value) .. ", burden " .. item.Burden
|
||||
end)
|
||||
note("item IntValue(IntId.Value) / HasAppraisalData", function() return tostring(item.IntValue(IntId.Value, -1)) .. " / " .. tostring(item.HasAppraisalData) end)
|
||||
end
|
||||
local packs = C.Containers()
|
||||
if #packs > 0 then
|
||||
check("pack Items()", function() local it = packs[1].Items(); return type(it) == "table", tostring(packs[1]) .. ": " .. #it .. " items" end)
|
||||
end
|
||||
note("Selected", function() return tostring(W.Selected) end)
|
||||
|
||||
-- ── Actions ───────────────────────────────────────────────────────────────
|
||||
section("game.Actions")
|
||||
local t0 = clock()
|
||||
local sl = await(A.Sleep(300))
|
||||
check("Sleep + await", function() return sl.Success and sl.IsFinished and clock() - t0 >= 280, (clock() - t0) .. " ms, Error " .. sl.Error end)
|
||||
|
||||
check("bad argument is an error", function() return not pcall(A.ObjectUse) end)
|
||||
|
||||
local selectedEvent = false
|
||||
W.OnSelected.Once(function(e) selectedEvent = (item ~= nil and e.ObjectId == item.Id) end)
|
||||
if item then
|
||||
local cbFired = false
|
||||
local a = await(A.ObjectSelect(item, function(act) cbFired = true end))
|
||||
check("ObjectSelect", function() return a.Success and W.Selected ~= nil and W.Selected.Id == item.Id, "Error " .. a.Error .. " " .. a.ErrorDetails end)
|
||||
check("action callback ran", function() return waitfor(function() return cbFired end, 2000) end)
|
||||
check("World.OnSelected fired", function() return waitfor(function() return selectedEvent end, 2000) end)
|
||||
local m = await(item.Select())
|
||||
check("WorldObject:Select() method", function() return m.Success, m.Error end)
|
||||
end
|
||||
|
||||
local apTarget = near or item
|
||||
if apTarget then
|
||||
local ap = await(A.ObjectAppraise(apTarget))
|
||||
check("ObjectAppraise", function() return ap.Success, tostring(apTarget) .. ", Error " .. ap.Error .. " " .. ap.ErrorDetails end)
|
||||
note("appraised HasAppraisalData", function() return tostring(apTarget.HasAppraisalData) end)
|
||||
end
|
||||
|
||||
-- Combat mode: to a fighting mode that suits what you wield, then back.
|
||||
local startMode = C.CombatMode
|
||||
local fightMode = CombatMode.Melee
|
||||
for _, wo in ipairs(equip) do
|
||||
if wo.ObjectClass == ObjectClass.MissileWeapon then fightMode = CombatMode.Missile end
|
||||
if wo.ObjectClass == ObjectClass.WandStaffOrb then fightMode = CombatMode.Magic end
|
||||
end
|
||||
local modeEvents = 0
|
||||
C.OnCombatModeChanged.Add(function(e) modeEvents = modeEvents + 1 end)
|
||||
local same = await(A.SetCombatMode(startMode))
|
||||
check("SetCombatMode(current) is immediate", function() return same.Success, same.Error end)
|
||||
local target = startMode == CombatMode.NonCombat and fightMode or CombatMode.NonCombat
|
||||
local m1 = await(A.SetCombatMode(target))
|
||||
check("SetCombatMode -> " .. CombatMode[target], function() return m1.Success and C.CombatMode == target, "now " .. C.CombatModeName .. ", Error " .. m1.Error .. " " .. m1.ErrorDetails end)
|
||||
local m2 = await(A.SetCombatMode(startMode))
|
||||
check("SetCombatMode back -> " .. CombatMode[startMode], function() return m2.Success and C.CombatMode == startMode, "now " .. C.CombatModeName .. ", Error " .. m2.Error end)
|
||||
check("OnCombatModeChanged fired", function() return waitfor(function() return modeEvents >= 2 end, 2000), modeEvents .. " events" end)
|
||||
|
||||
local long = A.Sleep(5000)
|
||||
long.Cancel()
|
||||
await(long)
|
||||
check("Cancel()", function() return long.IsFinished and not long.Success and long.Error == "Cancelled", long.Error end)
|
||||
|
||||
local s1, s2 = A.Sleep(100), A.Sleep(100)
|
||||
local all2 = await(A.RunAllOrdered({ s1, s2 }))
|
||||
check("RunAllOrdered", function() return all2.Success and s1.Success and s2.Success, all2.Error end)
|
||||
check("ActionQueue", function() return type(Q.Count) == "number" and type(Q.IsBusy) == "boolean", "count " .. Q.Count .. ", busy " .. tostring(Q.IsBusy) end)
|
||||
|
||||
-- ── Events ────────────────────────────────────────────────────────────────
|
||||
section("Events")
|
||||
local ticks = 0
|
||||
local function onTick() ticks = ticks + 1 end
|
||||
game.OnTick.Add(onTick)
|
||||
sleep(1000)
|
||||
game.OnTick.Remove(onTick)
|
||||
check("game.OnTick", function() return ticks >= 5, ticks .. " ticks in 1 s" end)
|
||||
local after = ticks
|
||||
sleep(300)
|
||||
-- A handler call started in the same tick as Remove may still finish once.
|
||||
check("Event Remove", function() return ticks <= after + 1, (ticks - after) .. " late call(s)" end)
|
||||
local untilN = 0
|
||||
game.OnTick.Until(function() untilN = untilN + 1; return untilN >= 3 end)
|
||||
sleep(600)
|
||||
check("Event Until stops at true", function() return untilN == 3, untilN end)
|
||||
local vitalEvents = 0
|
||||
C.OnVitalChanged.Add(function() vitalEvents = vitalEvents + 1 end)
|
||||
note("Character.OnVitalChanged (seen so far)", function() return vitalEvents end)
|
||||
local chatSeen = false
|
||||
W.OnChatText.Once(function(e) chatSeen = true end)
|
||||
chat("[smoke-test] chat line to your own window")
|
||||
note("World.OnChatText from chat()", function() return tostring(waitfor(function() return chatSeen end, 1500)) end)
|
||||
|
||||
-- ── RynthAi (rynth.ai module and v1 globals) ──────────────────────────────
|
||||
section("RynthAi")
|
||||
if not ai.Available then
|
||||
out("INFO", "rynth.ai", "RynthAi not loaded, skipped")
|
||||
else
|
||||
out("PASS", "rynth.ai Available")
|
||||
check("SettingNames()", function() local n = ai.SettingNames(); return #n > 0, #n .. " settings" end)
|
||||
note("MacroRunning", function() return tostring(ai.MacroRunning) end)
|
||||
note("Evaluate('getcharintprop[25]') (level)", function() return tostring(ai.Evaluate("getcharintprop[25]")) end)
|
||||
if near then note("ai.DistanceTo(nearest)", function() return ai.DistanceTo(near) end) end
|
||||
note("ai.FindNearest('Portal', true)", function() local wo, d = ai.FindNearest("Portal", true); return tostring(wo) .. " " .. tostring(d) end)
|
||||
-- v1 globals (me, expr, ...) come from RynthAi too.
|
||||
check("v1 me.name", function() return me.name == C.Name end)
|
||||
check("v1 me.maxhealth", function() return me.maxhealth == C.MaxHealth, "me " .. tostring(me.maxhealth) .. ", Character " .. C.MaxHealth .. " (base " .. C.Vitals.Health.Base .. ")" end)
|
||||
check("v1 me.maxmana", function() return me.maxmana == C.MaxMana, "me " .. tostring(me.maxmana) .. ", Character " .. C.MaxMana end)
|
||||
end
|
||||
|
||||
-- ── Command, results ──────────────────────────────────────────────────────
|
||||
section("Done")
|
||||
game.RegisterCommand("/smoketest", function(args)
|
||||
local line = "INFO /smoketest " .. args .. ": command received"
|
||||
print(line)
|
||||
local prev = fs.ReadText("results.txt") or ""
|
||||
fs.WriteText("results.txt", prev .. "\n" .. line)
|
||||
if args == "stop" then
|
||||
print("stopping via stop()")
|
||||
stop()
|
||||
else
|
||||
chat("[smoke-test] pong: " .. args)
|
||||
end
|
||||
end)
|
||||
|
||||
local summary = string.format("%d passed, %d failed, %d info", counts.PASS, counts.FAIL, counts.INFO)
|
||||
lines[#lines + 1] = ""
|
||||
lines[#lines + 1] = summary
|
||||
print(summary)
|
||||
local ok, err = fs.WriteText("results.txt", table.concat(lines, "\n"))
|
||||
if not ok then print("couldn't write results.txt: " .. tostring(err)) end
|
||||
chat("[smoke-test] " .. summary .. ". Now try /smoketest hello, then /smoketest stop.")
|
||||
93
Plugins/RynthCore.Plugin.RynthLua/Examples/world-demo.lua
Normal file
93
Plugins/RynthCore.Plugin.RynthLua/Examples/world-demo.lua
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
-- world-demo: a tour of game.World and WorldObject.
|
||||
-- Prints what's around you and in your packs, then keeps listening for
|
||||
-- objects, tells and selection changes until you press Stop.
|
||||
|
||||
local World = game.World
|
||||
|
||||
-- ObjectClass numbers (Decal/UtilityBelt order). A filter can also be the exact
|
||||
-- class name as a string: World.GetLandscape("Monster").
|
||||
local MONSTER, PORTAL, CORPSE = 5, 14, 27
|
||||
|
||||
local function where(wo)
|
||||
local p = wo.Position
|
||||
if not p then return "(no position)" end
|
||||
return ("%.1f%s %.1f%s"):format(math.abs(p.NS), p.NS >= 0 and "N" or "S",
|
||||
math.abs(p.EW), p.EW >= 0 and "E" or "W")
|
||||
end
|
||||
|
||||
-- Around you ----------------------------------------------------------------
|
||||
local me = World.Get(game.CharacterId)
|
||||
if not me then print("Log in first.") return end
|
||||
print("You are " .. tostring(me) .. " at " .. where(me))
|
||||
|
||||
local monsters = World.GetLandscape(MONSTER)
|
||||
print(#monsters .. " monster(s) nearby")
|
||||
for _, m in ipairs(monsters) do
|
||||
print((" %-28s %6.1f m wcid %d"):format(m.Name, me:DistanceTo(m), m.WeenieClassId))
|
||||
end
|
||||
|
||||
local portal = World.GetNearest("Portal") -- by class name
|
||||
if portal then
|
||||
print("Nearest portal: " .. portal.Name .. " at " .. where(portal))
|
||||
end
|
||||
|
||||
-- A function filter: corpses within 30 m.
|
||||
local close = World.GetLandscape(function(wo)
|
||||
return wo.ObjectClass == CORPSE and me:DistanceTo(wo) < 30
|
||||
end)
|
||||
print(#close .. " corpse(s) within 30 m")
|
||||
|
||||
-- Your stuff ----------------------------------------------------------------
|
||||
local inv = World.GetInventory()
|
||||
print(#inv .. " item(s) in your packs (game.Character.Inventory() adds what you wear)")
|
||||
local burden = 0
|
||||
for _, item in ipairs(inv) do burden = burden + item.Burden end
|
||||
print("Burden of appraised items: " .. burden)
|
||||
|
||||
for _, pack in ipairs(World.GetInventory(function(wo) return wo.ObjectClass == 10 end)) do
|
||||
print((" %s holds %d item(s)"):format(pack.Name, #pack:Items()))
|
||||
end
|
||||
|
||||
local tapers = World.GetInventory("Taper") -- a name substring
|
||||
for _, p in ipairs(tapers) do
|
||||
print((" %s x%d (stack prop 12 = %d)"):format(p.Name, p.StackSize, p:IntValue(12, 1)))
|
||||
end
|
||||
|
||||
-- The selection ---------------------------------------------------------------
|
||||
local sel = World.Selected
|
||||
if sel then
|
||||
print("Selected: " .. tostring(sel) .. ", class " .. sel.ObjectClass ..
|
||||
", appraised: " .. tostring(sel.HasAppraisalData))
|
||||
end
|
||||
|
||||
-- Events ------------------------------------------------------------------------
|
||||
World.OnObjectCreated.Add(function(e)
|
||||
local wo = e.Object
|
||||
if wo and wo.ObjectClass == PORTAL then
|
||||
print("A portal appeared: " .. wo.Name)
|
||||
end
|
||||
end)
|
||||
|
||||
World.OnObjectReleased.Add(function(e)
|
||||
-- e.ObjectId only: the object is already gone.
|
||||
end)
|
||||
|
||||
World.OnTell.Add(function(e)
|
||||
print(os.date("%H:%M") .. " tell from " .. e.SenderName .. ": " .. e.Message)
|
||||
end)
|
||||
|
||||
World.OnSelected.Add(function(e)
|
||||
if e.Object then
|
||||
print("You selected " .. e.Object.Name .. " (" .. where(e.Object) .. ")")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Stops listening to chat after the first line that contains "stop demo".
|
||||
World.OnChatText.Until(function(e)
|
||||
if e.Message:find("stop demo") then
|
||||
print("OnChatText handler removed.")
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
print("Listening for portals, tells and selections. Press Stop to end.")
|
||||
46
Plugins/RynthCore.Plugin.RynthLua/Examples/xp-tracker.lua
Normal file
46
Plugins/RynthCore.Plugin.RynthLua/Examples/xp-tracker.lua
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
-- xp-tracker.lua: a tracker window (script windows): XP gained, XP per hour, kills and a
|
||||
-- health bar, with a Reset button that has a tooltip.
|
||||
-- Needs RynthCore API v71 (engine) with ImGui on. Start it with /lua start xp-tracker;
|
||||
-- close the window with its X and bring it back from the bar's Scripts button or with
|
||||
-- /lua hud show xp-tracker/XP Tracker.
|
||||
--
|
||||
-- OnRender runs about 20 times a second while the window is shown and records what to
|
||||
-- draw; the engine draws it every frame. ImGui.Button returns true on the pass after the
|
||||
-- click. OnPreRender runs just before OnRender in the same pass: it is where the window's
|
||||
-- first size goes (FirstUseEver: only until the player moves or sizes it).
|
||||
|
||||
local views = require("views")
|
||||
local ImGui = require("imgui")
|
||||
|
||||
if not views.Available then
|
||||
print("Script windows aren't available here (engine older than API v71, or ImGui is off).")
|
||||
end
|
||||
|
||||
local hud = views.Huds.CreateHud("XP Tracker")
|
||||
-- Shown at start. Leave this line out to let the player's last choice (the X, the bar's
|
||||
-- Scripts menu) decide instead.
|
||||
hud.Visible = true
|
||||
|
||||
local startXp, startAt, kills = game.Character.TotalExperience, clock(), 0
|
||||
on("kill", function() kills = kills + 1 end) -- v1 event; v2 has no kill event yet
|
||||
|
||||
hud.OnPreRender.Add(function()
|
||||
ImGui.SetNextWindowSize(Vector2.new(240, 130), ImGuiCond.FirstUseEver)
|
||||
end)
|
||||
|
||||
hud.OnRender.Add(function()
|
||||
local c = game.Character
|
||||
local gained = c.TotalExperience - startXp
|
||||
local hours = math.max((clock() - startAt) / 3600000, 1 / 3600)
|
||||
ImGui.Text("XP gained: " .. math.floor(gained))
|
||||
ImGui.Text("XP / hour: " .. math.floor(gained / hours))
|
||||
ImGui.Text("Kills: " .. kills)
|
||||
ImGui.ProgressBar(c.Health / math.max(c.MaxHealth, 1), Vector2.new(-1, 0),
|
||||
c.Health .. " / " .. c.MaxHealth)
|
||||
if ImGui.Button("Reset") then
|
||||
startXp, startAt, kills = c.TotalExperience, clock(), 0
|
||||
end
|
||||
ImGui.SetItemTooltip("Start counting again from now")
|
||||
end)
|
||||
|
||||
print("XP Tracker open. /lua stop xp-tracker closes it.")
|
||||
Loading…
Reference in a new issue