Am I putting these variables in the right function??

Hey I just need a pointer tell let me know if im putting the variables in the right functions. Thanks :slight_smile: ( not 100% because of the Garrys Mod 13 changes )



AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
 
include( 'shared.lua' )

function GM:PlayerSpawn( ply )
    self.BaseClass:PlayerSpawn( ply )   
 
    ply:SetGravity  ( 1 )  
    ply:SetMaxHealth( 100, true )  
    ply:SetWalkSpeed( 190 )  
    ply:SetRunSpeed ( 235 ) 
	ply:SetTeam( 3 )

//Setting Team Models
if ply:Team() == 1 then
	ply:SetModel("models/player/male03.mdl")
elseif ply:Team() == 2 then
	ply:SetModel("models/player/male02.mdl")
elseif ply:Team() == 3 then
	--Dont know what I want him to do?
end

//Evening Teams
local VTGG == math.random( 1, 2 )
	if VTGG == 1 then
		ply:SetTeam( 1 )
	elseif VTGG == 2 then
		ply:SetTeam( 2 )
end
GAN = team.NumPlayers ( 1 ) -- Do we need that long variable?
WHI = team.NumPlayers ( 2 ) -- Do we need that long variable?
	if GAN > WHI them
		ply:SetTeam( 2 )
	elseif WHI > GAN
		ply:SetTeam( 1 )
	end
end


function GM:PlayerInitialSpawn( ply )
	   ply:PrintMessage( HUD_PRINTTALK, "Welcome, " .. ply:Name() .. "!" )
end


And this is the init.lua

include( ‘shared.lua’ )
include( “shared.lua” ) ?

Your indents are fucked but as far as I can see everything looks good.

Why are my indents fucked :stuck_out_tongue: I like organization :stuck_out_tongue:

[editline]26th August 2014[/editline]

Does it matter? I thought it really didnt yet i could be wrong :stuck_out_tongue:

For the evening teams part there are some mistakes, I personally would group that check into one.


local VTGG = math.random( 1, 2 )
local GAN = team.NumPlayers( 1 )
local WHI = team.NumPlayers( 2 )

if GAN > WHI then
	ply:SetTeam( 2 )
elseif WHI > GAN then
	ply:SetTeam( 1 )
elseif WHI == GAN then
	ply:SetTeam( VTGG )
end

Take a look and if you don’t get the differences just shout.

So what im looking at if WHI = GAN then it will put it in another random team? I wanted to try and keep teams even. Unless your aware, then can you explain what the changes will do? :slight_smile: Thanks for spotting that out tho :slight_smile:

Here’s an error from before:

If you’re defining a variable it’s a single ‘=’.

The reason why I did that is, your script first puts people into randomly selected teams, then checks for imbalances and reassigns again. Whereas, in mine it checks for imbalances and if there is it will put you in the team with less, however if there isn’t a stacked side it will randomly put you a team…

Ahh ok thats very useful :slight_smile: thanks :slight_smile: I understand your logic :slight_smile: So just some im receiving it right. Lets do example. ( My code ) 1. Player Joins 2. Randomly puts in team. 3. Sees’ if there is imbalances. 4. If so changes team… ( Your code ) 1. Player Joins 2. Places team that is < than the other.