Need help with init.lua (new gamemode)

I seem to get an error but I’m not sure where it is. I probably use something I shouldn’t use/do.

[lua] function GM:InitPostEntity()
Entity=ents.Create(“spawnred1”)
Entity:SetPos(Vector(-336, -120, 424))
Entity:Spawn()
Entity2=ents.Create(“spawnblue1”)
Entity2:SetPos(Vector(3249, -3280, 584))
Entity2:Spawn()
end
end

function GM:PlayerSelectSpawn( pl )
if (pl:Team() == 0) then
local spawns = ents.FindByClass( “spawnblue1” )
local random_entry = math.random( #spawns )

return spawns[ random_entry ]
elseif (pl:Team() == 1) then
local spawns = ents.FindByClass( “spawnred1” )
local random_entry = math.random( #spawns )
return spawns[ random_entry ]
end
end[/lua]

You are having two "end"s closing the first function. Also, learn to indent your code right at the beginning!



function GM:InitPostEntity()
    entity1 = ents.Create("spawnred1")
    entity1:SetPos(Vector(-336, -120, 424))
    entity1:Spawn()
    
    entity2=ents.Create("spawnblue1")
    entity2:SetPos(Vector(3249, -3280, 584))
    entity2:Spawn()
end

function GM:PlayerSelectSpawn(pl)
    if (pl:Team() == 0) then
        local spawns = ents.FindByClass("spawnblue1")
        local random_entry = math.random(#spawns)

        return spawns[random_entry]    
    elseif (pl:Team() == 1) then 
        local spawns = ents.FindByClass("spawnred1")
        local random_entry = math.random(#spawns)
        return spawns[random_entry]
    end
end


Also, Entity capitalised is a built-in class, so you should not be using that name for a variable you created.

ok Thanks though. Is there any round system for free around here? It was hard enough to code this part xD. Like 10 rounds, each round 2 minutes. I have no clue where to start…

I found some basic round file:
[editline]27th August 2015[/editline]

[lua] round = {}

– Variables
round.Break = 30 – 30 second breaks
round.Time = 300 – 5 minute rounds

– Read Variables
round.TimeLeft = -1
round.Breaking = false

function round.Broadcast(Text)
for k, v in pairs(player.GetAll()) do
v:ConCommand(“play buttons/button17.wav”)
v:ChatPrint(Text)
end
end

function round.Begin()
– Your code
– (Anything that may need to happen when the round begins)

round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
round.TimeLeft = round.Time

end

function round.End()
– Your code
– (Anything that may need to happen when the round ends)

round.Broadcast("Round over! Next round in " .. round.Break .. " seconds!")
round.TimeLeft = round.Break

end

function round.Handle()
if (round.TimeLeft == -1) then – Start the first round
round.Begin()
return
end

round.TimeLeft = round.TimeLeft - 1

if (round.TimeLeft == 0) then
	if (round.Breaking) then
		round.Begin()
		round.Breaking = false
	else
		round.End()
		round.Breaking = true
	end
end

end
timer.Create(“round.Handle”, 1, 0, round.Handle)[/lua]

I would need some help in:

I want the round to begin when there’s atleast TWO players on. (1v1). I want the round to last 3 minutes. at the start(round.start I want all people to spawn at their spawn (I made new spawn location for the two teams I got, (red and blue) TEAM 1 and 0.

Here is a very basic way of doing this. There are better ways, but this will work for now.


round = {}

-- Variables
round.Break	= 30	-- 30 second breaks
round.Time	= 300	-- 5 minute rounds

-- Read Variables
round.TimeLeft = -1
round.Breaking = false

local alivePlayers = 0 --the variable for the amount of alive players

function round.Broadcast(Text)
	for k, v in pairs(player.GetAll()) do
		v:ConCommand("play buttons/button17.wav")
		v:ChatPrint(Text)
	end
end

function round.Begin()
	-- Your code
	-- (Anything that may need to happen when the round begins)
	
	round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
	round.TimeLeft = round.Time
end

function round.End()
	-- Your code
	-- (Anything that may need to happen when the round ends)
	
	round.Broadcast("Round over! Next round in " .. round.Break .. " seconds!")
	round.TimeLeft = round.Break
end

function round.Handle()
	if (round.TimeLeft == -1) then -- Start the first round
		if alivePlayers >= 2 then  --if the alive players are greater than or equal to 2
			round.Begin()	--let the round begin 
			return
		end
	end
	
	round.TimeLeft = round.TimeLeft - 1
	
	if (round.TimeLeft == 0) then
		if (round.Breaking) && alivePlayers >= 2 then --Check if the alive players are 2 or more 
			round.Begin()
			round.Breaking = false
		else
			round.End()
			round.Breaking = true
		end
	end
end
timer.Create("round.Handle", 1, 0, round.Handle)


--creates the function to check the amount of alive players
local function AlivePlayers()
	for k,v in pairs(player.GetAll()) do --this will get all of the players
		if v:Alive() then		--checks if they are alive or bot
			alivePlayers = alivePlayers + 1		--if they are alive then add to the amount of alive players
		end
	end
	return alivePlayers --this will return the number of alive players
end

-- you may edit this to your liking
hook.Add("PlayerDeath", "checkAlivePlayers", function()
	if AlivePlayers() <= 1 then --checks if the amount of alive players is less than or equal to 1
		round.End()		--if the amount of alive players is less than or equal to 1, make the round end.
	end
end)

Please note this is incomplete so that you will need to do some scripting. But it should give you and idea of how it works.