• STools
    1 replies, posted
So, I have an STool coded, but I can't seem to modify the vars. I'm using clientside ConVars to save the information, and I have no idea how the GUI portion of it works. Any help would be appreciated. [code]if (SERVER) then CreateConVar('sbox_maxkeypads', 10) end local Debug = true TOOL.Category = "Construction" TOOL.Name = "Keypad" TOOL.Command = nil CreateConVar('keypad_weld', 1) CreateConVar('keypad_freeze', 1) CreateConVar('keypad_secure', 0) CreateConVar('keypad_repeats_granted', 0) CreateConVar('keypad_repeats_denied', 0) CreateConVar('keypad_length_granted', 0.1) CreateConVar('keypad_length_denied', 0.1) CreateConVar('keypad_delay_granted', 0) CreateConVar('keypad_delay_denied', 0) CreateConVar('keypad_init_delay_granted', 0) CreateConVar('keypad_init_delay_denied', 0) CreateConVar('keypad_key_granted', 0) CreateConVar('keypad_key_denied', 0) CreateConVar('keypad_password', 1111) function TOOL:GetClientConVar( property, default ) default = default or 0 return GetConVar(property) end cleanup.Register("keypads") if(CLIENT) then language.Add("tool.keypad.name", "Keypad") language.Add("tool.keypad.0", "Left Click: Create, Right Click: Update") language.Add("tool.keypad.desc", "Creates Keypads for secure access") language.Add("Undone_Keypad", "Undone Keypad") language.Add("Cleanup_keypads", "Keypads") language.Add("Cleaned_keypads", "Cleaned up all Keypads") language.Add("SBoxLimit_keypads", "You've hit the Keypad limit!") end function TOOL:SetupKeypad(ent, pass) local pass2 = GetConVar("keypad_password"):GetInt() local data = { Password = pass2, RepeatsGranted = self:GetClientConVar("repeats_granted"), RepeatsDenied = self:GetClientConVar("repeats_denied"), LengthGranted = self:GetClientConVar("length_granted"), LengthDenied = self:GetClientConVar("length_denied"), DelayGranted = self:GetClientConVar("delay_granted"), DelayDenied = self:GetClientConVar("delay_denied"), InitDelayGranted = self:GetClientConVar("init_delay_granted"), InitDelayDenied = self:GetClientConVar("init_delay_denied"), KeyGranted = self:GetClientConVar("key_granted"), KeyDenied = self:GetClientConVar("key_denied"), Secure = util.tobool(self:GetClientConVar("secure")), Owner = self:GetOwner() } for k, v in pairs(player.GetAll()) do v:ChatPrint(data.Password.." set "..pass2) end ent:SetData(data) end function TOOL:RightClick(tr) if(IsValid(tr.Entity) and tr.Entity:GetClass() ~= "keypad") then return false end if(CLIENT) then return true end local ply = self:GetOwner() local password = tonumber(self:GetClientConVar("keypad_password"):GetInt()) for k, v in pairs(player.GetAll()) do v:ChatPrint(tostring(password)) end local spawn_pos = tr.HitPos local trace_ent = tr.Entity if(password == nil or (string.len(tostring(password)) > 4) or (string.find(tostring(password), "0"))) then ply:PrintMessage(3, "Invalid password!") return false end if(trace_ent:GetClass() == "keypad" and trace_ent.KeypadData.Owner == ply) then self:SetupKeypad(trace_ent, password) return true end end function TOOL:LeftClick(tr) if(IsValid(tr.Entity) and tr.Entity:GetClass() == "player") then return false end if(CLIENT) then return true end local ply = self:GetOwner() local password = tonumber(self:GetClientConVar("keypad_password"):GetInt()) for k, v in pairs(player.GetAll()) do v:ChatPrint(tostring(password)) end local spawn_pos = tr.HitPos + tr.HitNormal local trace_ent = tr.Entity if(password == nil or (string.len(tostring(password)) > 4) or (string.find(tostring(password), "0"))) then ply:PrintMessage(3, "Invalid password!") return false end if(not self:GetWeapon():CheckLimit("keypads")) then return false end local ent = ents.Create("keypad") ent:SetPos(spawn_pos) ent:SetAngles(tr.HitNormal:Angle()) ent:Spawn() ent:SetPlayer(ply) ent:SetAngles(tr.HitNormal:Angle()) ent:Activate() local phys = ent:GetPhysicsObject() -- rely on this being valid self:SetupKeypad(ent, password) undo.Create("Keypad") if(util.tobool(self:GetClientConVar("freeze"))) then phys:EnableMotion(false) end if(util.tobool(self:GetClientConVar("weld"))) then phys:EnableMotion(false) -- The timer allows the keypad to fall slightly, no thanks timer.Simple(0, function() if(IsValid(ent) and IsValid(trace_ent)) then local weld = constraint.Weld(ent, trace_ent) end end) ent:GetPhysicsObject():EnableCollisions(false) end undo.AddEntity(ent) undo.SetPlayer(ply) undo.Finish() ply:AddCount("keypads", ent) ply:AddCleanup("keypads", ent) return true end if(CLIENT) then function TOOL.BuildCPanel(CPanel) local r, l = CPanel:TextEntry("Password (No 0s, no longer than 4)", "keypad_password") r:SetTall(22) CPanel:ControlHelp("Allowed Digits: 1-9") CPanel:CheckBox("Secure Mode", "keypad_secure") CPanel:CheckBox("Weld and Freeze", "keypad_weld") CPanel:CheckBox("Freeze", "keypad_freeze") local ctrl = vgui.Create("CtrlNumPad", CPanel) ctrl:SetConVar1("keypad_key_granted") ctrl:SetConVar2("Keypad_key_denied") ctrl:SetLabel1("Access Granted") ctrl:SetLabel2("Access Denied") CPanel:AddPanel(ctrl) CPanel:Help("") CPanel:Help("Settings when access granted") CPanel:NumSlider("Hold Length", "keypad_length_granted", 0.1, 10, 2) CPanel:NumSlider("Initial Delay", "keypad_init_delay_granted", 0, 10, 2) CPanel:NumSlider("Multiple Press Delay", "keypad_delay_granted", 0, 10, 2) CPanel:NumSlider("Additional Repeats", "keypad_repeats_granted", 0, 5, 0) CPanel:Help("") CPanel:Help("Settings when access denied") CPanel:NumSlider("Hold Length", "keypad_length_denied", 0.1, 10, 2) CPanel:NumSlider("Initial Delay", "keypad_init_delay_denied", 0, 10, 2) CPanel:NumSlider("Multiple Press Delay", "keypad_delay_denied", 0, 10, 2) CPanel:NumSlider("Additional Repeats", "keypad_repeats_denied", 0, 5, 0) end end[/code]
you should use TOOL.ClientConVar["my_convar"]=1. take a look at the example stool found in the gamemodes/sandbox/entities/weapons/gmod_tool/stools: [lua] -- Remove this to add it to the menu TOOL.AddToMenu = false -- Define these! TOOL.Category = "My Category" -- Name of the category TOOL.Name = "#Example" -- Name to display TOOL.Command = nil -- Command on click (nil for default) TOOL.ConfigName = nil -- Config file name (nil for default) if ( true ) then return end -- An example clientside convar TOOL.ClientConVar["CLIENTSIDE"] = "default" -- An example serverside convar TOOL.ServerConVar["SERVERSIDE"] = "default" function TOOL:LeftClick( trace ) Msg( "PRIMARY FIRE\n" ) end function TOOL:RightClick( trace ) Msg( "ALT FIRE\n" ) end function TOOL:Reload( trace ) -- The SWEP doesn't reload so this does nothing :( Msg( "RELOAD\n" ) end function TOOL:Think() end [/lua]
Sorry, you need to Log In to post a reply to this thread.