Jump to content

spawn system


Recommended Posts

hi guys i made this script for players who join the server for the FIRST time but i have  a problem 
i want the players who didnt spawn yet be frozen 
any idea
 


local randomSpawnTable =
{
    { 152.24,-2090,702 },
    { 152.24,-2090,702 },
    { 152.24,-2090,702 }
}
 
function randomSpawn( thePlayer, randomSpawnTable )
    local random = math.random( 1, #randomSpawnTable )
    spawnPlayer(
	thePlayer,
        randomSpawnTable[random][1],
        randomSpawnTable[random][2],
        randomSpawnTable[random][3],
        randomSpawnTable[random][4]
    )

	setElementModel ( thePlayer, 312 )
	giveWeapon ( thePlayer, 46 )
	giveWeapon ( thePlayer, 9 )
	giveWeapon ( thePlayer, 25, 5000 ,true )
	giveWeapon ( thePlayer, 28, 5000 ,true )
	giveWeapon ( thePlayer, 31, 5000 ,true )
	giveWeapon ( thePlayer, 22, 5000 ,true )

end


 
function onPlayerJoin()
	fadeCamera( source, true )
   	setCameraTarget( source, source  )
    	randomSpawn( source, randomSpawnTable  )

end
addEventHandler( "onPlayerJoin",root, onPlayerJoin )
 

 

Link to comment

Hi, first off you're trying to get the 4th value of randomSpawnTable which doesn't exist (randomSpawnTable[random][4])?

Second, to actually know if a player is joining for the first time or not, I'd suggest you store every player's serial key once they join in XML file or SQL table (your choice). That way you can loop through the XML file or SQL table in the onPlayerJoin function and if no serial matches his own then use setElementFrozen.

Edited by Hale
Link to comment

no i want all the players who join the server be frozen and when they login they can move

local randomSpawnTable =
{
    { 152.24,-2090,702 },
    { 152.24,-2090,702 },
    { 152.24,-2090,702 }
}
 
function randomSpawn( thePlayer, randomSpawnTable )
    local random = math.random( 1, #randomSpawnTable )
    spawnPlayer(
    thePlayer,
        randomSpawnTable[random][1],
        randomSpawnTable[random][2],
        randomSpawnTable[random][3],
        randomSpawnTable[random][4]
    )

    setElementModel ( thePlayer, 312 )
    giveWeapon ( thePlayer, 46 )
    giveWeapon ( thePlayer, 9 )
    giveWeapon ( thePlayer, 25, 5000 ,true )
    giveWeapon ( thePlayer, 28, 5000 ,true )
    giveWeapon ( thePlayer, 31, 5000 ,true )
    giveWeapon ( thePlayer, 22, 5000 ,true )

end


 
function onPlayerJoin()
    fadeCamera( source, true )
    setElementFrozen ( source, true )
       setCameraTarget( source, source  )
        randomSpawn( source, randomSpawnTable  )

end
addEventHandler( "onPlayerJoin",root, onPlayerJoin )


function onPlayerLogin()
    setElementFrozen ( source, false )

end
addEventHandler( "onPlayerLogin",root, onPlayerLogin )

 

Link to comment

local randomSpawnTable =
{
    { 152.24,-2090,702 },
    { 152.24,-2090,702 },
    { 152.24,-2090,702 }
}
 
function randomSpawn( thePlayer, randomSpawnTable )
    local random = math.random( 1, #randomSpawnTable )
    spawnPlayer(
	thePlayer,
        randomSpawnTable[random][1],
        randomSpawnTable[random][2],
        randomSpawnTable[random][3]
    )

	setElementModel ( thePlayer, 312 )
	giveWeapon ( thePlayer, 46 )
	giveWeapon ( thePlayer, 9 )
	giveWeapon ( thePlayer, 25, 5000 ,true )
	giveWeapon ( thePlayer, 28, 5000 ,true )
	giveWeapon ( thePlayer, 31, 5000 ,true )
	giveWeapon ( thePlayer, 22, 5000 ,true )

end


 
function onPlayerJoin()
	fadeCamera( source, true )
	setElementFrozen ( source, true )
   	setCameraTarget( source, source  )
    	randomSpawn( source, randomSpawnTable  )

end
addEventHandler( "onPlayerJoin",root, onPlayerJoin )


function onPlayerLogin()
	setElementFrozen ( source, false )

end
addEventHandler( "onPlayerLogin",root, onPlayerLogin )
 

not working yet

Link to comment

Try this, maybe @StormFighter is right about the player not being created so early.

function onPlayerJoin()
	setTimer(function(source)
		fadeCamera(source, true)
		setElementFrozen(source, true)
		setCameraTarget(source, source)
		randomSpawn(source, randomSpawnTable)
	end, 1000, 1, source)
end
addEventHandler("onPlayerJoin", root, onPlayerJoin)

function onPlayerLogin()
	setElementFrozen(source, false)
end
addEventHandler("onPlayerLogin", root, onPlayerLogin)

Experiment with the timer's duration a bit, if this^ does nothing, try setting it from 1000ms to 10000ms (from 1second to 10 seconds) just to see if it will do anything when the player has for sure been created.

Edited by koragg
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...