Useful functions

From PioneerWiki
Revision as of 23:27, 21 July 2024 by Zonkmachine (talk | contribs) (Timers and Game Time)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Timers and Game Time

Timer: Defined in src/lua/LuaTimer.cpp and documented in https://pioneerspacesim.net/codedoc/files/lua/LuaTimer-cpp.html.

local Comms = require 'Comms'
local Game = require 'Game'
local Event = require 'Event'
local Timer = require 'Timer'

local onShipDocked = function (ship, station)
    if not ship:IsPlayer() then return end

    Timer:CallAt(Game.time+10, function ()
        Comms.Message("This one last shown will be", "Yoda")
    end)
    Timer:CallAt(Game.time+6, function ()
        Comms.Message("This one will be shown in the middle", "Obi-Wan")
    end)
    Timer:CallAt(Game.time+2, function ()
        Comms.Message("This one will be shown first", "Obi-Wan")
    end)
end

Event.Register("onShipDocked", onShipDocked)