I am coding a gamemode for gmod. It is a simple teamdeathmatch gamemode with some custom content.
This is my first time scripting in lua so please excuse me if its a really obvious solution but anyway.
I create a local variable named cageFfa and set it to a convar set when you start the server.
Later in the code I send it to players so they know which menus to show and what teams to join.
BUT around the time I started using timers to keep track of the time left in the round, it started acting really weird.
When i first set it it would always be "true" or "false", in this case I have it set to "false", now just after the GM:Initialize() call
it changes to something like "function: 0x21d006d8". Even more confusing is after sending it to the client the client thinks its "true"
when its "false". Code for init.lua and cl_init.lua
init.lua:
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "cl_hud.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
-----------------------------------------------
local cageFfa = GetConVar( "cage_ffa" ):GetBool()
print (cageFfa) -- Prints "false"
local cageFrag = GetConVar( "cage_maxfrags" ):GetFloat()
local cageMapTime = GetConVar( "cage_maptime" ):GetFloat()
function mapTimerEnd()
end
function GM:Initialize()
print (cageFfa ) -- Prints "function: 0x00SOMETHING"
timer.Create( "mapTimer", cageMapTime, 1, mapTimerEnd )
end
function GM:PlayerInitialSpawn( ply )
ply:SetModel( "models/player/kleiner.mdl" )
sendConvars(ply,cageFfa,cageFrag,timer.TimeLeft( "mapTimer" ))
ply:ConCommand( "cage_teammenu" )
end
function sendConvars( ply, ffa, frag, timer )
umsg.Start( "sendConvars", ply );
umsg.Bool( ffa );
umsg.Float( frag );
umsg.Long( timer );
umsg.End();
end
function GM:PlayerLoadout( ply )
if ply:Team() == 0 then
ply:KillSilent()
end
ply:StripWeapons()
ply:SetMaxSpeed(350)
ply:SetRunSpeed(500)
ply:SetCrouchedWalkSpeed(280)
ply:Give("weapon_crowbar")
ply:Give("weapon_pistol")
ply:Give("weapon_smg1")
ply:GiveAmmo(9999, "Pistol", true)
ply:GiveAmmo(9999, "SMG1", true)
if ply:Team() == 1 then
ply:SetPlayerColor( Vector(255,0,0,255) )
elseif ply:Team() == 2 then
ply:SetPlayerColor( Vector(0,0,255,255) )
elseif ply:Team() == 3 then
ply:SetPlayerColor( Vector(255,255,255,255) )
end
end
function GM:PlayerShouldTakeDamage( victim, pl )
if pl:IsPlayer() then
if( pl:Team() == victim:Team() and GetConVarNumber( "cage_teamdamage" ) == 0 ) and pl != victim and cageffa == false then
return false
end
end
return true
end
-----------------------------------------------
function cageRed( ply )
if cageFfa == false then
ply:SetTeam( 1 )
ply:KillSilent()
end
end
function cageBlue( ply )
if cageFfa == false then
ply:SetTeam( 2 )
ply:KillSilent()
end
end
function cageFfa( ply )
if cageffa == true then
ply:SetTeam( 3 )
ply:KillSilent()
end
end
concommand.Add( "cage_redteam", cageRed )
concommand.Add( "cage_blueteam", cageBlue )
concommand.Add( "cage_ffateam", cageFfa )[/CODE]
cl_init.lua:
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "cl_hud.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
-----------------------------------------------
local cageFfa = GetConVar( "cage_ffa" ):GetBool()
print (cageFfa) -- Prints "false"
local cageFrag = GetConVar( "cage_maxfrags" ):GetFloat()
local cageMapTime = GetConVar( "cage_maptime" ):GetFloat()
function mapTimerEnd()
end
function GM:Initialize()
print (cageFfa ) -- Prints "function: 0x00SOMETHING"
timer.Create( "mapTimer", cageMapTime, 1, mapTimerEnd )
end
function GM:PlayerInitialSpawn( ply )
ply:SetModel( "models/player/kleiner.mdl" )
sendConvars(ply,cageFfa,cageFrag,timer.TimeLeft( "mapTimer" ))
ply:ConCommand( "cage_teammenu" )
end
function sendConvars( ply, ffa, frag, timer )
umsg.Start( "sendConvars", ply );
umsg.Bool( ffa );
umsg.Float( frag );
umsg.Long( timer );
umsg.End();
end
function GM:PlayerLoadout( ply )
if ply:Team() == 0 then
ply:KillSilent()
end
ply:StripWeapons()
ply:SetMaxSpeed(350)
ply:SetRunSpeed(500)
ply:SetCrouchedWalkSpeed(280)
ply:Give("weapon_crowbar")
ply:Give("weapon_pistol")
ply:Give("weapon_smg1")
ply:GiveAmmo(9999, "Pistol", true)
ply:GiveAmmo(9999, "SMG1", true)
if ply:Team() == 1 then
ply:SetPlayerColor( Vector(255,0,0,255) )
elseif ply:Team() == 2 then
ply:SetPlayerColor( Vector(0,0,255,255) )
elseif ply:Team() == 3 then
ply:SetPlayerColor( Vector(255,255,255,255) )
end
end
function GM:PlayerShouldTakeDamage( victim, pl )
if pl:IsPlayer() then
if( pl:Team() == victim:Team() and GetConVarNumber( "cage_teamdamage" ) == 0 ) and pl != victim and cageffa == false then
return false
end
end
return true
end
-----------------------------------------------
function cageRed( ply )
if cageFfa == false then
ply:SetTeam( 1 )
ply:KillSilent()
end
end
function cageBlue( ply )
if cageFfa == false then
ply:SetTeam( 2 )
ply:KillSilent()
end
end
function cageFfa( ply )
if cageffa == true then
ply:SetTeam( 3 )
ply:KillSilent()
end
end
concommand.Add( "cage_redteam", cageRed )
concommand.Add( "cage_blueteam", cageBlue )
concommand.Add( "cage_ffateam", cageFfa )[/CODE]
[QUOTE=Jackyminer;50999628][code]function cageFfa( ply )
if cageffa == true then
ply:SetTeam( 3 )
ply:KillSilent()
end
end[/CODE][/QUOTE]
this is the same as doing [code]cageFfa = function(ply)[/code]
oh XD THX
Sorry, you need to Log In to post a reply to this thread.