G1R:MP Forum Alpha
Log in Join
Gothic 1 Remake Multiplayer

The Colony Forum

News, support, development discussions, server communities, and stories from beyond the Barrier.

Colony discussion

onPlayerJoin event with spawnPlayer

Started by Xardas0327 in Scripting Help

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
08-31-2026, 06:15 AM (This post was last modified: 08-31-2026, 06:21 AM by Gummik. Edit Reason: removed old msg )
#2
Quote:local function spawnPlayerSafe(playerId, x, y, z, heading, skin)
    local attempts = 0
    local maxAttempts = 50
    local function trySpawn()
        attempts = attempts + 1

        local success = spawnPlayer(playerId, x, y, z, heading)
        if skin then
            setPlayerIdentity(playerId, skin)
        end
        if success then
            initiateInventory(playerId)
            return
        end

        if attempts >= maxAttempts then
            outputDebugString("Failed to spawn player after " .. maxAttempts .. " attempts.", 1)
            return
        end

        setTimer(trySpawn, 100, 1)
    end
    trySpawn()
end



For the framework I’m creating, I use this part for spawning players. The server simply waits until the player successfully spawns, and if the spawn fails, it repeats the command.
Forum Jump: