• Any way to make this string only apply to one team?
    2 replies, posted
Firstly, apologies if this is a string of lua that [I]only[/I] applies to the Nutscript RP gamemode and nobody here can read it. But this code makes a line trace back to the location of the player and print their name above a pointed that points them out. Normally it only works when an admin is in noclip mode, but I chopped it up so that if you're playing on the Civil Protection or Combine Overwatch team it appears. The problem is, I'd like to make it apply only to players who are on the team FACTION_CP - alternatively, I'd be fine with it only [B]not[/B] applying to the team FACTION_CITIZEN. Basically I want this code to only apply to players on a certain team. Any pointers, or is it a lost cause? [code] if (CLIENT) then NUT_CVAR_ADMINESP = CreateClientConVar("nut_policehud", 1, true, true) local client, sx, sy, scrPos, marginx, marginy, x, y, teamColor, distance, factor, size, alpha local dimDistance = 1024 function PLUGIN:HUDPaint() client = LocalPlayer() if (client:isCombine()) then sx, sy = surface.ScreenWidth(), surface.ScreenHeight() for k, v in ipairs(player.GetAll()) do if (v == client) then continue end scrPos = v:GetPos():ToScreen() marginx, marginy = sy*.1, sy*.1 x, y = math.Clamp(scrPos.x, marginx, sx - marginx), math.Clamp(scrPos.y, marginy, sy - marginy) teamColor = team.GetColor(v:Team()) distance = client:GetPos():Distance(v:GetPos()) factor = 1 - math.Clamp(distance/dimDistance, 0, 1) size = math.max(10, 32*factor) alpha = math.Clamp(255*factor, 80, 255) surface.SetDrawColor(teamColor.r, teamColor.g, teamColor.b, alpha) surface.DrawLine(sx * 0.5, sy * 0.5, x, y) surface.DrawTexturedRect(x - size/2, y - size/2, size, size) nut.util.drawText(v:Name(), x, y - size, ColorAlpha(teamColor, alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, nil, alpha) end end end function PLUGIN:SetupQuickMenu(menu) if (Client:isCombine()) then local button = menu:addCheck(L"toggleESP", function(panel, state) if (state) then RunConsoleCommand("nut_policehud", "1") else RunConsoleCommand("nut_policehud", "0") end end, NUT_CVAR_ADMINESP:GetBool()) menu:addSpacer() end end else end [/code] [editline]9th June 2015[/editline] As a pointer, I suspect that changing Player.GetAll would solve things, but I'm not sure which to pop in there. What could also apply is only showing players who have "ASF-" in their name.
If you want it to apply to FACTION_CP, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/team/GetPlayers]team.GetPlayers[/url](FACTION_CP). Otherwise, make a table with the team indexes you want as indexes in the table, and check if the player's team is in index within that table. If it is not, then go onto the text one in the loop using continue.
Worked beautifully, thank you!
Sorry, you need to Log In to post a reply to this thread.