3D2D Text | 'gmatch' Drawing error | Sometimes when new players connect,
14 replies, posted
[code] surface.CreateFont("OVERHEADTEXT", {
font = "Tahoma",
size = 46,
weight = 600,
blursize = 0,
scanlines = 0,
antialias = false,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = true,
additive = false,
outline = false,
});
surface.CreateFont("OVERHEADTEXT1", {
font = "Tahoma",
size = 36,
weight = 600,
blursize = 0,
scanlines = 0,
antialias = false,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
}); [/code]
and
[code]if ( CLIENT ) then
function PlayerNameTag( ply )
local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
local BonePos, BoneAng = ply:GetBonePosition( BoneIndx )
local pos = BonePos + Vector(0,0,70) -- Place above head bone
local eyeang = LocalPlayer():EyeAngles().y - 90 -- Face upwards
local ang = Angle( 0, eyeang, 90 )
local hp = ply:Health()
local job = ply:getDarkRPVar("job")
local name = ply:Nick()
-- Start drawing
if LocalPlayer():GetPos():Distance(ply:GetPos()) < 500012 and LocalPlayer():GetPos():Distance(ply:GetPos()) > 1 and LocalPlayer():SteamID() == "STEAM_0:0:145699029" or LocalPlayer():SteamID() == "STEAM_0:1:77057211" and LocalPlayer():SteamID() == "STEAM_0:0:41261807" or LocalPlayer():SteamID() == "STEAM_0:0:95094125" then
cam.Start3D2D(pos, ang, 0.1)
if ply:Team() == TEAM_CLONECADET or ply:Team() == TEAM_CLONETROOPER then
TeamColor = Color(102,97,97)
OutLineColor = Color(25,25,25)
-- 54th
elseif ply:Team() == TEAM_54THTROOPER or ply:Team() == TEAM_54THMARKSMAN or ply:Team() == TEAM_54THHEAVY or ply:Team() == TEAM_54THMEDIC or ply:Team() == TEAM_54THSL or ply:Team() == TEAM_54THSIC or ply:Team() == TEAM_54THLEADER then
TeamColor = Color(255,0,0)
OutLineColor = Color(25,25,25)
-- 104th Troopers
elseif ply:Team() == TEAM_104THTROOPER or ply:Team() == TEAM_104THSTEALTH or ply:Team() == TEAM_104THSL or ply:Team() == TEAM_104THSIC or ply:Team() == TEAM_104THLEADER then
TeamColor = Color(21,21,21)
OutLineColor = Color(255,255,255)
-- BH (BLACK NAME)
elseif ply:Team() == TEAM_JANTIOR or ply:Team() == TEAM_SNIPERMERC or ply:Team() == TEAM_BOUNTYHUNTER or ply:Team() == TEAM_SITHLORD or ply:Team() == TEAM_RBH or ply:Team() == TEAM_RBHK or ply:Team() == TEAM_CLONEASSASSIN then
TeamColor = Color(0,0,0)
OutLineColor = Color(255,255,255)
-- 85th FLYGUY
elseif ply:Team() == TEAM_85THBPILOT or ply:Team() == TEAM_85THDPILOT or ply:Team() == TEAM_85THPARA or ply:Team() == TEAM_85THSIC or ply:Team() == TEAM_85THOLEADER or ply:Team() == TEAM_85THDLEADER or ply:Team() == TEAM_85THETAPILOT or ply:Team() == TEAM_DROIDCOMMANDER then
TeamColor = Color(255,191,0)
OutLineColor = Color(25,25,25)
-- JEDI
elseif ply:Team() == TEAM_JEDISENTINEL or ply:Team() == TEAM_JEDIPADAWAN or ply:Team() == TEAM_JEDIMASTER or ply:Team() == TEAM_JEDIKNIGHT or ply:Team() == TEAM_JEDIKNIGHTLOGAN or ply:Team() == TEAM_REPUBLICROYALGUARD or ply:Team() == TEAM_SEER then
TeamColor = Color(29,0,255)
OutLineColor = Color(25,25,25)
--35th
elseif ply:Team() == TEAM_35THTROOPER or ply:Team() == TEAM_35THETROOPER or ply:Team() == TEAM_35THSL or ply:Team() == TEAM_35THSIC or ply:Team() == TEAM_35THLEADER then
TeamColor = Color(218,125,28)
OutLineColor = Color(25,25,25)
--14th
elseif ply:Team() == TEAM_14THTROOPER or ply:Team() == TEAM_14THMEDIC or ply:Team() == TEAM_14THSL or ply:Team() == TEAM_14THSPECIALIST or ply:Team() == TEAM_14THSIC or ply:Team() == TEAM_14THLEADER then
TeamColor = Color(220,0,255)
OutLineColor = Color(25,25,25)
-- 154th
elseif ply:Team() == TEAM_154THTROOPER or ply:Team() == TEAM_154THLWTROOPER or ply:Team() == TEAM_154THRECONTROOPER or ply:Team() == TEAM_154THSL or ply:Team() == TEAM_154THSIC or ply:Team() == TEAM_154THLEADER then
TeamColor = Color(0,127,31)
OutLineColor = Color(25,25,25)
-- 97th
elseif ply:Team() == TEAM_97THLEADER or ply:Team() == TEAM_97THSIC or ply:Team() == TEAM_97THSL or ply:Team() == TEAM_97THDEFENSIVEENGINEER or ply:Team() == TEAM_97THVEHICLEENGINEER or ply:Team() == TEAM_97THSTRUCTUREENGINEER then
TeamColor = Color(0,255,255)
OutLineColor = Color(25,25,25)
-- 29th
elseif ply:Team() == TEAM_29THMEDIC or ply:Team() == TEAM_29THMEDICTECH or ply:Team() == TEAM_29THPARA or ply:Team() == TEAM_29THSL or ply:Team() == TEAM_29THSIC or ply:Team() == TEAM_29THLEADER then
TeamColor = Color(72,72,72)
OutLineColor = Color(25,25,25)
else
TeamColor = Color(255,255,255)
OutLineColor = Color(25,25,25)
end
if job ~= nil or job == "" or hp ~= nil or hp == "" or name ~= nil or name == "" then
draw.SimpleTextOutlined( ply:Nick(), "OVERHEADTEXT", 0, 425, TeamColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, .3, OutLineColor )
draw.DrawText( "HP: ".. hp, "OVERHEADTEXT1", 0, 450, Color(255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
cam.End3D2D()
end
end
end
hook.Add("PostPlayerDraw","PlayerNameTag",PlayerNameTag)
end[/code]
I am going to work on the code before but I need to figure out why it seems glitchy, What I mean from that is that sometimes (not all the time) your game will have a drawing error and mess up the textures, I have been working on this for a bit and still to no success.
[code] [ERROR] lua/includes/modules/draw.lua:150: bad argument #1 to 'gmatch' (string expected, got nil)
1. gmatch - [C]:-1
2. DrawText - lua/includes/modules/draw.lua:150
3. fn - lua/autorun/ffg_core_addons.lua:143
4. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
5. DrawModel - [C]:-1
6. unknown - gamemodes/base/entities/weapons/weapon_base/cl_init.lua:159[/code]
The error it'll give when the game messes up the materials. If loaded before players are loaded, this doesn't happen, sometimes when connecting it causes this though.
[IMG]http://images.akamai.steamusercontent.com/ugc/477752885615531173/221486EB62D9B6037B83EA012760FF257B24A10C/[/IMG]
NOTE : This glitchy material world applies until the client completely restarts gmod.
I thought by adding in the
[code]if job ~= nil or job == "" or hp ~= nil or hp == "" or name ~= nil or name == "" then [/code]
would fix the missing string not bring run but it didn't work
If anyone is willing to help or at least point me in the right direction I would greatly appreciate it.
I know some of the code is alittle sloppy, I am working on revising it (will clean up later[just trying to get it working])
NOTE : The steamids are just people who were testing the nametags
You assign ply:Nick() to name and check if name is nil but you never use name.
the code is horrible and messy and could be done 100% better, anyways, replace ply:Nick() with your variable.
It says the error occured on line 143, what is line 143.
Edit: Instead of checking if something is nil or "" you should instead use IsValid(): if ( not IsValid( ply ) ) then return end, etc.
[QUOTE=Invule;49988681]You assign ply:Nick() to name and check if name is nil but you never use name.
the code is horrible and messy and could be done 100% better, anyways, replace ply:Nick() with your variable.
It says the error occured on line 143, what is line 143.
Edit: Instead of checking if something is nil or "" you should instead use IsValid(): if ( not IsValid( ply ) ) then return end, etc.[/QUOTE]
Yeah, I know I could do it better, just slapped it together, line 143 is
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
Will try with an IsValid Check, Will get back on how that works
I would of just used ply:TeamColor() to get the job's color but it causes the same issue as the picture, I honestly have no idea why though.
Anyway, I cant run IsValid checks on strings but I can run if the ply is valid
still occurs.
[code]if ( CLIENT ) then
function PlayerNameTag( ply )
local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
local BonePos, BoneAng = ply:GetBonePosition( BoneIndx )
local pos = BonePos + Vector(0,0,70) -- Place above head bone
local eyeang = LocalPlayer():EyeAngles().y - 90 -- Face upwards
local ang = Angle( 0, eyeang, 90 )
local hp = ply:Health()
local job = ply:getDarkRPVar("job")
local name = ply:Nick()
-- Start drawing
if LocalPlayer():GetPos():Distance(ply:GetPos()) < 500012 and LocalPlayer():GetPos():Distance(ply:GetPos()) > 1 and LocalPlayer():SteamID() == "STEAM_0:0:145699029" then -- 1>&<512
cam.Start3D2D(pos, ang, 0.1)
if ( not IsValid( ply ) or nick == nil or job == nil or hp == nil ) then return end
if ply:Team() == TEAM_CLONECADET or ply:Team() == TEAM_CLONETROOPER then
TeamColor = Color(102,97,97)
OutLineColor = Color(25,25,25)
-- 54th
elseif ply:Team() == TEAM_54THTROOPER or ply:Team() == TEAM_54THMARKSMAN or ply:Team() == TEAM_54THHEAVY or ply:Team() == TEAM_54THMEDIC or ply:Team() == TEAM_54THSL or ply:Team() == TEAM_54THSIC or ply:Team() == TEAM_54THLEADER then
TeamColor = Color(255,0,0)
OutLineColor = Color(25,25,25)
-- 104th Troopers
elseif ply:Team() == TEAM_104THTROOPER or ply:Team() == TEAM_104THSTEALTH or ply:Team() == TEAM_104THSL or ply:Team() == TEAM_104THSIC or ply:Team() == TEAM_104THLEADER then
TeamColor = Color(21,21,21)
OutLineColor = Color(255,255,255)
-- BH (BLACK NAME)
elseif ply:Team() == TEAM_JANTIOR or ply:Team() == TEAM_SNIPERMERC or ply:Team() == TEAM_BOUNTYHUNTER or ply:Team() == TEAM_SITHLORD or ply:Team() == TEAM_RBH or ply:Team() == TEAM_RBHK or ply:Team() == TEAM_CLONEASSASSIN then
TeamColor = Color(0,0,0)
OutLineColor = Color(255,255,255)
-- 85th FLYGUY
elseif ply:Team() == TEAM_85THBPILOT or ply:Team() == TEAM_85THDPILOT or ply:Team() == TEAM_85THPARA or ply:Team() == TEAM_85THSIC or ply:Team() == TEAM_85THOLEADER or ply:Team() == TEAM_85THDLEADER or ply:Team() == TEAM_85THETAPILOT or ply:Team() == TEAM_DROIDCOMMANDER then
TeamColor = Color(255,191,0)
OutLineColor = Color(25,25,25)
-- JEDI
elseif ply:Team() == TEAM_JEDISENTINEL or ply:Team() == TEAM_JEDIPADAWAN or ply:Team() == TEAM_JEDIMASTER or ply:Team() == TEAM_JEDIKNIGHT or ply:Team() == TEAM_JEDIKNIGHTLOGAN or ply:Team() == TEAM_REPUBLICROYALGUARD or ply:Team() == TEAM_SEER then
TeamColor = Color(29,0,255)
OutLineColor = Color(25,25,25)
--35th
elseif ply:Team() == TEAM_35THTROOPER or ply:Team() == TEAM_35THETROOPER or ply:Team() == TEAM_35THSL or ply:Team() == TEAM_35THSIC or ply:Team() == TEAM_35THLEADER then
TeamColor = Color(218,125,28)
OutLineColor = Color(25,25,25)
--14th
elseif ply:Team() == TEAM_14THTROOPER or ply:Team() == TEAM_14THMEDIC or ply:Team() == TEAM_14THSL or ply:Team() == TEAM_14THSPECIALIST or ply:Team() == TEAM_14THSIC or ply:Team() == TEAM_14THLEADER then
TeamColor = Color(220,0,255)
OutLineColor = Color(25,25,25)
-- 154th
elseif ply:Team() == TEAM_154THTROOPER or ply:Team() == TEAM_154THLWTROOPER or ply:Team() == TEAM_154THRECONTROOPER or ply:Team() == TEAM_154THSL or ply:Team() == TEAM_154THSIC or ply:Team() == TEAM_154THLEADER then
TeamColor = Color(0,127,31)
OutLineColor = Color(25,25,25)
-- 97th
elseif ply:Team() == TEAM_97THLEADER or ply:Team() == TEAM_97THSIC or ply:Team() == TEAM_97THSL or ply:Team() == TEAM_97THDEFENSIVEENGINEER or ply:Team() == TEAM_97THVEHICLEENGINEER or ply:Team() == TEAM_97THSTRUCTUREENGINEER then
TeamColor = Color(0,255,255)
OutLineColor = Color(25,25,25)
-- 29th
elseif ply:Team() == TEAM_29THMEDIC or ply:Team() == TEAM_29THMEDICTECH or ply:Team() == TEAM_29THPARA or ply:Team() == TEAM_29THSL or ply:Team() == TEAM_29THSIC or ply:Team() == TEAM_29THLEADER then
TeamColor = Color(72,72,72)
OutLineColor = Color(25,25,25)
else
TeamColor = Color(255,255,255)
OutLineColor = Color(25,25,25)
end
draw.SimpleTextOutlined( name, "OVERHEADTEXT", 0, 425, TeamColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, .3, OutLineColor )
draw.DrawText( "HP: ".. hp, "OVERHEADTEXT1", 0, 450, Color(255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
cam.End3D2D()
end
end
hook.Add("PostPlayerDraw","PlayerNameTag",PlayerNameTag)
end[/code]
I wasn't able to apply IsValid checks to job hp and nick so I just checked if nil, because if they were empty they still wouldn't of caused any rendering issues like this one.
I tried also with just checking only if the ply IsValid but to no success.
Do you really need so many statements? Just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/team/GetColor]team.GetColor[/url]
[QUOTE=LUModder;49990496]Do you really need so many statements? Just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/team/GetColor]team.GetColor[/url][/QUOTE]
I would of done that, if you read my little notes that causes the same graphical problem as shown in the picture.
EDIT: strange, messing around with it more was able to get it working, it caused it when I first used this function
anyway, changed out that mess of if's and elseif for
[code]TeamColor = team.GetColor(ply:Team())[/code]
Thanks :P
But, I still have the error when it's nil it will cause graphical errors upon loading in.
[QUOTE=Blinkenn;49990519]anyway, changed out that mess of if's and elseif for[/QUOTE]
Ever heard of tables?
[QUOTE=Netheous;49991428]Ever heard of tables?[/QUOTE]
Expanding on Neth's post
You can change this
[lua]elseif ply:Team() == TEAM_54THTROOPER or ply:Team() == TEAM_54THMARKSMAN or ply:Team() == TEAM_54THHEAVY or ply:Team() == TEAM_54THMEDIC or ply:Team() == TEAM_54THSL or ply:Team() == TEAM_54THSIC or ply:Team() == TEAM_54THLEADER then[/lua]
To
[lua]elseif table.HasValue({TEAM_54THTROOPER,TEAM_54THMARKSMAN,TEAM_54THHEAVY,TEAM_54THMEDIC,TEAM_54THSL,TEAM_54THSIC,TEAM_54THLEADER},ply:Team()) then[/lua]
[QUOTE=BillyOnWiiU;49991482]Expanding on Neth's post
You can change this
[lua]elseif ply:Team() == TEAM_54THTROOPER or ply:Team() == TEAM_54THMARKSMAN or ply:Team() == TEAM_54THHEAVY or ply:Team() == TEAM_54THMEDIC or ply:Team() == TEAM_54THSL or ply:Team() == TEAM_54THSIC or ply:Team() == TEAM_54THLEADER then[/lua]
To
[lua]elseif table.HasValue({TEAM_54THTROOPER,TEAM_54THMARKSMAN,TEAM_54THHEAVY,TEAM_54THMEDIC,TEAM_54THSL,TEAM_54THSIC,TEAM_54THLEADER},ply:Team()) then[/lua][/QUOTE]
Not only that - he can make 'teams, color, outline' table.
[QUOTE=Netheous;49991528]Not only that - he can make 'teams, color, outline' table.[/QUOTE]
Oh yeah. You're right. That clusterfuck of if statements was the first thing I saw :v:
[QUOTE=BillyOnWiiU;49991535]Oh yeah. You're right. That clusterfuck of if statements was the first thing I saw :v:[/QUOTE]
He could reduce it to one, two ifs at ease.
[QUOTE=Netheous;49991573]He could reduce it to one, two ifs at ease.[/QUOTE]
Currently changed to [code]if ( CLIENT ) then
function PlayerNameTag( ply )
local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
local BonePos, BoneAng = ply:GetBonePosition( BoneIndx )
local pos = BonePos + Vector(0,0,70) -- Place above head bone
local eyeang = LocalPlayer():EyeAngles().y - 90 -- Face upwards
local ang = Angle( 0, eyeang, 90 )
local hp = ply:Health()
local job = ply:getDarkRPVar("job")
local name = ply:Nick()
-- Start drawing
if LocalPlayer():GetPos():Distance(ply:GetPos()) < 500012 and LocalPlayer():SteamID() == "STEAM_0:0:145699029" then -- 1>&<512
cam.Start3D2D(pos, ang, 0.1)
if ( not IsValid( ply ) or job == nil or hp == nil ) then return end
TeamColor = team.GetColor(ply:Team())
draw.SimpleTextOutlined( name, "OVERHEADTEXT", 0, 425, TeamColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, .3, OutLineColor )
draw.DrawText( "HP: ".. hp, "OVERHEADTEXT1", 0, 450, Color(255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
cam.End3D2D()
end
end
hook.Add("PostPlayerDraw","PlayerNameTag",PlayerNameTag)
end[/code]
That's a lot of spaces.
You don't need to start the cam3d2d so far up, you could and should(not sure if it makes a difference) start it above your simpletextoutlined shit
[QUOTE=Invule;49996388]you could and should(not sure if it makes a difference)[/QUOTE]
Why would it make the slightest difference... also, he's already starting it above his simpletextoutlined 'shit'
[code]
cam.Start3D2D(pos, ang, 0.1)
if ( not IsValid( ply ) or job == nil or hp == nil ) then return end
TeamColor = team.GetColor(ply:Team())
draw.SimpleTextOutlined( name, "OVERHEADTEXT", 0, 425, TeamColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, .3, OutLineColor )
draw.DrawText( "HP: ".. hp, "OVERHEADTEXT1", 0, 450, Color(255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
cam.End3D2D()
[/code]
He has it like this, I meant something like this:
[code]
if ( not IsValid( ply ) or job == nil or hp == nil ) then return end
TeamColor = team.GetColor(ply:Team())
cam.Start3D2D(pos, ang, 0.1)
draw.SimpleTextOutlined( name, "OVERHEADTEXT", 0, 425, TeamColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, .3, OutLineColor )
draw.DrawText( "HP: ".. hp, "OVERHEADTEXT1", 0, 450, Color(255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
cam.End3D2D()
[/code]
You check for things to be invalid, assigning stuff to your variables then you do the drawing not the other way around. I'm not sure if this is just preference but I've never seen anyone do it the way he's doing it, lol.
[QUOTE=Invule;49996934][code]
cam.Start3D2D(pos, ang, 0.1)
if ( not IsValid( ply ) or job == nil or hp == nil ) then return end
TeamColor = team.GetColor(ply:Team())
draw.SimpleTextOutlined( name, "OVERHEADTEXT", 0, 425, TeamColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, .3, OutLineColor )
draw.DrawText( "HP: ".. hp, "OVERHEADTEXT1", 0, 450, Color(255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
cam.End3D2D()
[/code]
He has it like this, I meant something like this:
[code]
if ( not IsValid( ply ) or job == nil or hp == nil ) then return end
TeamColor = team.GetColor(ply:Team())
cam.Start3D2D(pos, ang, 0.1)
draw.SimpleTextOutlined( name, "OVERHEADTEXT", 0, 425, TeamColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, .3, OutLineColor )
draw.DrawText( "HP: ".. hp, "OVERHEADTEXT1", 0, 450, Color(255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( job, "OVERHEADTEXT1", 0, 475, Color(255, 255, 255), TEXT_ALIGN_CENTER)
cam.End3D2D()
[/code]
You check for things to be invalid, assigning stuff to your variables then you do the drawing not the other way around. I'm not sure if this is just preference but I've never seen anyone do it the way he's doing it, lol.[/QUOTE]
That might of been it, I'll do some more testing when some more players are on, as when new players connect seem to trigger it. But it appears to not be triggering it when I just connected with my own player's nametag enabled.
EDIT: After testing, this appeared to fix the problem and now going to close the thread, thanks for the help, such a silly mistake I made :P
I'm not sure how to close a thread, I'll just say
SOLVED
Sorry, you need to Log In to post a reply to this thread.