--[[ Spooky "Pluto" example script - exercises the expanded API. Run it from the menu: Settings -> Scripts -> Example -> Start. Everything here runs on the game thread and is written to be non-destructive. API summary: Globals: LOG/Log, Notify, Yield(ms), GetGameVersion, GetSpookyVersion, GetAccountName, GetAccountTier, AmIHost, IsGameLoaded, IsInMainMenu, GetSceneName, GetMapName, GetPing, GetPlayerSanity, SetPlayerSanity, GetTimeScale, SetTimeScale, GetDeltaTime, Teleport(x,y,z | {x,y,z}), GetPlayerList(), GetObjectsOfType(typeName), GetLocalPlayer, GetObjectByName, GetObjectByTypeName, SetCursorVisible, SetCursorLockState, GetCursorLockState, GetServerAddress Component: GetName, IsValid, GetTransform, GetGameObject, GetComponent(name), GetComponents(name), SetName, Destroy, CallMethod(name, ...), CallMethodFloat/Int/Bool/String(name, ...) GameObject: GetName, IsValid, GetTransform, GetComponent, GetComponents, GetActive, SetActive, CallMethod(+typed) Transform: GetName, GetPosition/SetPosition, GetLocalPosition/SetLocalPosition, GetRotation/SetRotation, GetScale/SetScale, GetParent, GetRoot, GetChildCount, GetChild(i), GetComponent(name), CallMethod(+typed) Note: CallMethod supports int / float / bool / string / object arguments. For struct arguments (Vector3/Quaternion) use the dedicated wrappers, and use CallMethodFloat/Int/Bool/String when you need a return value. ]] local function log(msg) LOG(LogState.Info, "[Example] " .. tostring(msg)) end log("Started - running on the game thread") -- ---- basic information ------------------------------------------------- log("Spooky: " .. tostring(GetSpookyVersion())) log("Game: " .. tostring(GetGameVersion())) log("User: " .. tostring(GetAccountName())) log("Host: " .. tostring(AmIHost())) log("Loaded: " .. tostring(IsGameLoaded()) .. " MainMenu: " .. tostring(IsInMainMenu())) log("Map: " .. tostring(GetMapName()) .. " (scene: " .. tostring(GetSceneName()) .. ")") log("Ping: " .. tostring(GetPing()) .. "ms") log("Sanity: " .. tostring(GetPlayerSanity())) log("Delta: " .. tostring(GetDeltaTime())) -- ---- players ----------------------------------------------------------- local players = GetPlayerList() log("Players (" .. #players .. "):") for _, player in ipairs(players) do log(string.format(" - %s host=%s me=%s dead=%s", tostring(player.Name), tostring(player.IsHost), tostring(player.IsMe), tostring(player.IsDead))) end -- ---- local player + component API -------------------------------------- local player = GetLocalPlayer() if not player:IsValid() then log("No local player - join a lobby/game and run this again.") Notify("Pluto example: no local player") return end log("Local player: " .. player:GetName()) local transform = player:GetTransform() if transform then local pos = transform:GetPosition() log(string.format("Position (%.1f, %.1f, %.1f), children: %d", pos.x, pos.y, pos.z, transform:GetChildCount())) end -- Reflection-based method calls. -- CallMethodBool(name) invokes a no-arg getter and returns a bool. local renderer = player:GetComponent("Renderer") if renderer and renderer:IsValid() then local enabled = renderer:CallMethodBool("get_enabled") log("Player renderer enabled: " .. tostring(enabled)) -- CallMethod(name, value) now correctly forwards arguments (this was the old bug): renderer:CallMethod("set_enabled", true) end -- ---- type queries ------------------------------------------------------ local doors = GetObjectsOfType("Door") log("Doors in scene: " .. #doors .. " (showing up to 3)") for i, door in ipairs(doors) do if i > 3 then break end if door:IsValid() then local doorTransform = door:GetTransform() if doorTransform then local p = doorTransform:GetPosition() log(string.format(" Door %d at (%.1f, %.1f, %.1f)", i, p.x, p.y, p.z)) end end end -- ---- cooperative loop -------------------------------------------------- -- Yield(ms) returns control to the game and resumes after `ms`. -- A script that loops without yielding is aborted after ~100ms. local ticks = 0 while ticks < 5 do ticks = ticks + 1 log(string.format("Tick %d/5 - sanity %.1f", ticks, GetPlayerSanity())) Yield(500) end log("Finished") Notify("Pluto example script finished!")