Jump to content

spawn when the map start?


Recommended Posts

hi, i have a problem :/ i create a simple deathmatch gamemode whit maps files and its work perfectly, but when the server has no start the gamemode

and use /votemap deathmatch and i choice one but the screen still black and use /reconnect and spawn perfectly.

how i can fix that?

  
function loadMap(startedMap, player) 
  
        mapRoot = getResourceRootElement(startedMap) 
        setTimer(joinHandler,1000,1,player) 
end 
addEventHandler("onGamemodeMapStart", dm_root, loadMap) 
  

function joinHandler() 
local total_spawns = getElementChildrenCount( getElementByID( "spawns" ) ) 
local num = math.random( 0, total_spawns - 1 ) 
local spawn_random = getElementChild ( getElementByID( "spawns" ), num ) 
local x = getElementData ( spawn_random, "posX" ) 
local y = getElementData ( spawn_random, "posY" ) 
local z = getElementData ( spawn_random, "posZ" ) 
local rot = getElementData ( spawn_random, "rot" ) 
  
        spawnPlayer(source, x, y, z, rot) 
        setCameraTarget ( source, source ) 
        fadeCamera(source, true) 
        giveWeapon(source, 22, 999) 
        giveWeapon(source, 4, 1) 
end 
addEventHandler("onPlayerJoin", dm_root, joinHandler) 

thx bye (.

Link to comment
yes i tryed this but only get warnings :/ i need a code for spawn all players in the server but i dont know how i can make this.

bye y thx for the reply (.

To spawn everyone you have to loop through all the player elements, like so:

local plrs = getElementsByType( "player" ); 
for i, plr in pairs( plrs ) do 
        spawnPlayer( plr, x, y, z, rot ); 
        setCameraTarget ( plr, plr ); 
        fadeCamera( plr, true ); 
        giveWeapon( plr, 22, 999 ); 
        giveWeapon( plr, 4, 1 ); 
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...