• Check if ConVar on/off?
    5 replies, posted
Hello, so I'm using a DCheckBox to on and off a ConVar called "synaps_randomcolor_phys", but when it's 1 it's not stopping this function below, here's the code: local test = CreateClientConVar("synaps_randomcolor_phys", "0", true, false) hook.Add("PostPlayerDraw", "DrawPlayerInfoSynaps", function(ply)     if test:GetInt() == 0 then         if not ply:IsValid() then return end         if not DarkRP then return end         if ply == LocalPlayer() then return end         if ply:GetPos():Distance(LocalPlayer():GetPos()) > 250 then return end                  local nameColor         local teamColor = team.GetColor(ply:Team())         local newColor = Color(math.Clamp(teamColor.r * 1.2, 100, 255), math.Clamp(teamColor.g * 1.2, 100, 255), math.Clamp(teamColor.b * 1.2, 100, 255))                  if GroupColor[ply:GetUserGroup()] then             if !ply.hue then                              ply.hue = 0                 ply.rate = 72             end             ply.hue = (ply.hue + FrameTime() * math.min(720, ply.rate)) % 360                          local hsvtColor = HSVToColor(ply.hue, 1, 1)             nameColor = hsvtColor         else             nameColor = Color(255, 255, 255)         end                  if ply:GetColor() == 0 then return end         local ang = LocalPlayer():EyeAngles()         local pos = ply:GetPos() + Vector(0, 0, 85) + ang:Up()         ang:RotateAroundAxis(ang:Forward(), 90)         ang:RotateAroundAxis(ang:Right(), 90)         cam.Start3D2D(pos, Angle(0, ang.y, 90), 0.05)                      draw.SimpleText(ply:Name(), "PlayerDrawFont", 0, -75, nameColor, 1, 1)             draw.SimpleText(team.GetName(ply:Team()), "PlayerDrawFont", 0, 25, newColor, 1, 1)                          draw.SimpleText("Press E for player info", "PlayerDrawFont2", 0, 80, Color(255, 255, 255, 220), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)             if (!ply.hue) then                              ply.hue = 0                 ply.rate = 72             end             ply.hue = (ply.hue + FrameTime() * math.min(720, ply.rate)) % 360                          local c = HSVToColor(ply.hue, 1, 1)             nameColor = c         cam.End3D2D()     end end) Any help would be appreciated!
Change CreateClientConVar("synaps_randomcolor_phys", "0", true, false) to CreateClientConVar("synaps_randomcolor_phys", 0, true, false)
Hm, that didn't seem to fix it, or change anything, still doesn't stop it from running.
Try printing converted integer (wiki says that it will set it to 0 on failure) and consider using ConVar/GetBool if your console variable is a 0/1
Either check for bool/string. Also if you did not restart the game upon changing it, that is why it did not work since the ConVar did not change
local test = CreateClientConVar("synaps_randomcolor_phys", "0", true, false) if not DarkRP then return end hook.Add("PostPlayerDraw", "DrawPlayerInfoSynaps", function(ply) if test:GetInt() == 1 then return end if not ply:IsValid() then return end if ply == LocalPlayer() then return end if ply:GetPos():Distance(LocalPlayer():GetPos()) > 250 then return end local nameColor local teamColor = team.GetColor(ply:Team()) local newColor = Color(math.Clamp(teamColor.r * 1.2, 100, 255), math.Clamp(teamColor.g * 1.2, 100, 255), math.Clamp(teamColor.b * 1.2, 100, 255)) if GroupColor[ply:GetUserGroup()] then if !ply.hue then ply.hue = 0 ply.rate = 72 end ply.hue = (ply.hue + FrameTime() * math.min(720, ply.rate)) % 360 local hsvtColor = HSVToColor(ply.hue, 1, 1) nameColor = hsvtColor else nameColor = Color(255, 255, 255) end if ply:GetColor() == 0 then return end local ang = LocalPlayer():EyeAngles() local pos = ply:GetPos() + Vector(0, 0, 85) + ang:Up() ang:RotateAroundAxis(ang:Forward(), 90) ang:RotateAroundAxis(ang:Right(), 90) cam.Start3D2D(pos, Angle(0, ang.y, 90), 0.05) draw.SimpleText(ply:Name(), "PlayerDrawFont", 0, -75, nameColor, 1, 1) draw.SimpleText(team.GetName(ply:Team()), "PlayerDrawFont", 0, 25, newColor, 1, 1) draw.SimpleText("Press E for player info", "PlayerDrawFont2", 0, 80, Color(255, 255, 255, 220), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) if (!ply.hue) then ply.hue = 0 ply.rate = 72 end ply.hue = (ply.hue + FrameTime() * math.min(720, ply.rate)) % 360 local c = HSVToColor(ply.hue, 1, 1) nameColor = c cam.End3D2D() end)
Sorry, you need to Log In to post a reply to this thread.