Examples
Eight complete mods, each showing a different part of the API. They are in the download's examples/mods/ folder:
copy one into your mods folder to try it, then change it. Every one of them is tested in the game.
| Mod | Keys | Shows |
|---|---|---|
| Creature Labels | the draw event, world.creatures, c:screen(), settings |
|
| Survival Waves | timers, spawning around the hunter, lives with player_death, saved data |
|
| Boss Rex | B | per-creature data, changing damage in hit, phases, a boss health bar |
| Admin Menu | F1 | a mod menu tab: combo boxes, sliders, checkboxes, a live table, camera, possession |
| Perk Shop | P | an interactive window with ui.cursor, points saved between sessions, a HUD radar |
| Pet Raptor | K | a creature driven entirely by the script (c.ai = false) |
| Dino Arena | F7, F1 | a whole game mode: team fights, pens, tints, a shrinking zone, hazards, kill cam, bets, tournaments, statistics |
| Clean HUD | H, Esc | the game's own HUD: hud.hide, hud.offset, hud.scale, player.ammo, the back event |
Creature Labels
A name, distance and health bar over every creature near the hunter, with three settings in the mod menu.
-- Creature Labels: a name and a health bar over every creature near the hunter.
-- Shows: the draw event, world.creatures with a filter, c:screen(), draw.text / draw.bar, settings.
mod.setting("enabled", true, { label = "Show labels" })
mod.setting("range", 6000, { label = "Range", min = 1000, max = 20000, help = "How far away creatures get a label" })
mod.setting("dead", false, { label = "Label dead bodies too" })
local function healthColor(f)
if f > 0.6 then return "#5fd35f" elseif f > 0.3 then return "#f0c040" else return "#e04a3a" end
end
on("draw", function()
if not (game.inHunt() and mod.settings.enabled) then return end
local filter = { radius = mod.settings.range, all = mod.settings.dead }
for _, c in ipairs(world.creatures(filter)) do
local sx, sy = c:screen()
if sx then
local f = c.alive and c.health / c.maxHealth or 0
local label = c.alive and string.format("%s %dm", c.name, math.floor(c.distance / 128)) or (c.name .. " (dead)")
draw.text(sx, sy - 26, label, c.alive and "white" or "gray", 18, "center")
if c.alive then draw.bar(sx - 40, sy - 6, 80, 7, f, healthColor(f)) end
end
end
end)
Survival Waves
Waves of predators that grow every round, three lives, the best wave saved. The settings choose the attackers and the pace.
-- Survival Waves: every round sends more predators at the hunter; survive as long as you can.
-- Shows: timers, spawning around the player, player_death (lives), kill counting, saved data, a HUD.
mod.setting("interval", 45, { label = "Seconds between waves", min = 15, max = 120 })
mod.setting("lives", 3, { label = "Lives", min = 1, max = 9 })
mod.setting("species", "velociraptor", { label = "Attackers", options = { "velociraptor", "utahraptor", "troodon", "allosaurus" } })
local save = mod.load() or { best = 0 }
local wave, lives, alive, nextWave, running = 0, 0, {}, 0, false
local function spawnWave()
wave = wave + 1
local x, _, z = player.pos()
local count = 2 + wave
for i = 1, count do
local angle = (i / count) * 360 + math.random(-15, 15)
local dx, dz = math.forward(angle)
local distance = 3500 + math.random(0, 1500)
local c = world.spawn(mod.settings.species, x + dx * distance, z + dz * distance)
if c then
c:alert() -- they know where you are
alive[#alive + 1] = c
end
end
game.message("Wave " .. wave .. ": " .. count .. " attackers!", 4, "orange")
if wave > save.best then
save.best = wave
mod.save(save)
end
end
on("hunt_start", function()
wave, lives, alive, running = 0, mod.settings.lives, {}, true
nextWave = timer.now() + 10
game.message("Survival: first wave in 10 seconds", 5)
end)
on("hunt_end", function() running = false end)
on("frame", function()
if not running or not game.inHunt() or game.paused() then return end
for i = #alive, 1, -1 do
if not alive[i].valid or not alive[i].alive then table.remove(alive, i) end
end
if timer.now() >= nextWave then
spawnWave()
nextWave = timer.now() + mod.settings.interval
end
end)
on("player_death", function(e)
if not running then return end
lives = lives - 1
if lives > 0 then
e.cancelled = true
game.message(lives .. (lives == 1 and " life" or " lives") .. " left!", 4, "red")
if e.killer then e.killer:kill() end -- the attacker pays for it
else
game.message("Game over at wave " .. wave .. " (best: " .. save.best .. ")", 8, "red")
running = false
end
end)
on("draw", function(e)
if not running then return end
local left = math.max(0, math.ceil(nextWave - timer.now()))
draw.fillRect(e.width / 2 - 170, 8, 340, 34, "#00000088", 6)
draw.text(e.width / 2, 13, string.format("Wave %d | %d left | next in %ds | lives %d", wave, #alive, left, lives),
"white", 20, "center")
end)
ui.panel("Survival", function()
ui.text("Best wave:", save.best)
if ui.button("Reset best") then save.best = 0; mod.save(save) end
if running and ui.button("Next wave now") then nextWave = timer.now() end
end)
Boss Rex
Press B in a hunt: a giant T-Rex with its own health bar. Below half health it grows, roars and calls raptors.
-- Boss Rex: a giant T-Rex with a boss health bar, an enraged second phase and raptor helpers.
-- Shows: per-creature data (c.data), the hit event changing damage, creature fields, sounds, a top-of-screen HUD.
local boss = nil
local function spawnBoss()
if boss and boss.valid and boss.alive then
game.message("The boss is already hunting you")
return
end
boss = world.spawnNear("trex", 6000)
if not boss then return end
boss.scale = boss.scale * 1.8
boss.health = 6000
boss.data.maxHealth = 6000
boss.data.phase = 1
boss:alert(60)
game.message("The Boss Rex is coming...", 5, "red")
end
keys.bind("B", function()
if game.inHunt() then spawnBoss() end
end)
on("hit", function(e)
if e.creature ~= boss then return end
e.damage = e.damage * 0.75 -- thick skin
local after = boss.health - e.damage
if boss.data.phase == 1 and after < boss.data.maxHealth / 2 then
boss.data.phase = 2
boss.scale = boss.scale * 1.15
game.message("The Boss Rex is ENRAGED!", 5, "red")
boss:sound(0, 1) -- its first sound (a roar for most species)
for i = 1, 3 do
local helper = world.spawn("velociraptor", boss.x + math.random(-800, 800), boss.z + math.random(-800, 800))
if helper then helper:alert() end
end
end
end)
on("kill", function(e)
if e.creature == boss then
game.message("You killed the Boss Rex!", 8, "yellow")
boss = nil
end
end)
on("draw", function(e)
if not (boss and boss.valid and boss.alive) then return end
local w = e.width * 0.5
local x = (e.width - w) / 2
local y = e.height * 0.1 -- below other mods' top-of-screen lines
draw.text(e.width / 2, y, boss.data.phase == 2 and "BOSS REX (enraged)" or "BOSS REX", "white", 22, "center")
draw.bar(x, y + 30, w, 16, boss.health / boss.data.maxHealth, boss.data.phase == 2 and "#ff3020" or "#d06020", "#000000aa")
draw.text(e.width / 2, y + 50, math.floor(boss.distance / 128) .. " m away", "#dddddd", 16, "center")
end)
Admin Menu
A tab in the mod menu (F1) with world tools: spawn any species, god mode, frozen world, creature fights, and a table of every creature with buttons to watch it or drive it.
-- Admin Menu: a tab in the mod menu (F1) with world tools and a live creature table.
-- Shows: ui.panel, combo / sliders / checkboxes / tables / collapsing headers, the world API, camera and possession.
local speciesList = world.species()
local names = {}
for i, s in ipairs(speciesList) do names[i] = s.name end
local chosen, distance, count, team = 1, 2000, 1, 0
ui.panel("Admin", function()
if not game.inHunt() then
ui.textDisabled("Start a hunt to use the world tools.")
return
end
ui.heading("Spawn")
chosen = ui.combo("Species", chosen, names)
distance = ui.slider("Distance", distance, 500, 8000, "%.0f")
count = ui.sliderInt("How many", count, 1, 20)
team = ui.sliderInt("Team (fights)", team, 0, 4)
if ui.button("Spawn") then
for i = 1, count do
local c = world.spawnNear(speciesList[chosen].id, distance + (i - 1) * 300)
if c and team > 0 then c.team = team end
end
end
ui.heading("World")
local god, changed = ui.checkbox("God mode", world.god())
if changed then world.god(god) end
ui.sameLine()
local inv; inv, changed = ui.checkbox("Invisible", world.invisible())
if changed then world.invisible(inv) end
ui.sameLine()
local frozen; frozen, changed = ui.checkbox("Frozen", world.frozen())
if changed then world.frozen(frozen) end
ui.sameLine()
local fights; fights, changed = ui.checkbox("Creature fights", world.fights())
if changed then world.fights(fights) end
if ui.button("Kill all") then world.killAll() end
ui.sameLine()
if ui.button("Remove all") then world.removeAll() end
ui.sameLine()
if ui.button("Clear bodies") then world.clearBodies() end
if camera.following() or world.possessed() then
ui.sameLine()
if ui.button("Back to the hunter") then camera.follow(nil); world.unpossess() end
end
if ui.collapsing("Creatures (" .. world.count() .. " alive)", true) then
ui.table("creatures", 6, function()
for _, c in ipairs(world.creatures({ radius = 20000 })) do
ui.id(c.id, function()
ui.nextRow(); ui.text(c.name)
ui.nextColumn(); ui.text(math.floor(c.distance / 128) .. " m")
ui.nextColumn(); ui.progress(c.health / c.maxHealth, tostring(math.floor(c.health)))
ui.nextColumn(); ui.text(c.team)
ui.nextColumn(); if ui.smallButton("Watch") then camera.follow(c, 1800) end
ui.nextColumn(); if ui.smallButton("Drive") then c:possess(); camera.follow(c) end
end)
end
end, { "Species", "Distance", "Health", "Team", "", "" })
end
end)
Perk Shop
Kills earn points (kept between sessions); P opens a shop window. The mouse cursor shows while it is open.
-- Perk Shop: points for kills, a shop window (press P) to buy perks. Points are saved between sessions.
-- Shows: an interactive ui.window with ui.cursor, saved data, the hit and player_death events, a HUD radar.
local data = mod.load() or { points = 0 }
local perks = { radar = false, heavy = false, life = false }
local shopOpen = false
local catalog = {
{ id = "radar", name = "Radar", cost = 50, text = "An arrow to the nearest creature" },
{ id = "heavy", name = "Heavy rounds", cost = 120, text = "Your shots deal 50% more damage" },
{ id = "life", name = "Second life", cost = 200, text = "Survive one deadly attack" },
}
local function setShop(open)
shopOpen = open
ui.cursor(open) -- the mouse cursor shows while the shop is open
end
keys.bind("P", function() if game.inHunt() then setShop(not shopOpen) end end)
on("hunt_end", function() setShop(false); perks = { radar = false, heavy = false, life = false } end)
on("kill", function(e)
if e.byHunter then
local reward = e.creature.predator and 40 or 15
data.points = data.points + reward
mod.save(data)
game.message("+" .. reward .. " points", 2, "yellow")
end
end)
on("hit", function(e)
if perks.heavy then e.damage = e.damage * 1.5 end
end)
on("player_death", function(e)
if perks.life then
perks.life = false
e.cancelled = true
game.message("Second life used!", 4, "orange")
end
end)
on("draw", function(e)
if not game.inHunt() then return end
draw.text(e.width - 20, 20, data.points .. " points (P: shop)", "yellow", 20, "right")
if perks.radar then
local target = world.nearest()
if target then
local x, _, z = player.pos()
local turn = math.angleDiff(player.yaw(), math.yaw(x, z, target.x, target.z))
local cx, cy, r = e.width / 2, e.height - 90, 34
local dx, dz = math.forward(turn)
draw.circle(cx, cy, r, "#ffffff66", 2)
draw.line(cx, cy, cx + dx * r, cy + dz * r, "#ffd040", 3)
draw.text(cx, cy + r + 4, target.name .. " " .. math.floor(target.distance / 128) .. " m", "white", 16, "center")
end
end
if shopOpen then
shopOpen = ui.window("Perk shop", function()
ui.text("Points:", data.points)
ui.separator()
for _, item in ipairs(catalog) do
ui.id(item.id, function()
ui.text(item.name .. " (" .. item.cost .. ")")
ui.textDisabled(item.text)
if perks[item.id] then
ui.textColored("green", "bought")
elseif ui.button("Buy") then
if data.points >= item.cost then
data.points = data.points - item.cost
perks[item.id] = true
mod.save(data)
else
game.message("Not enough points", 2, "red")
end
end
ui.spacing()
end)
end
end, { x = e.width / 2 - 170, y = 120, w = 340, h = 330, closable = true })
if not shopOpen then setShop(false) end
end
end)
Pet Raptor
Press K: a Velociraptor that follows you. Its AI is switched off; the script turns, moves and animates it.
-- Pet Raptor: a Velociraptor whose AI is switched off; the script makes it follow the hunter.
-- Shows: c.ai = false, choosing animations by name, c:move / c.yaw / c:animate, per-frame control.
local pet, walk, run, idle = nil, nil, nil, nil
local function callPet()
if pet and pet.valid and pet.alive then pet:remove() end
pet = world.spawnNear("velociraptor", 800)
if not pet then return end
pet.ai = false -- the game's AI no longer moves it: we do
pet.team = 0
walk = pet:findAnim("walk") or 0
run = pet:findAnim("run") or walk
idle = pet:findAnim("idle") or pet:findAnim("stand") or walk
pet.anim = idle
game.message("Your raptor is here. Good boy.", 4, "green")
end
keys.bind("K", function() if game.inHunt() then callPet() end end)
on("frame", function(e)
if not (pet and pet.valid and pet.alive) or game.paused() then return end
local x, _, z = player.pos()
local d = pet:distanceTo(x, z)
local wanted = idle
if d > 600 then
local speed = d > 2000 and 1400 or 450 -- units per second: run to catch up, walk when close
wanted = d > 2000 and run or walk
local goal = math.yaw(pet.x, pet.z, x, z)
pet.yaw = pet.yaw + math.clamp(math.angleDiff(pet.yaw, goal), -240 * e.dt, 240 * e.dt)
pet:move(speed * e.dt)
end
if pet.anim ~= wanted then pet.anim = wanted end
pet:animate(e.dt)
end)
on("hunt_end", function() pet = nil end)
Dino Arena
A complete game mode built only from the API: two teams of dinosaurs in pens, a countdown, then team against team.
Team colours on the models (c.tint), health bars, a shrinking zone and hazard strikes drawn on the ground, a director
camera and a slow-motion kill cam, handicaps, bets with your credits, automatic 1v1 tournaments and a species win-rate
table that is saved. Set it up in the mod menu's Arena tab, or press F7 in a hunt.
-- Dino Arena: team fights between dinosaurs, made only with the modding API.
-- F7 in a hunt (or the Arena tab of the mod menu) starts a match with the current setup.
local TEAM = { { name = "RED", color = "#ff4a3a", tint = { 1, 0.35, 0.3, 0.75 } },
{ name = "BLUE", color = "#4a8cff", tint = { 0.35, 0.55, 1, 0.75 } } }
local speciesIds, speciesNames = {}, {}
for _, s in ipairs(world.species()) do
if s.type >= 16 then speciesIds[#speciesIds + 1] = s.id; speciesNames[#speciesNames + 1] = s.name end
end
local function speciesIndex(id) for i, v in ipairs(speciesIds) do if v == id then return i end end return 1 end
local setup = { speciesIndex("velociraptor"), speciesIndex("allosaurus") } -- red / blue species
local counts = { 4, 2 }
local handicap = { 100, 100 } -- damage in percent
local options = { zone = true, hazards = true, killcam = true, director = true, tournament = false }
local bet = { team = 1, amount = 100 }
local stats = mod.load() or { species = {} }
local arena = nil -- the running match
local function record(id, won)
local s = stats.species[id] or { wins = 0, games = 0 }
s.games = s.games + 1
if won then s.wins = s.wins + 1 end
stats.species[id] = s
end
local function fighters(team)
local out = {}
for _, c in ipairs(arena.fighters) do
if c.valid and c.alive and (not team or c.team == team) then out[#out + 1] = c end
end
return out
end
local function stop()
if not arena then return end
world.fights(false)
camera.follow(nil)
game.timeScale(1)
arena = nil
end
local function start(redSpecies, redCount, blueSpecies, blueCount)
if not game.inHunt() then game.message("Start a hunt first") return end
stop()
world.removeAll(); world.clearBodies(); world.fights(false)
world.invisible(true); world.god(true)
local cx, _, cz = world.inFront(5000)
local dx, dz = player.forward()
arena = { x = cx, z = cz, fighters = {}, phase = "setup", t = 0, zone = 7000, hazards = {}, nextHazard = 12,
pens = { { x = cx - dz * 1800, z = cz + dx * 1800 }, { x = cx + dz * 1800, z = cz - dx * 1800 } },
species = { redSpecies, blueSpecies }, bet = nil }
for team = 1, 2 do
local pen = arena.pens[team]
for i = 1, team == 1 and redCount or blueCount do
local c = world.spawn(arena.species[team], pen.x + math.random(-500, 500), pen.z + math.random(-500, 500))
if c then
c.team, c.tint = team, TEAM[team].tint
arena.fighters[#arena.fighters + 1] = c
end
end
end
if bet.amount > 0 and player.credits() >= bet.amount then
player.addCredits(-bet.amount)
arena.bet = { team = bet.team, amount = bet.amount }
end
camera.follow(arena.fighters[1], 3500)
game.message("Arena: " .. redCount .. " x " .. redSpecies .. " vs " .. blueCount .. " x " .. blueSpecies, 5)
end
local function startFromSetup()
start(speciesIds[setup[1]], counts[1], speciesIds[setup[2]], counts[2])
end
local function randomDuel()
local a, b = speciesIds[math.random(#speciesIds)], speciesIds[math.random(#speciesIds)]
start(a, 1, b, 1)
end
keys.bind("F7", startFromSetup)
-- pens: until the release, nobody leaves its pen
on("creature_after_ai", function(e)
if not arena or arena.phase == "fight" or arena.phase == "over" then return end
local c = e.creature
if c.team ~= 1 and c.team ~= 2 then return end
local pen = arena.pens[c.team]
local d = c:distanceTo(pen.x, pen.z)
if d > 700 then
c.x = pen.x + (c.x - pen.x) * 700 / d
c.z = pen.z + (c.z - pen.z) * 700 / d
end
end)
-- handicaps
on("creature_damage", function(e)
if arena and e.attacker and (e.attacker.team == 1 or e.attacker.team == 2) then
e.damage = e.damage * handicap[e.attacker.team] / 100
end
end)
-- kill cam: slow motion on the winner of a duel
on("kill", function(e)
if not arena or arena.phase ~= "fight" or not options.killcam then return end
if e.killer and e.killer.valid then
camera.follow(e.killer, 2200)
game.timeScale(0.3)
arena.killcamUntil = timer.now() + 1.2
end
end)
local function finish(winner)
arena.phase, arena.t = "over", 0
arena.winner = winner
world.fights(false)
for team = 1, 2 do record(arena.species[team], winner == team) end
mod.save(stats)
if arena.bet then
if arena.bet.team == winner then
player.addCredits(arena.bet.amount * 2)
game.message("You won the bet: +" .. arena.bet.amount * 2 .. " credits", 6, "yellow")
else
game.message("You lost the bet", 4, "gray")
end
end
end
on("frame", function(e)
if not arena then return end
if not game.inHunt() then arena = nil return end
local dt = e.dt
arena.t = arena.t + dt
if arena.killcamUntil and timer.now() > arena.killcamUntil then game.timeScale(1); arena.killcamUntil = nil end
if arena.phase == "setup" and arena.t > 3 then
arena.phase, arena.t = "countdown", 0
elseif arena.phase == "countdown" and arena.t > 3 then
arena.phase, arena.t = "fight", 0
world.fights(true)
game.message("FIGHT!", 2, "orange")
elseif arena.phase == "fight" then
local red, blue = #fighters(1), #fighters(2)
if red == 0 or blue == 0 then finish(red > 0 and 1 or (blue > 0 and 2 or 0)) return end
if options.zone then -- the zone shrinks; outside it, creatures lose health
arena.zone = math.max(1500, arena.zone - 60 * dt)
for _, c in ipairs(fighters()) do
if c:distanceTo(arena.x, arena.z) > arena.zone then c.health = math.max(0, c.health - c.maxHealth * 0.08 * dt) end
end
end
if options.hazards and arena.t > arena.nextHazard then -- a strike: marked first, then it hits
local a, r = math.random() * 360, math.random() * arena.zone * 0.7
local hx, hz = math.forward(a)
arena.hazards[#arena.hazards + 1] = { x = arena.x + hx * r, z = arena.z + hz * r, at = arena.t + 2 }
arena.nextHazard = arena.t + 8 + math.random() * 6
end
for i = #arena.hazards, 1, -1 do
local h = arena.hazards[i]
if arena.t >= h.at then
for _, c in ipairs(fighters()) do
if c:distanceTo(h.x, h.z) < 600 then c.health = math.max(0, c.health - c.maxHealth * 0.4) end
end
sound.playAt("dbsgun_sound_0.wav", h.x, world.ground(h.x, h.z), h.z, 1, 30000)
table.remove(arena.hazards, i)
end
end
if options.director and not arena.killcamUntil and arena.t - (arena.lastCut or -10) > 6 then -- the director: cut to the action
local best, bestScore = nil, -1
for _, c in ipairs(fighters()) do
local score = (c.attacking and 100 or 0) + c.damageDealt
if score > bestScore then best, bestScore = c, score end
end
if best then camera.follow(best, 2600); arena.lastCut = arena.t end
end
elseif arena.phase == "over" and arena.t > 5 then
if options.tournament then randomDuel() else stop() end
end
end)
-- a world-space circle on the screen
local function circle(x, z, radius, color, thickness)
local px, py
for i = 0, 48 do
local dx, dz = math.forward(i * 7.5)
local wx, wz = x + dx * radius, z + dz * radius
local sx, sy = game.project(wx, world.ground(wx, wz) + 60, wz)
if sx and px then draw.line(px, py, sx, sy, color, thickness) end
px, py = sx, sy
end
end
on("draw", function(e)
if not arena then return end
for _, c in ipairs(fighters()) do -- health bars in team colours
local sx, sy = c:screen()
if sx then
draw.text(sx, sy - 26, c.name, TEAM[c.team].color, 17, "center")
draw.bar(sx - 36, sy - 6, 72, 7, c.health / c.maxHealth, TEAM[c.team].color)
end
end
if options.zone and arena.phase == "fight" then circle(arena.x, arena.z, arena.zone, "#ffd04099", 3) end
for _, h in ipairs(arena.hazards) do circle(h.x, h.z, 600, "#ff2020", 2) end
local w = e.width
draw.fillRect(w / 2 - 190, 10, 380, 34, "#00000099", 6)
draw.text(w / 2, 15, string.format("RED %d vs %d BLUE", #fighters(1), #fighters(2)), "white", 22, "center")
if arena.phase == "countdown" then
draw.text(w / 2, e.height * 0.35, tostring(3 - math.floor(arena.t)), "white", 96, "center")
elseif arena.phase == "setup" then
draw.text(w / 2, e.height * 0.35, "Get ready", "white", 48, "center")
elseif arena.phase == "over" then
local text = arena.winner == 0 and "DRAW" or (TEAM[arena.winner].name .. " WINS")
draw.text(w / 2, e.height * 0.35, text, arena.winner == 0 and "white" or TEAM[arena.winner].color, 72, "center")
end
end)
ui.panel("Arena", function()
if not game.inHunt() then ui.textDisabled("Start a hunt, then set up a match here (or press F7).") end
ui.table("teams", 2, function()
for team = 1, 2 do
ui.nextColumn()
ui.id(team, function()
ui.textColored(TEAM[team].color, TEAM[team].name)
setup[team] = ui.combo("Species", setup[team], speciesNames)
counts[team] = ui.sliderInt("Count", counts[team], 1, 12)
handicap[team] = ui.sliderInt("Damage %", handicap[team], 25, 300)
end)
end
end)
ui.heading("Options")
options.zone = ui.checkbox("Shrinking zone", options.zone); ui.sameLine()
options.hazards = ui.checkbox("Hazard strikes", options.hazards); ui.sameLine()
options.killcam = ui.checkbox("Kill cam", options.killcam)
options.director = ui.checkbox("Director camera", options.director); ui.sameLine()
options.tournament = ui.checkbox("Auto tournament (random 1v1s)", options.tournament)
ui.heading("Bet (credits: " .. player.credits() .. ")")
if ui.radio("Red", bet.team == 1) then bet.team = 1 end; ui.sameLine()
if ui.radio("Blue", bet.team == 2) then bet.team = 2 end; ui.sameLine()
ui.width(160); bet.amount = ui.sliderInt("Stake", bet.amount, 0, 1000)
if ui.button("Start match (F7)") then startFromSetup() end; ui.sameLine()
if ui.button("Random duel") then randomDuel() end; ui.sameLine()
if arena and ui.button("Stop") then stop() end
if ui.collapsing("Species win rates") then
local rows = {}
for id, s in pairs(stats.species) do rows[#rows + 1] = { id = id, s = s } end
table.sort(rows, function(a, b) return a.s.wins / a.s.games > b.s.wins / b.s.games end)
ui.table("rates", 3, function()
for _, r in ipairs(rows) do
ui.nextRow(); ui.text(r.id)
ui.nextColumn(); ui.text(r.s.wins .. " / " .. r.s.games)
ui.nextColumn(); ui.progress(r.s.wins / r.s.games)
end
end, { "Species", "Wins", "Rate" })
if ui.smallButton("Reset") then stats.species = {}; mod.save(stats) end
end
end)
Clean HUD
Changes the game's own HUD: no MENU tab (Esc opens the menu and closes it again), an ammo counter of its own, the compass bigger and higher by settings, and H hides the whole HUD for screenshots (H or Esc brings it back).
-- Clean HUD: changes the game's own HUD. No MENU tab (Esc opens the menu, and closes it again), the ammo count replaced
-- by a counter of its own (loaded / total), the compass bigger and higher, and H hides every part of the HUD for
-- screenshots. Shows: hud.hide / hud.offset / hud.scale, player.ammo, the back event, settings that apply at once.
mod.setting("menuTab", false, { label = "Show the MENU tab" })
mod.setting("ammo", true, { label = "Own ammo counter" })
mod.setting("compassSize", 1.4, { label = "Compass size", min = 0.5, max = 3 })
mod.setting("compassUp", 0, { label = "Compass higher by", min = 0, max = 400 })
local screenshot = false -- H: everything hidden
local function apply()
hud.reset()
if screenshot then
hud.hide("all")
return
end
if not mod.settings.menuTab then hud.hide("menu") end
if mod.settings.ammo then hud.hide("ammo") end
hud.scale("compass", mod.settings.compassSize)
hud.offset("compass", 0, -mod.settings.compassUp)
end
apply()
on("setting", function(e)
if e.mod == mod.id then apply() end
end)
keys.bind("H", function()
if not game.inHunt() then return end
screenshot = not screenshot
apply()
end)
-- Esc while the HUD is hidden brings it back instead of opening the menu
on("back", function(e)
if screenshot and game.inHunt() and not e.menuOpen then
screenshot = false
apply()
e.cancelled = true
end
end)
on("draw", function(e)
if screenshot or not (mod.settings.ammo and game.inHunt()) or hud.menuOpen() then return end
local total, loaded = player.ammo()
if not total then return end
local text = string.format("%d / %d", loaded, total)
local w = draw.textSize(text, 26)
local x, y = e.width - 28, e.height - 58
draw.fillRect(x - w - 18, y - 8, w + 32, 44, { 0, 0, 0, 0.45 }, 8)
draw.text(x, y, text, total == 0 and "#ff6040" or "#ffd040", 26, "right")
end)
Small recipes
Bigger dinosaurs everywhere
on("spawn", function(e) e.creature.scale = e.creature.scale * 1.5 end)
One-shot kills with the first weapon
on("hit", function(e) if e.weapon == 0 then e.damage = 100000 end end)
A T-Rex every two minutes
on("hunt_start", function()
timer.every(120, function() if game.inHunt() then world.spawnNear("trex", 5000) end end)
end)
Raptor ambush: ten raptors in a ring around you, five seconds into the hunt
on("hunt_start", function()
timer.after(5, function()
local x, _, z = player.pos()
for i = 1, 10 do
local dx, dz = math.forward(i * 36)
local r = world.spawn("velociraptor", x + dx * 4000, z + dz * 4000)
if r then r:alert() end
end
end)
end)
Creature fights between two teams
keys.bind("F6", function()
for i = 1, 4 do world.spawnNear("velociraptor", 2500 + i * 200).team = 1 end
for i = 1, 2 do world.spawnNear("allosaurus", 4000 + i * 300).team = 2 end
world.fights(true)
end)
Count kills per species, saved
local stats = mod.load() or {}
on("kill", function(e)
if e.byHunter then
stats[e.creature.species] = (stats[e.creature.species] or 0) + 1
mod.save(stats)
end
end)
ui.panel("My trophies", function()
for species, n in pairs(stats) do ui.text(species, n) end
end)