Jump to content

Spawning player on join.


rusztamas

Recommended Posts

addEventHandler("onPlayerJoin", root,function()
    spawn(source)
end)


function spawn(source)
    x, y, z = 2028.4606933594, 1342.2176513672, 10.8203125
    repeat until spawnPlayer(source,x+1,y+1,z, 0,303)
    setCameraTarget(source, player)
    fadeCamera(source, true) 
    setElementRotation(source, 0, 0, -90)
end

 

  • Like 1
Link to comment
  • Administrators
local x,y,z = 0,0,0

function spawnHandler(player)
	spawnPlayer(player, x, y, z)
	fadeCamera(player, true)
	setCameraTarget(player, player)
end

function start()
	local players = getElementsByType ( "player" )
	for i, v in ipairs(players) do
		spawnHandler(v)
	end
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), start )

function join()
	spawnHandler(source)
end
addEventHandler("onPlayerJoin", getRootElement(), join)

This will handle player spawning on join, and in the event that you restart the resource whilst people are in the server it will handle respawning too.

Works fine as I use this for many resources of my own.

2 hours ago, SuperCroz said:

don't use onPlayerJoin event I guess.

Try onClientResourceStart so this thing work whenever the resource starts instead whenever the player join. when the player joins this resource would not be loaded and therefore won't work I guess.

Also this doesn't make any sense. "onPlayerJoin" is only being triggered because the resource IS loaded.

Edited by LopSided_
Link to comment

@LopSided_ It doesn't make any sense but I believe I was right. Because the event onPlayerJoin is triggered whenever a player joins, at this point he has no resources started therefore this won't be working for him and when the resource starts it would be too late to trigger the event onPlayerJoin because the player did not just join.

To sum up, and I'm not quite sure as I mentioned above, onPlayerJoin can be only triggered when the resource was already started, so for instance to use onPlayerJoin we trigger this event to affect an already exisiting player by the joining of another player while we can't affect the joining player.

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...