CreateTeams not running clientside, or include() not working?
4 replies, posted
Okay. This problem is pretty random.
So, I have a file called "cl_hud.lua" in my gamemode. It's AddCSLuaFile'd on the server and on the client it's include'd after shared.lua (which should create the teams, as I have CreateTeams defined)
However, with this code in cl_hud.lua, I get errors spammed in my console:
[lua]function hud.DrawText( fonttouse, col, x, y, text )
x = x + 1
y = y + 1
surface.SetFont( fonttouse ) -- set the font to draw
surface.SetTextColor( col.r, col.g, col.b, col.a ) -- set the colour to draw
surface.SetTextPos( x, y ) -- set the position of the text
surface.DrawText( text ) -- draw the text
end
-- in HUDPaint:
hud.DrawText( font, team.GetColor( me:Team() ), ScrW() / 15, ScrH() / 1.4, "Team: "..team.GetAllTeams(me:Team()).Name )
[/lua]
The errors:
[lua][ERROR] addons/battle_gamemode/gamemodes/battle/gamemode/cl_hud.lua:134: attempt to concatenate field 'Name' (a nil value)
1. unknown - addons/battle_gamemode/gamemodes/battle/gamemode/cl_hud.lua:134
[/lua]
After doing some simple debugging, CreateTeams seems to be called only serverside, but shared.lua is being included clientside.
createteams:
[lua]BATTLE_TEAM_NONE = 1
BATTLE_TEAM_COMBINE = 2
BATTLE_TEAM_REBELS = 3
BATTLE_TEAMCOLOUR_1 = Color( 255, 255, 255, 255 )
BATTLE_TEAMCOLOUR_2 = Color( 0, 0, 200 )
BATTLE_TEAMCOLOUR_3 = Color( 200, 0, 0 )
function GM:CreateTeams()
print("run!")
team.SetUp( BATTLE_TEAM_NONE, "None", BATTLE_TEAMCOLOUR_1 )
team.SetUp( BATTLE_TEAM_COMBINE, "Combine", BATTLE_TEAMCOLOUR_2 )
team.SetSpawnPoint( BATTLE_TEAM_COMBINE, { "info_player_counterterrorist", "info_player_combine" } )
team.SetUp( BATTLE_TEAM_REBELS, "Rebels", BATTLE_TEAMCOLOUR_3 )
team.SetSpawnPoint( BATTLE_TEAM_REBELS, { "info_player_terrorist", "info_player_rebel" } )
end[/lua]
(don't forget that shared.lua is AddCSLuaFiled'd like it should be, too)
What is going on?!
Does it error only a few times when joining, or every frame?
[QUOTE=Robotboy655;49204828]Does it error only a few times when joining, or every frame?[/QUOTE]
Every frame.
You should be using [url]http://wiki.garrysmod.com/page/team/GetName[/url] over what you have and do print(me:Team() ) and see what ID it gives you.
[editline]28th November 2015[/editline]
[url]http://wiki.garrysmod.com/page/team/GetAllTeams[/url]
You have got to be kidding me. Did you even try looking what the function actually does, what it takes?
[QUOTE=Robotboy655;49204947]You should be using [url]http://wiki.garrysmod.com/page/team/GetName[/url] over what you have and do print(me:Team() ) and see what ID it gives you.
[editline]28th November 2015[/editline]
[url]http://wiki.garrysmod.com/page/team/GetAllTeams[/url]
You have got to be kidding me. Did you even try looking what the function actually does, what it takes?[/QUOTE]
Oh god, shit :v:... I accidentally put it like team.GetAllTeams(teamid) instead of team.GetAllTeams()[teamid]. Sorry :v:
Sorry, you need to Log In to post a reply to this thread.