Jump to content

Join Handler


CapY

Recommended Posts

Well, with bandi's code the player will spawn, but you will still see a black screen.

And next time, use the wiki and the search in it.

For spawning a player you must use 3 functions:

fadeCamera -- fades the player's camera to a color or back to normal 
setCameraTarget -- used to make the camera follows the player (or follows another player 'spectate') 
spawnPlayer -- spawns the player 

Example:

addEventHandler("onPlayerJoin", root, 
function() 
local x = -1942 
local y = 537 
local z = 277 
spawnPlayer(source, x, y, z) 
fadeCamera(source, true) 
setCameraTarget(source, source) 
end) 

You can change the x, y, z.

Good luck.

Link to comment

This works good.

addEventHandler("onResourceStart", resourceRoot, 
    function() 
        resetMapInfo() 
        for i,player in ipairs(getElementsByType("player")) do 
            spawn(player) 
        end 
    end 
) 
  
function spawn(player) 
    if not isElement(player) then return end 
    repeat until spawnPlayer ( player, -711+math.random(1,5), 957+math.random(5,9), 12.4, 90, math.random(9,288), 0, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    showChat(player, true) 
end 
  
addEventHandler("onPlayerJoin", root, 
    function() 
    local x = -1942 
    local y = 537 
    local z = 277 
    spawnPlayer(source, x, y, z) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
    local x = -1942 
    local y = 537 
    local z = 277 
    spawnPlayer(source, x, y, z) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    setTimer(spawn, 1000, 1, source) 
    end 
) 

On join i spawn there and when i die i respawn there , but when i die i respawn there for 1 second and then it backs me to the default spawn...

What i did wrong ?

Link to comment

That's because you are using a timer to call "spawn" which will spawn the player back at the default position.

here:

addEventHandler("onPlayerWasted", root, 
    function() 
    local x = -1942 
    local y = 537 
    local z = 277 
    spawnPlayer(source, x, y, z) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    end 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...