API reference¶
port/modsdk/obm.lua declares everything on this page for the Lua language server; Editor support sets it up.
Conventions:
- Positions and distances are in world units, which are centimetres; Y is up. Speeds are units per second, accelerations units per second squared.
- Times are in seconds.
- Angles are in degrees, except
obm.draw3d.avatar's yaw, which is in radians. - Refs are integers that name game objects (
ZGEOMrefs).0is no object. - HUD,
draw3d, ghost and projectile colours are integers0xRRGGBB, such as0xc81822. Light colours (obm.lights.set_global,add_point,add_spot) and atmosphere tints are three numbers r, g, b, with 1.0 as full or neutral. Alpha is a number from 0 to 1. - HUD coordinates are pixels from the top-left corner of the game picture;
obm.hud.size()gives its size. - Optional arguments are in brackets, with their defaults.
Core¶
| Function | Description |
|---|---|
obm.log(text) |
Writes [mod:<id>] text to the SDL log |
obm.warn(text) |
The same as a warning |
obm.on(event, fn) |
Registers a listener (see Lifecycle and event order) |
obm.reload() |
Reloads all mods at the start of the next frame |
require(name) |
Loads a module from the mod's package (see The Lua environment) |
obm.scene, obm.gamemode, obm.level¶
| Function | Returns and description |
|---|---|
obm.scene.name() |
The scene's base name, such as "M05_Main", or "" |
obm.scene.is_gameplay() |
true when a scene is loaded and its name contains _main and not hideout |
obm.scene.load(path) |
Starts loading a scene, such as "M05/M05_Main" or "Hideout/Hideout_Main". A path of 260 bytes or more raises an error. |
obm.scene.menu_open() |
true while one of the game's menus is open: the pause menu, the inventory and map screens, briefings |
obm.gamemode.active() |
The active gamemode's id, or nil for the campaign |
obm.level.active() |
The id of the custom level being played, or nil |
obm.level.info() |
{ id, title, base_scene, briefing, mod_id, mission } of that level, or nil; mission is the level's mission file or "" |
obm.level.load_json(path) |
A JSON file from the mods, as a Lua value, or nil |
obm.config, obm.storage¶
| Function | Returns and description |
|---|---|
obm.config.get(key [, default]) |
The setting's current value: boolean, integer, number, or string for choice and string settings. default (or nil) when the mod declares no such setting. |
obm.config.set(key, value) |
true when the value was stored and saved under mods.configs.<id> in obm.config.json. The type must match: a boolean for bool, a number for int and float (clamped), a string for string settings, one of the choices for choice. |
obm.storage.read(key) |
The value stored under key, or nil |
obm.storage.write(key, value) |
true when written to mod_saves/<id>/<key>.json. key: 1 to 63 characters of letters, digits, _, -, ., no ... Raises an error when the value is larger than 1 MB as JSON, holds more than 131,072 values in all (a table that contains itself counts once per path to it), or has a table with more than 1,024 string keys: the limits obm.storage.read can read back. |
obm.config and obm.storage always act for the mod whose environment they belong to, whichever mod's callback is running. Storage converts values to JSON: a table whose keys are 1..n is an array, any other table an object with its string keys (other keys are dropped), to a depth of 32. Functions and other non-JSON values become null. Whole numbers read back as integers.
obm.world¶
| Function | Returns and description |
|---|---|
obm.world.player() |
nil without a player, or { ref, x, y, z, fx, fz, alive, health, health_frac, tension, tension_level, suspicion_level, trespassing, recorded, weapon, firearm, weapon_detectable, weapon_disallowed, ammo_mag, ammo_reserve, ammo_capacity, suit_only, outfit, money, difficulty, room }. fx, fz is the ground direction 47 faces (a unit vector, as the pause map draws him); health_frac (0 to 1) and tension (0 to 100) are the game's health bar and suspicion meter as drawn; tension_level is the highest interest level a watching actor holds (0 to 5) and suspicion_level its name: neutral, interesting, strange, suspicious, threatening or dangerous; trespassing is true in a restricted area (the test the level scripts' Ishitmantrespassing makes); recorded is true while security footage of 47 exists; weapon is the right-hand item's template name or ""; firearm is true when that item fires projectiles; weapon_detectable is true when a search would find it; weapon_disallowed is true when guards who see it in hand take 47 as armed, because his outfit allows no weapons (the fibre wire counts); ammo_mag and ammo_reserve are the rounds in the magazine and carried besides, and ammo_capacity a full magazine (0 without a firearm); outfit is the name of the outfit 47 wears (HitmanTemplate for his suit); suit_only is false once a disguise was used; difficulty is the profile's difficulty level; room is the name of the room 47 is in, or "". |
obm.world.actors() |
Array of actor tables for every actor except 47 |
obm.world.map_icons() |
The pause map's live icons, as the map shows them on the current difficulty (47 and the map legend's sample icons left out): an array of { kind, role, ref, x, y, z, fx, fz, current }. kind is person, dead, target, point_of_interest or exit. obm.world.map_icons({ navigation = true }) adds the map's navigation symbols: stairs, stairs_up, stairs_down, ladder, elevator, sewer, power_switch, vehicle, helicopter, pickup, guard_quarters and ica (the agency's places); role, for people and bodies, guard, police, civilian, vip, target or optional_target ("" otherwise); ref is the icon's object, or the person carrying an item the map marks; fx, fz the ground direction that object faces; current is true for the icons on the map (floor) 47 is on, the only ones the pause map shows with it. |
obm.world.map_labels() |
The pause map's room and area names, as the map shows them in the current language: an array of { text, x, y, z, current } in world coordinates; current is true for the labels of the map 47 is on (his floor) |
obm.world.actor(ref) |
The actor table, or nil. Fields: ref, name, x, y, z, alive, dead, sedated, health, role, species, room, outfit, weapon, weapon_class. role is target, optional_target, guard, police, vip, civilian or other; species is human, dog, rat, corpse, wheelchair or other; room is the current room's name or ""; outfit is the outfit they wear ("" for ordinary clothes 47 cannot take); weapon and weapon_class are their gun's template and class, or "". |
obm.world.set_actor_role(ref, role) |
true on success. Roles as above (enemy means guard); the map icon and the level's target table are updated. |
obm.world.set_actor_hp(ref, hp) |
true on success; sets the actor's hitpoints |
obm.world.items() |
Array of { ref, name, template, type, class, x, y, z, is_weapon, owned, state } for every item outside containers; type is the game's item type number and class its item class |
obm.world.item_templates() |
Array of { ref, name, type, class, is_weapon } for every item template the scene loads: its level items and its weapons, equipment and ammunition groups |
obm.world.spawn_item(template, x, y, z [, yaw=0]) |
The new item's ref, or nil when the scene has no such template. The item lies at (x, y, z) turned yaw degrees, as if placed in the level. |
obm.world.outfits() |
Array of { ref, name, group, quality, suit } for every outfit the scene defines, 47's suit included (suit true). group is the disguise group (guards of one group recognise each other); quality is the dress quality, 4 for 47's suit. |
obm.world.set_actor_weapon(ref, template) |
true when the person now carries a gun of that template; works before and after they have drawn one |
obm.world.swap_items(ref_a, ref_b) |
true when both are items no one carries; swaps their positions |
obm.world.ref(name_or_path) |
The ref of the object with exactly that name (case-insensitive, the first one found), or, for a name with a \, of the object at that scene path ("ROOT\Level\Exit", as the scene's properties name objects); nil when there is none |
obm.world.find_geom(pattern) |
The ref of the first object whose name contains pattern (case-insensitive), 0 if that object has no game object, or nil |
obm.world.light_links(ref) |
Current scene lighting links as an array of { ref, name }. A mesh lists its lights and a light lists the geometry it affects. An unknown ref returns nil. |
obm.world.nearby_geoms([max_dist=1500]) |
Up to 64 { name, dist, x, y, z } for named objects with a mesh within max_dist of 47 |
obm.world.interactables([max_dist=1000]) |
The objects with an action 47 could use, wherever he stands, within max_dist of him: an array of { ref, x, y, z, dist, pickup }. Doors, switches, elevator panels, the places to put a bomb or an item, items to pick up (pickup true) and the like; people, 47 and items someone carries are left out. x, y, z is the object's centre. |
obm.world.traversal_guides() |
The active climbable windows and drainpipes: an array of { kind, x, y, z, corners, models }, kind "window" or "drainpipe", x, y, z the centre, corners the four world-space corners of the face 47 climbs, and models the refs of the drainpipe's or window's own meshes (pipe; frame, glass and shutters), for obm.fx.highlight_overlay; empty where the level draws the window as part of a wall. A window's face and models are its opening, above the guide's box (which is the wall under the sill). |
obm.world.get_pos(ref) |
x, y, z, or nothing for an unknown ref |
obm.world.set_pos(ref, x, y, z) |
true when the object exists; moves it. A NaN or infinite coordinate raises an error. Actors and 47 are moved with their path-following state, as the game's own teleports do, so they stay where they are put. |
obm.world.explode(x, y, z [, radius=450, damage=120, force=35]) |
Number of actors hit. Damage falls off to 0 at radius; an actor whose hitpoints it exceeds dies and is thrown with force. Shakes the camera. |
obm.world.distract(x, y, z [, radius=800]) |
Number of living actors within radius sent the Investigate message |
obm.world.raycast(x1, y1, z1, x2, y2, z2) |
nil, or { hit = true, x, y, z, nx, ny, nz, dist, ref, name, is_actor } for the nearest hit against sight collision, actors (a 42-unit capsule around each) and props (name is "prop:<id>", ref is 0) |
obm.world.doors() |
All doors with their reference, name, position, lock state, open state and signed swing fraction (openness). |
obm.world.door(ref) |
Current state of one door. Returns nil for other objects. |
obm.world.set_door(ref, action[, operator]) |
true on success. "open" unlocks and opens, "close", "lock" closes and locks, "unlock". On open, the optional operator supplies the side of approach. It defaults to the player. |
obm.world.cameras() |
Array of { ref, name, x, y, z, online, range } for security cameras |
obm.world.set_camera_disabled(ref, disabled) |
true on success; switches the camera off or on |
obm.world.trigger_alarm(on) |
Number of objects named *alarm* or *siren* sent FireAlarmOn or FireAlarmOff |
Item classes¶
class sorts items by what they do: fiber_wire, poison (poison syringes and poisons), sedative (sedative syringes, chloroform, ether, the stun gun and tranquiliser rifle), explosive (remote mines, exploding flasks), detonator, pistol, smg, shotgun, rifle, sniper, melee (knives, hammers, bats and the other close-combat weapons), lockpick, key (keys and keycards), ammo, equipment (vests, binoculars, painkillers, adrenaline), coin, food, container, mission (a level's own story items), other and none.
obm.player¶
| Function | Returns and description |
|---|---|
obm.player.get() |
The same as obm.world.player() |
obm.player.get_health() |
47's hitpoints, or 0 without a player |
obm.player.set_health(hp) |
true on success |
obm.player.heal([amount=100]) |
true on success; heals like the game's medkits |
obm.player.give_money(delta) |
The new balance (0 without a profile); delta may be negative |
obm.player.give_item(template) |
true when the request was queued. The item is added a moment later if the scene loads an item template with that exact name (case-insensitive), such as "Custom_Pistol", "Equip_LockPick_01" or "CC_Syringe_Poison_01" (obm.world.item_templates() lists them); otherwise nothing happens (the F10 or Shift+F1 debug overlay shows why). |
obm.player.inventory() |
Array of { ref, name, template, type, class } for the items 47 carries |
obm.player.remove_item(ref) |
true when 47 carried the item; it leaves his inventory |
obm.player.outfit() |
{ ref, name, group, quality, suit } of the outfit 47 wears (as obm.world.outfits()), or nil |
obm.player.get_forward() |
fx, fy, fz, 47's facing as a unit vector, or nil |
obm.player.set_disguise(ref_or_name) |
true when 47 now wears the outfit: an outfit's ref or name (obm.world.outfits()), or a person's ref for the outfit they wear. The change is instant, without the animation, and counts for the guards as any change of clothes does. |
obm.player.give_default_weapons() |
Gives 47 the mission's default weapons; true when there is a player |
obm.player.aim_target() |
The ref of the living person under the crosshair while 47 aims, or nil |
obm.player.weapon_state() |
nil unless 47's right hand holds a firearm, else { magazine, capacity, spare, reloading, auto_reload }: the rounds in its magazine and a full magazine, spare true when he carries rounds for it (or ammunition is infinite), reloading true while he reloads, and auto_reload false when the Reprisal weapons mod's Manual reload only keeps an empty magazine from reloading by itself |
obm.player.ammo_warning() |
Reprisal's ammunition warning for the weapon in 47's right hand, "RELOADING", "RELOAD", "NO AMMO" or "LOW AMMO", and whether it pulses; nil when there is none |
obm.player.last_stand() |
nil unless the Reprisal weapons mod's Scaled last stand is running, else { elapsed, duration, needed, kills, skip_shown, skip_key }: seconds of game time since it began and in all, the head shots that end it and those made, whether the skip prompt shows (716 ms after the start) and its key ("START" or "ESC") |
obm.mission, obm.rating, obm.difficulty¶
| Function | Returns and description |
|---|---|
obm.mission.set_custom_rules(on) |
While on, the stock mission completion and failure are suppressed (the level's scripts and the engine can no longer end the mission), so the mod must end it with complete or fail. Reset to off at every scene unload; call it in scene_loaded. |
obm.mission.complete() |
Completes the mission, even with custom rules on |
obm.mission.complete_all() |
Completes every open objective and then the mission, as the PC version's cheat does; true in a mission |
obm.mission.fail([reason="Mission Failed"]) |
Fails the mission, even with custom rules on. reason is a locale key or the text itself; only its first 199 bytes are used. |
obm.mission.level_time() |
Seconds since scene_loaded, the sum of the frame dt values |
obm.mission.set_objective_text(index, text) |
Changes an objective's text (a locale key or the text itself); only its first 127 bytes are used |
obm.mission.complete_objective(index [, tick=true]) |
Marks an objective complete |
obm.mission.show_info(text [, exclusive=false]) |
Shows an info line on the OSD |
obm.mission.show_warning(text [, exclusive=false]) |
Shows a warning line on the OSD |
obm.mission.define(def) |
The mission library: a mission from a table of targets, exits, objectives and events. Returns the mission. Mission scripting describes it. |
obm.mission.actor(name), obm.mission.object(name) |
The ref of an actor by the name obm.world.actors() gives it, or of an object by name or scene path; nil when not found |
obm.mission.dir() |
The folder of the running level's mission file, such as "levels/contract", or "" |
obm.mission.play(sound), obm.mission.say(text [, kind="info", seconds]) |
Plays a WAV (relative to the level mission's folder, then the mod; { file, at = object, pos, range, volume, loop }) or a scene sound ({ scene = index, at = object }); shows text as "info", "warning" or "subtitle" |
obm.rating.live() |
nil outside a mission, or { rating, silent_assassin, suit_lost, targets_killed, enemies_killed, innocents_killed, police_killed, accident_kills, fiberwire_kills, witnesses, bodies_found, target_bodies_found, sedated_bodies_found, caught_on_tape, cover_blown, alarms, disguises_used, shots_fired, notoriety, reasons }. rating is the current rating's name or "N/A"; reasons is an array of { name, count } for what is costing the rating. |
obm.rating.display() |
show, details: the settings of the built-in rating mod (openblood.rating), for a mod that hides that band (obm.hud.set_vanilla_visible("rating", false)) and draws the rating itself |
obm.difficulty.get() |
nil without a profile, or the difficulty settings in effect: level and hitman_hp, guard_hp, civilian_hp, target_hp, accuracy_modifier, rof_multiplier, aim_speed, relaxed_vision_range, alert_vision_range, relaxed_fov, alert_fov, shot_hearing_range, scream_hearing_range, footsteps_behind_range, run_suspicious_range, see_through_disguise_distance, see_through_disguise_speed, stand_down_time, lockpick_time_multiplier, money_multiplier, headshots_against_hitman. Values are in the units of the game's DifficultySettings.xml. |
obm.difficulty.set(patch) |
Overrides the fields present in patch (same names, except level) |
obm.difficulty.reset() |
Removes all overrides |
The difficulty overrides are one set shared by all mods and kept across scenes: reset also removes other mods' overrides.
obm.weapons¶
| Function | Returns and description |
|---|---|
obm.weapons.list() |
Array of { ref, name, damage, impact, spread, shot_time, range } for the weapon templates in the scene |
obm.weapons.set_stats(ref_or_name, patch) |
true when a template was found and patched. ref_or_name is a template ref, a weapon item ref, or part of a template name. patch fields: damage (damage multiplier), impact, spread (precision in degrees), shot_time (seconds between shots), near_range, range (far range), velocity (muzzle velocity). |
obm.ai, obm.dialogue¶
| Function | Returns and description |
|---|---|
obm.ai.teleport(ref, x, y, z) |
true when the object exists; the same as obm.world.set_pos |
obm.ai.set_patrol(ref, points [, speed=140]) |
true when the patrol was set. points is an array of 2 to 12 { x, y, z [, wait=1.5] }. The runtime moves the actor straight between points at speed, waits wait seconds at each and loops; there is no path finding. The patrol ends when the actor dies. |
obm.ai.clear_patrol(ref) |
Removes the actor's patrol |
obm.ai.set_enforcer(ref, on) |
Marks an actor as an enforcer: a dot above its head, white, amber above 0.15 suspicion and red above 0.65. Suspicion rises by 0.42 per second while 47 is within 850 units in front of it and falls by 0.25 per second otherwise. It is the port's meter only; the actor's own AI is unchanged. |
obm.ai.is_enforcer(ref) |
Boolean |
obm.ai.make_ally(ref, on) |
Marks an actor as an ally: an ICA ALLY label, and the runtime moves it after 47 (up to 195 units per second) while it is between 165 and 2,400 units away. Clears the enforcer mark. |
obm.ai.is_ally(ref) |
Boolean |
obm.ai.set_suspicion(ref, value) |
Sets the enforcer meter, clamped to 0..1 |
obm.ai.get_suspicion(ref) |
The meter, 0 for an untagged actor |
obm.ai.get_forward(ref) |
fx, fy, fz, the object's facing, or nil |
obm.dialogue.say(speaker, text [, wav_path="", duration=4.5]) |
Shows SPEAKER: text as a subtitle bar for duration seconds (3 when below 0.2) and plays wav_path if given |
Tags and patrols end when the actor dies or the scene unloads.
obm.time, obm.physics, obm.camera¶
| Function | Returns and description |
|---|---|
obm.time.set_scale(scale [, follow_pitch=true]) |
Sets this mod's game time scale, clamped to 0.02..4. Each mod has its own; the game runs at their product (at most 10). Below 0.98, and until obm.audio.set_pitch is called, the audio pitch follows the product of the scales set with follow_pitch (0.48 + 0.52 × scale, at least 0.45); pass false for a slowdown that should not deepen the sound. set_scale(1) takes this mod's scale back. |
obm.time.set_scale_cap([scale=1]) |
Sets a ceiling on the game time scale, clamped to 0.02..1: the game runs at the lower of it and the product of the scales, so a slow-motion mod slower still is not slowed further. The audio pitch does not follow it. set_scale_cap(1) takes it back; it also ends at scene unload. |
obm.time.get_scale() |
The scale in effect, every mod's together |
obm.time.pause(on) |
Pauses the game and its sound without the pause menu, or releases this pause (the game stays paused if it already was). Released at scene unload. |
obm.time.is_paused() |
true while the game is paused, by a mod or by the game |
obm.time.real_dt() |
Seconds since the last frame in real time, at most 0.25: unlike dt, it runs while the game is paused or slowed |
obm.time.now() |
Seconds since the port started, in real time |
obm.physics.ragdoll(ref [, fx=0, fy=1, fz=0, force=25]) |
true for an actor. Kills it, credited to 47, and throws it along (fx, fy, fz). |
obm.camera.set_fov(scale) |
Scales the field of view, clamped to 0.5..1.75 |
obm.camera.shake(intensity [, duration=0.35]) |
Shakes the camera |
obm.camera.get_pose() |
nil before the first frame is drawn, or { x, y, z, fx, fy, fz, rx, ry, rz }: the camera position, its forward unit vector and the picture's right as a unit vector, from the projection the last frame was drawn with |
obm.camera.set_override(px, py, pz, tx, ty, tz [, fov_scale=1.0, opts]) |
Puts the camera at (px, py, pz) looking at (tx, ty, tz) until cleared. opts.horizontal_fov sets the horizontal field of view in degrees (5–150). With opts.move_camera, the game's own camera moves there too, so the rooms drawn and the visibility follow it: a free camera that can leave 47's room, as photo mode does. Without it, the picture is drawn from there with what 47's camera sees. |
obm.camera.clear_override() |
Gives the camera back to the game |
obm.lights, obm.fx, obm.atmosphere, obm.shader¶
| Function | Returns and description |
|---|---|
obm.lights.set_global(r, g, b) |
Multiplies the world lighting by (r, g, b); 1, 1, 1 is unchanged |
obm.lights.set_blackout(on) |
Multiplies the world lighting by (0.16, 0.19, 0.28) |
obm.lights.set_flashlight(on [, intensity=0.85]) |
A glow at the centre of the screen, drawn only during a blackout |
obm.lights.add_point(id, x, y, z [, r=1.0, g=0.92, b=0.75, radius=650, intensity=2.2, surface=false]) |
true when placed or updated. Lights world geometry within radius (at least 20). Pass surface=true for per-pixel lighting of static strips without a source marker. |
obm.lights.add_spot(id, x, y, z, dx, dy, dz [, r=1.0, g=0.95, b=0.85, radius=1100, angle=32, intensity=3.0, surface=false]) |
true when placed or updated. A cone along (dx, dy, dz); angle is the half-angle in degrees, clamped to 5..85; radius at least 40. Pass surface=true for per-pixel lighting of static strips without a source marker. |
obm.lights.remove(id) |
Removes a dynamic light |
obm.lights.clear() |
Removes all dynamic lights |
obm.lights.reset() |
Ends the tint, blackout and flashlight; dynamic lights stay |
obm.fx.highlight(ref, rgb [, opts]) |
Outlines and tints a character this frame; call it from frame every frame. opts: through_walls (draw the outline over geometry), outline_only (no tint), fill (tint the visible parts with the colour over their own shading, inside a solid outline). true when the object has a model. |
obm.fx.set_highlight_style(opts) |
For this frame: dim (0..1, darkens everything that is not highlighted), vignette (0..1), pulse (0..1, the outline's brightness), occluder (a ref, usually 47, whose model hides the outlines behind it), saturation (0..1, the colour left in the scene; the highlights, drawn after it, keep theirs), fill (0..1, default 1, how strongly fill highlights show, tint and outline: fade them with it rather than with a darker colour) |
obm.fx.highlight_overlay(ref, fill, outline [, subobjects]) |
Highlights a character or object this frame as Reprisal does; call it from frame every frame. fill and outline are { r, g, b, a } from 0 to 1 (alpha 1 when left out): the fill is blended over the parts 47's camera sees, and the outline over the shape's edge, 2 pixels wide at 1080 lines. Nothing shows through walls. subobjects, an array of numbers from 0 to 31, keeps only those meshes of the object itself (the n-th prim of its mesh, as Reprisal's overrides file numbers them) and none of the objects below it. Up to 8 different colour pairs a frame. true when the highlight was added. |
obm.fx.set_weather(kind [, intensity=1.0]) |
"rain", "snow" or "ash" draws screen-space particles; anything else, such as "none", stops them. intensity is clamped to 0..2; 0.1 to 1 sets the particle count. |
obm.atmosphere.set(opts) |
Colour grade. opts fields, each optional and kept from the last call: r, g, b (tint, default 1), brightness (offset, default 0), contrast (default 1), saturation (default 1), bloom (extra bloom, default 0), noise (film grain, default 0) |
obm.atmosphere.reset() |
Ends the grade |
obm.shader.set_preset(name [, params]) |
A built-in post-process shader: "thermal", "nightvision" (or "nvg"), "sincity", "crt", "sonar", "comic"; any other name ends the shader. params is an array of up to 4 numbers. |
obm.shader.load_custom(spv_path, msl_path [, params]) |
A fragment shader from the mods: the SPIR-V file on Vulkan, the MSL file on Metal (entry point PSMain). It samples the frame, depth and a noise texture; params reach it as a 4-component uniform. Other GPU back ends do not load custom shaders. |
obm.shader.clear() |
Ends the preset or custom shader |
obm.audio¶
| Function | Returns and description |
|---|---|
obm.audio.play(wav_path [, volume=0.85, loop=false, emitter]) |
true when the file was found and started |
obm.audio.play_3d(wav_path, x, y, z [, range=1200, volume=1.0, loop=false, emitter]) |
true when started. Panned and attenuated against the listener; silent beyond range. |
obm.audio.emitter_gain(emitter, volume [, fade_seconds=0]) |
Changes the named voice’s gain over the specified time. Returns true while the voice exists. Passing an emitter name (up to 63 bytes) to either play call replaces that voice. Named voices end when the scene unloads. |
obm.audio.stop_emitter(emitter [, fade_seconds=0]) |
Stops one named voice, optionally fading it out first. Returns true if the voice existed. |
obm.audio.set_pitch([scale=1]) |
Pitch of game and mod audio, clamped to 0.25..2.5. Stops the pitch from following the time scale. |
obm.audio.set_music_layer(name [, wav_path="", volume=1.0, fade=1.5]) |
true on success. Starts a looping layer, or with wav_path "" fades an existing layer to volume over fade seconds. |
obm.audio.stop_all() |
Stops all mod voices and layers and resets the pitch |
obm.audio.duck_music([music=1, emitters=music]) |
Scales the volume of the level's music by music and of the music its emitters play (a club's or a radio's) by emitters, 0..1, on top of the game's own fades. It lasts until called again, but music that starts later plays at full volume: call it every frame while it is lowered, and once with 1 to end it. true when the level has music. |
obm.audio.set_high_gain(gain) |
Lowers the highs of the game's sounds (not mod sounds) above about 5 kHz to gain, 0..1, easing there over 0.05 s, as an OpenAL low-pass filter's high-frequency gain; 1 ends it. It lasts until called again. |
obm.instinct, obm.gaze¶
Reprisal's Instinct tracker and gaze interaction, for the built-in instinct and interaction mods (Instinct, Highlights and Gaze).
| Function | Returns and description |
|---|---|
obm.instinct.objects([range=1000]) |
The objects Reprisal's Instinct shows now, nearest first: an array of { ref, category, dist, subobjects }, category "object" or "climbable", subobjects the meshes of the object to highlight when the overrides file names some (nil for the whole object; pass it to obm.fx.highlight_overlay). These are the geoms with an action, security cameras, explosion controllers and bomb places, corrected by Reprisal's InstinctObjectOverrides.json, within range of 47 measured between the origins. Characters are not included. |
obm.instinct.state() |
What refuses Instinct, or nil without 47: { cut_sequence, camera, map, pickup, injecting, touch, input }. camera is a camera mode other than third or first person; injecting the syringe used on an item; input whether 47's input control takes input. |
obm.instinct.sound(on) |
Stops the OSD sound and plays Reprisal's Instinct sound for turning on (OSD sound 16) or off (17) |
obm.instinct.duck_emitters(entries [, music=1, emitters=music]) |
After obm.audio.duck_music(music, emitters), scales the level's sound objects named in entries, an array of { name, volume = v [, all = true] }, by v on top: the first object of each name, or with all every one. v 1 restores them. |
obm.gaze.target() |
With the interaction mod's gaze option on, the object the camera gazes at, the geom its highlight goes on (nil for 47's own items) and that geom's meshes to highlight when the overrides file names some (nil for all), or nil |
obm.gaze.pickup() |
The pickup menu's selected object (its first entry while closed) and whether the menu is open, or nil |
obm.models, obm.props, obm.draw3d, obm.projectiles¶
| Function | Returns and description |
|---|---|
obm.models.replace(ref_or_pattern, glb_path) |
Number of meshes now drawn with the .glb: those of the object ref, or of every object whose name contains pattern |
obm.models.clear() |
Ends all replacements |
obm.models.stats() |
{ registered, overridden } |
obm.props.spawn(id, glb_path, x, y, z [, rx=0, ry=0, rz=0, scale=1, solid=true]) |
true when placed (or updated, for an existing id). Rotations in degrees. |
obm.props.set_transform(id, x, y, z [, rx=0, ry=0, rz=0, scale=1, solid=true]) |
true for an existing prop. Omitted values take the defaults, not the prop's old ones. |
obm.props.remove(id) |
true when removed |
obm.props.list() |
Array of { id, glb, x, y, z, rx, ry, rz, scale, solid } for every prop in the scene: all mods' props, and projectiles drawn with a model |
obm.draw3d.line(x1, y1, z1, x2, y2, z2 [, rgb=0xff3030, alpha=1.0, xray=false]) |
Draws a line this frame. With xray, it is drawn over geometry. |
obm.draw3d.box(cx, cy, cz, hx, hy, hz [, rgb=0x38d0ff, alpha=0.75, xray=false]) |
A box with half-extents hx, hy, hz |
obm.draw3d.sphere(cx, cy, cz, radius [, rgb=0xffaa20, alpha=0.85, xray=false]) |
A sphere |
obm.draw3d.cone(x, y, z, dx, dy, dz, length [, half_angle=35, rgb=0x38e070, alpha=0.55, xray=false]) |
A flat fan on the ground plane along the horizontal part of (dx, dy, dz), like a vision cone |
obm.draw3d.circle(cx, cy, cz, radius [, rgb=0x38d0ff, alpha=0.9, xray=false]) |
A horizontal ring |
obm.draw3d.avatar(x, y, z [, yaw=0, stride=0, suit_rgb=0x1c1e24, tie_rgb=0xc81822, gun=false]) |
A simple 175-unit figure; yaw in radians, stride is the walk phase |
obm.projectiles.spawn(opts) |
true when spawned. opts: id ("proj"), glb (model, else a sphere), x, y, z, vx, vy, vz (0), gravity (-680), bounce (0.35, clamped to 0..0.95), radius (14), life (5 s), color (0xffaa20), on_hit. On each hit on_hit({ id, x, y, z, ref, name, is_actor }) runs; the projectile bounces off geometry and ends on an actor or when bounce is near 0. |
obm.projectiles.clear() |
Removes all projectiles |
draw3d shapes last one frame; draw them from frame.
obm.actions, obm.input¶
| Function | Returns and description |
|---|---|
obm.actions.register(id, opts, fn) |
true when registered; the same id replaces an earlier action. opts: label (default id), x, y, z, or geom_ref to follow an object, radius (220), key ("E"). The nearest action in range shows [KEY] LABEL, and pressing the key calls fn(id). The game also sees the key: E is the game's own action key. |
obm.actions.unregister(id) |
Removes the action |
obm.actions.clear() |
Removes all actions |
obm.input.is_down(key) |
true while the key is held |
obm.input.just_pressed(key) |
true during the frame the key went down |
obm.input.binding_down(id [, mod_id]) |
true while any key or the button of the binding is held. Without mod_id, the calling mod's binding; another mod's id reads that mod's. Bindings of inactive mods are never down. |
obm.input.binding_pressed(id [, mod_id]), binding_released(id [, mod_id]) |
true during the frame the binding went down or came up |
obm.input.binding_info(id [, mod_id]) |
{ id, label, keys, pad } with the player's current keys (an array of key names) and button name, or nil; use it to name the key in a hint |
obm.input.mouse_delta() |
dx, dy: the mouse movement this frame, 0 while the debug overlay or the mod UI takes the mouse |
obm.input.pad_connected() |
true when a gamepad is connected |
obm.input.pad_axis(name) |
An SDL gamepad axis ("leftx", "lefty", "rightx", "righty", "lefttrigger", "righttrigger"), -1..1 for the sticks with the launcher's dead zone applied, 0..1 for the triggers; 0 without a gamepad |
obm.input.pad_down(button), pad_pressed(button) |
An SDL gamepad button ("a", "leftshoulder", "touchpad"): held, or went down this frame |
obm.input.fast_descend_prompt() |
While the modern controller layout drives 47 from the pad, or the Reprisal touch layout drives him, on a ladder, drainpipe or climbing wall, where holding the right stick or the crouch button drops him (Reprisal's JUMP DOWN prompt), the label of that button ("RS", "R3", or "crouch" on touch); else nil |
obm.input.pointer_down() |
true while the left mouse button is held, or a finger is on a touch screen (SDL presses the mouse for it) |
obm.input.set_look_scale(scale) |
Scales 47's look and aim speed from the mouse and right stick, 0..4; each mod has its own and they multiply. Reset at scene unload. |
Prefer a binding to a fixed key: the player can then move it off a key they use for something else.
Key names are SDL scancode names: "F7", "H", "9", "Space", "Left Shift", "Home", "[", "Keypad 1". They name physical positions (US layout), whatever the keyboard layout. An unknown name is never down. Input is read whether or not the game or a Dear ImGui window also uses the key. See Hotkey map for keys to avoid.
obm.hud¶
The drawing functions draw only inside hud_draw; elsewhere they do nothing.
| Function | Returns and description |
|---|---|
obm.hud.size() |
{ w, h, scale } of the game picture, with pixel, one screen pixel in HUD units (0.5 on a 2x display), dp, one Android density-independent pixel in HUD units (the display's scale over its pixel density), and touch and left_handed |
obm.hud.rect(x, y, w, h, rgb [, alpha=1]) |
Filled rectangle |
obm.hud.rect_outline(x, y, w, h, rgb [, alpha=1, thickness=1.5]) |
Rectangle outline |
obm.hud.band(x, y, w, h [, alpha=1]) |
The game's dark band with red rules |
obm.hud.text(x, y, size, rgb, alpha, text [, font=true, shadow=true]) |
Text, size in pixels, with a one-pixel black shadow unless shadow is false. font is true or "condensed" for the condensed HUD font (Barlow Condensed SemiBold), false or "body" for the body font (Barlow Medium), or "heavy" for Reprisal's lettering (Barlow Condensed Bold at nine tenths of its width) |
obm.hud.text_size(size, text [, font=true]) |
w, h of the text in pixels, font as for text (works anywhere) |
obm.hud.line(x1, y1, x2, y2, rgb [, alpha=1, thickness=1.5]) |
Line |
obm.hud.circle(cx, cy, radius, rgb [, alpha=1, filled=true, thickness=1.5, segments=0]) |
Circle; segments 0 lets the renderer choose from the radius |
obm.hud.arc(cx, cy, radius, from, to, rgb [, alpha=1, thickness=1.5, segments=32]) |
Stroked arc; angles in degrees, 0 to the right, growing clockwise |
obm.hud.polygon(points, rgb [, alpha=1, filled=true, thickness=1.5]) |
points is { x1, y1, x2, y2, ... }, 3 to 64 points. Filled takes any simple polygon, convex or not, in either winding; an outline is closed and stroked inside the shape |
obm.hud.gradient_rect(x, y, w, h, rgb, left_alpha, right_alpha) |
Rectangle whose opacity runs from left to right |
obm.hud.radial_gradient(cx, cy, inner, outer, rgb, inner_alpha, outer_alpha [, segments=64]) |
Ring between two radii whose opacity runs from the inner edge to the outer one; inner 0 fills the disc. Use it for glows and vignettes |
obm.hud.push_clip(x, y, w, h), obm.hud.pop_clip() |
Later drawing shows only inside the rectangle, and inside any clip already pushed, until pop_clip. The edges snap to the nearest screen pixel, so clips that meet leave no gap. Clips still pushed when hud_draw returns are removed |
obm.hud.icon(name, x, y, size [, options]) |
One of the port's HUD icons centred on x, y, size its half-size: point_of_interest, exit, target, person, hitman, alert, trespass or health. options: alpha, color (person and the glyphs alert, trespass, health), angle (person and hitman, degrees clockwise from up), hollow (person) |
obm.hud.progress_bar(x, y, w, h, frac [, fg=0xc81822, bg=0x18181b, alpha=0.9]) |
Bar filled to frac (0..1) |
obm.hud.item_silhouette(x, y, w, h [, template, alpha=1]) |
A white side view of the held item's own 3D model, centred on x, y and fitted to the box: its longest side across, a weapon with the muzzle right and the grip down, anything else showing the side that fills the box best, with its handle or thicker end left and a blade's back up. With template, that item's, once 47 has held it. true, width, height when drawn, the size of the picture drawn |
obm.hud.load_image(png_path) |
{ id, w, h } or nil (also for a PNG larger than 4096 x 4096, and past 32 images); loading the same path again returns the same image (works anywhere) |
obm.hud.image(id, x, y, w, h [, alpha=1]) |
Draws a loaded image |
obm.hud.icon_target(x, y, size [, alpha=1]) |
The game's target icon |
obm.hud.world_to_screen(x, y, z) |
sx, sy, true for a point on screen, nil, nil, false otherwise (works anywhere) |
obm.hud.logical_to_screen(x, y) |
sx, sy: a point of the game's 512 x 448 logical screen, the coordinates of the PS2 HUD, in HUD pixels; use it to line drawings up with the game's own HUD. In widescreen the logical screen runs past 0 and 512 (works anywhere) |
obm.hud.edge_shift() |
How far, in logical pixels, the game's corner HUD elements move out with the launcher's widescreen HUD anchoring; 0 when it is off (works anywhere) |
obm.hud.game_hud_shown() |
true while the game draws its own HUD: not in menus, the pause map, cutscenes or the pause, and with 47 in the scene. HUD additions that belong to play should draw only then (works anywhere) |
obm.hud.suspicion_meter() |
The game's suspicion bar, 0 to 100, as its health and suspicion display fills it: it jumps up with the tension (obm.world.player().tension) and falls back half a point each game frame; 0 without the overlay (works anywhere) |
obm.hud.crosshair_shown() |
true while the game shows its crosshair (works anywhere) |
obm.hud.weapon_display() |
enabled, shown: whether the game draws its weapon display, and whether that shows an item now (works anywhere) |
obm.hud.view_reticle() |
true when Reprisal's VIEW RETICLE would show: no weapon crosshair, the crosshair option on and not forced off, and 47 alive and not reloading (works anywhere) |
obm.hud.osd_sound(id) |
Stops the HUD's sound and plays sound id (0 to 21) of the game's OSD sound set, as the game's HUD does |
obm.hud.preview() |
true when the port runs with OPENBLOOD_HUD_PREVIEW=1 for test captures, when HUD mods should show their warnings whatever the game state (works anywhere) |
obm.hud.set_vanilla_visible(element, visible) |
Hides or shows a stock HUD element: health (the health and suspicion display), weapon, compass, crosshair, info, actions, rating (the band of the built-in rating mod) or all (works anywhere) |
obm.hud.actions([all_drops]) |
The game's interaction prompts now, read without changing them: the action list (its first entry, every entry while it is held open, or with the modern pad layout one entry per button), the pickup list, the open container list, and the drop prompt while 47 drags a body or holds a human shield (all_drops adds the held item's). Each { text, kind, action, selected, open, more, key, pad, button, hold, x, y, z, person }: kind is action, pickup, drop or container; action names what it does (door, strangle, drag_body, change_clothes, place, retrieve, exit_keyhole, ...); key is the key with keyboard and mouse prompts, pad the PS2 button and button the controller's own label (nil for a PlayStation symbol); hold is true when the modern pad layout performs it on a held button; x, y, z place the person or item the prompt is about. Hide the game's own prompts with set_vanilla_visible("actions", false) |
obm.hud.vanilla_visible(element) |
false when a mod has hidden the element (works anywhere) |
obm.hud.set_osd_visible(on), obm.hud.osd_visible() |
The game's whole on-screen display, as the cheat menu's Show OSD switches it (works anywhere) |
obm.ui¶
Dear ImGui windows. The widgets work only inside ui_draw and in debug overlay tabs; ui_draw fires only while the mod UI is visible. While it is visible, the mouse cursor is free and Dear ImGui takes keyboard and mouse input.
| Function | Returns and description |
|---|---|
obm.ui.set_visible(on) |
Shows or hides the mod UI (one switch for all mods) |
obm.ui.is_visible() |
Boolean |
obm.ui.begin_window(title [, x=32, y=32, w=380, h=420]) |
true when the window is open and not collapsed. Position and size apply the first time the window appears. A window left open is closed at the end of the callback. Returns false outside ui_draw. |
obm.ui.end_window() |
Ends the window, and the disabled blocks begun inside it; a call when the innermost open window or popup is not a window is ignored. Call it whatever begin_window returned. |
obm.ui.text(text) |
A line of text |
obm.ui.separator() |
A horizontal line |
obm.ui.text_disabled(text), obm.ui.text_wrapped(text) |
A greyed line; text wrapped to the window |
obm.ui.same_line([offset=0, spacing=-1]) |
Puts the next widget on the same line, at offset pixels from the window's left edge when not 0 |
obm.ui.button(label), obm.ui.small_button(label) |
true the frame it is clicked |
obm.ui.checkbox(label, value) |
new_value, changed |
obm.ui.slider_float(label, value, min, max [, format="%.3f"]) |
new_value, changed. format holds one float conversion (%[flags][width][.precision] and f, e or g) with any text around it and %% for a percent sign; any other format is replaced by "%.3f". |
obm.ui.slider_int(label, value, min, max) |
new_value, changed |
obm.ui.combo(label, index, items) |
new_index, changed; items is an array of strings (other values show as empty items) and index is 1-based |
obm.ui.set_next_item_width(pixels) |
Width of the next widget |
obm.ui.collapsing_header(label [, open=false]) |
true while the section is expanded; open is its first state |
obm.ui.open_popup(id), begin_popup(id), end_popup(), close_popup() |
A popup: open it from a button, then draw it between begin_popup (when it returns true) and end_popup; close_popup closes it from inside. A popup left open is ended at the end of the callback. |
obm.ui.begin_disabled([disabled=true]), end_disabled() |
Greys out and blocks the widgets in between. An end_disabled that does not close the innermost thing begun is ignored. Windows, popups and disabled blocks open at once are limited to 32 together; one more raises an error. |
obm.ui.input_text(label, text [, max_length=63]) |
new_text, changed: a text field |
obm.ui.copy_to_clipboard(text) |
true when the text is on the system clipboard (works anywhere) |
Dear ImGui identifies widgets by label, so two widgets with the same label in one window need a ## suffix: "Delete##3".
obm.debug¶
Tabs in the F10 or Shift+F1 debug overlay. The overlay works with the debug UI setting on; a tab's widgets are the obm.ui ones above, and work inside the tab's function whether or not the mod UI is visible.
| Function | Returns and description |
|---|---|
obm.debug.add_tab(title, fn) |
Adds a tab, before the Mods tab, whose contents fn() draws each frame it is shown. The same title from the same mod replaces the function. At most 16 tabs. |
obm.debug.open([title]) |
Opens the overlay, on the mod tab named title if given |
obm.debug.close(), obm.debug.is_open() |
Closes the overlay; whether it is open |
obm.cheats, obm.save, obm.movies¶
| Function | Returns and description |
|---|---|
obm.cheats.get() |
{ god_mode, invisible, infinite_ammo, infinite_clip, time_multiplier }: the engine's cheat switches |
obm.cheats.set(patch) |
Sets the fields present in patch; time_multiplier is clamped to 0.2..10. They are the game's own and stay until changed. |
obm.save.can_quick_save() |
true in a mission where the pause menu would allow a save |
obm.save.quick_save(), obm.save.quick_load() |
Saves to, or loads, the quick save slot at the start of the next frame, as the quick save/load bindings do; true when allowed |
obm.movies.playing() |
true while a movie plays |
obm.movies.skip_intros(on) |
Skips the logo movies before the main menu (true), plays them (false), or with nil follows the launcher's SKIP INTRO setting. Takes effect for the next movie, so set it at the top of the entry file. |
obm.movies.skip() |
In a movie_start listener: skips that movie. true there, false elsewhere. |
obm.ghost, obm.net¶
| Function | Returns and description |
|---|---|
obm.ghost.start_record() |
Starts recording 47's position every 0.1 s, up to 3,600 frames |
obm.ghost.stop_record() |
Stops and returns the array of { t, x, y, z } frames (t in seconds from the start) |
obm.ghost.play(id, frames [, opts]) |
true on success. Plays frames as a figure with a name plate. opts: label (default id), color (0x38d0ff), loop (true), armed (false: draws the figure holding a gun). Frames without t are 0.1 s apart. |
obm.ghost.set_pose(id, x, y, z [, label=id, rgb=0x38d0ff, armed=false]) |
true on success. Places a figure; its facing and walk follow its movement between calls. |
obm.ghost.remove(id) |
Removes a figure |
obm.net.allowed() |
true when the player allowed mod networking |
obm.net.open([port=0]) |
true when this mod's UDP socket is bound to port on all interfaces; 0 lets the system choose a free port. Opening again replaces the mod's socket. At most 8 mods can have a socket at once. |
obm.net.send(host, port, data) |
true when sent. host is a numeric IPv4 address or "localhost", in the ranges in Security model; data is a string of at most 1,400 bytes. |
obm.net.poll() |
data, host, port for the next waiting packet, or nil when none is waiting. Call it in a loop until it returns nil. |
obm.net.close() |
Closes this mod's socket |
local data, host, port = obm.net.poll()
while data do
handle(data, host, port)
data, host, port = obm.net.poll()
end
obm.contracts¶
| Function | Returns and description |
|---|---|
obm.contracts.list() |
Array of contract tables from contracts/*.json |
obm.contracts.active() |
The active contract, or nil |
obm.contracts.start(id) |
true when the contract exists; makes it active (its tracker is shown in missions) |
obm.contracts.clear() |
No active contract |
obm.contracts.save(contract) |
true, id when written to contracts/<id>.json, otherwise false. Without an id, one is made from the title; a given id must be a valid id (as for mods). |
obm.contracts.delete(id) |
true when deleted |
A contract table is { id, title, author, scene, briefing, kill_method, disguise, suit_only, targets }, with targets an array of up to 4 names (see Community contracts).
obm.scripts, obm.api¶
These reach the compiled mission scripts (the .c scripts of each level, see scene-scripts.md) and the 716 script interfaces they call.
| Function | Returns and description |
|---|---|
obm.scripts.list() |
Array of { ref, script, geom } for the scripts loaded in the scene: the object's ref, the script name and the object's name |
obm.scripts.send(ref, msg [, sender=0]) |
true when sent. Sends the message named msg to the object. A name the game does not know is registered for the rest of the session; the game's table holds 1,024 names, and once it is full a new name returns false. |
obm.scripts.on_message(msg, fn) |
Calls fn(ev) for each message named msg (case-insensitive; "*" for all) delivered to a script, with ev = { target, script, msg, msg_id }. Returning false blocks the message; later handlers are then not called. Script messages (ids from 1024, such as M01_ExitPlane) have no name in the engine's message table: a hook by name matches them by id, and a "*" hook sees msg as "" with the id in msg_id. |
obm.scripts.hook_api(name [, { script = "..." }], fn) |
Calls fn(call) each time a scene script calls the interface name (only scripts named script, if given), with call = { api, script, object, args }. Calls a mod makes through obm.api are not offered to hooks. An unknown interface name raises an error. args holds the arguments: numbers for float parameters, strings for string parameters, unsigned 32-bit integers for integer and REF parameters, and addresses for the rest (an event gives its message number). Return nil to let the call run, obm.scripts.BLOCK to skip it with a result of 0, or a value to skip it and use the value as its result. The first handler that returns something wins. |
obm.scripts.disable(name_or_ref) |
Stops scripts with that name, or the script of that object: they no longer update or receive messages, until the mods reload |
obm.scripts.replace(name, def) |
Runs Lua in place of each script with that name loaded from now on. def.run(self) runs as a coroutine resumed at every script update; self:wait(seconds) pauses it for that much game time. def.on_message is a table of MessageName = function(self, msg) handlers. self is { ref, script, imports, wait }, with imports the script's scene properties in order. Register at the top level of the entry file to catch the first scene's scripts. |
obm.scripts.signature(name) |
letters, callable for an interface, or nil for an unknown name. letters is the result type followed by one letter per parameter; callable says whether obm.api can call it. Hm3Gui__Displaysubtitletimed is "vsf": no result, a string and a float. |
obm.api.<Name>(...) |
Calls a script interface directly. nil when no interface has that name or Lua cannot call it. |
Interface names are those of the script thunks in port/engine/ScriptInterfaces/_sdl/scriptthunkssdl.cpp, without the ScriptThunk_ prefix: a class and a method joined by two underscores, each capitalised as one word, such as Silevelcontrol__Missionfailed, Silevelcontrol__Getdifficulty, Hm3Gui__Displaysubtitletimed or Zhm3Actor__Gethitpoints. Names are matched without regard to case. script-thunks.md describes the interfaces.
Signature letters:
| Letter | Meaning | obm.api argument |
|---|---|---|
w |
integer, enum or ref | an integer or a boolean |
f |
float | a number |
s |
string | a string (copied to script memory) or nil |
p |
pointer to anything else, or a struct | cannot be called |
v |
void result; as a parameter, variable arguments | cannot be called when a parameter |
m |
struct result | cannot be called |
obm.api can call an interface whose parameters are only w, f and s, with at most 16 integer and string arguments, 8 float arguments and no struct result. There is no way to pass a raw address. Every argument must be given with the right type, or the call raises an error. The result is a number for f, an integer for w and s, and nothing for v.