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-30-2026, 05:50 PM (This post was last modified: 08-30-2026, 05:52 PM by Xardas0327.)
#1
I don't know these things are bugs or features.
So, I write them here.

There are 2 simple functions.
Quote:addEventHandler("onPlayerJoin", root, function(playerId)
      outputDebugString("onPlayerJoin Start")
      spawnPlayer(playerId, 12.0, 24.0, 2.0, 90)
      outputDebugString("onPlayerJoin End")
end)

addCommandHandler("default", function(playerId, commandName)
      spawnPlayer(playerId, 12.0, 24.0, 2.0, 90)
end)


  1. If a player join to the server, the player should be spawned on that position. ( x= 12.0, y = 24.0, z = 2.0)
    But it doesn't work. I have seen the 2 debug logs, but the player are still on the default position, where we start the game.
  2. If you the /default command, it is fine.
    But I see similar messages in the server log:
    Quote:[security] movement snapshot held player=2 violation=4 score=0.00 horizontal=4313.8/240.0 vertical=399.1/400.0 authorityGrace=1TRAFFIC_GUARD acceptedConnections=2 rejectedConnections=0 droppedPackets=4 disconnectedPeers=1 blockedAddresses=0 invalidPackets=0 oversizedPackets=0 trackedAddresses=1

  3. If I spawn the player another places like in the Gomez's castle, the game is loading and I get a new player id. (x= 1116.75, y = -1007.51, z = -36.66)
    And I see similar messages in the server log:
    Quote:[security] movement snapshot held player=1 violation=4 score=0.00 horizontal=43267.8/240.0 vertical=6120.6/400.0 authorityGrace=1
    CONNECT_PENDING player=2 address=xxx.xxx.xxx.xxx peer=0000020538CEE540

  4. If I use setPlayerPosition instead of  spawnPlayer, I get the same results.
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.
08-31-2026, 03:26 PM (This post was last modified: 08-31-2026, 03:28 PM by Xardas0327.)
#3
Thanks for an idea.
I have checked the spawnPlayer and setPlayerPosition return true or false, when they are called in onPlayerJoin.
Both of them are false.

I don't think it is the good behaviour.
I will create a bug report.
Forum Jump: