RandomlyTeleportPlayer
Module: randomlyteleportplayer.lua
Overview
The RandomlyTeleportPlayer module is a stress test utility that randomly teleports the local player to predefined locations in the game world. It sets up a timer to repeatedly perform this teleportation, adding variability by changing both the destination and the delay between teleports.
Inheritance
- Inherits from:
none — base/utility module - Imports:
none
Instance pattern
This is a stateless utility module (no per-instance tables). It holds one local destination list, tLocation, and a set of file-scope local scratch variables x, y, z, n, s, e, guid shared across calls (declared once at the top, reused by Go each tick — they are not fresh per-call locals). e holds the current Event.TimerRelative handle.
tLocation — the destination markers
The hardcoded jump targets are named world markers resolved at runtime via Pg.GetGuidByName: "All_HQ", "Gur_HQ2", "GurHQ", "MecRecruit", "OilHQ", "PMC1.1", "Teleporter 0x000921c5". Edit this list to point the stress test at your own markers.
Functions
Init()
Called once when the module initializes. It starts the teleportation process by calling Go.
Go()
Performs one random teleport and reschedules itself:
- Picks
tLocation[Math.floor(Math.randf(1, table.maxn(tLocation)))]. - Resolves it to a GUID with
Pg.GetGuidByName; if that fails,x/y/zare set nil. - Bad-location path — if no position resolved, logs
"STRESS TEST: Bad location: …"and retries quickly viaEvent.Create(Event.TimerRelative, {0.1}, Go)(0.1 s). - Good path — logs the destination + delay, then teleports the local character with
Object.SetPosition(Player.GetLocalCharacter(), x, y + 20, z)(the+ 20Y offset drops the player in from slightly above the marker), and reschedulesGoafterMath.randf(5, 20)seconds.
Off-by-one in the picker: the index is
Math.floor(Math.randf(1, table.maxn(tLocation))), i.e. a float in[1, 7)floored — which yields1–6, never7. The last entry ("Teleporter 0x000921c5") is therefore unreachable. If you add markers totLocation, the final one you add is always the one that never gets picked.
Events
Uses Event.Create(Event.TimerRelative, {<delay>}, Go) to re-arm itself each cycle — a real Event scheduling call (a one-shot relative timer), re-created every tick rather than a persistent subscription. The good path schedules Go after 5–20 s; the bad-location path after 0.1 s. Init kicks the first Go off directly (no timer).
Notes for modders
- Stress-test utility, not for production — it teleports the local player indefinitely once
Initruns. - Retarget it by editing
tLocation(see above) — but remember the last entry is never chosen (the off-by-one above), so pad the list with a throwaway final marker if you want all your real ones reachable. - Change the cadence via the two
Math.randf(5, 20)calls inGo; change the drop height via they + 20offset. - It teleports
Player.GetLocalCharacter()only — the local player, not every player (contrast_G.DebugTeleportin the cheat bootstrap, which moves all players).