I've gone blind to this problem and it's irritating. I'm running this client script inside addons/lua/autorun/client and it doesn't seem to be running on startup.
[CODE]if CLIENT then
print("running2")
local charge = 10
local enabled = false
local flashframe
local bar
local _skin = { };
function _skin:PaintProgress( panel, w, h )
-- self.tex.ProgressBar.Back( 0, 0, w, h );
self.tex.ProgressBar.Front( 0, 0, w * panel:GetFraction(), h );
end
derma.DefineSkin( "BarSkin", "Bar Skin", _skin );
flashframe = vgui.Create("DFrame")
flashframe:SetSize(100, 30)
flashframe:SetPos(ScrW() - (100 + 50), 50)
flashframe:SetVisible(false)
flashframe:SetDraggable(false)
flashframe:ShowCloseButton(false)
flashframe:SetTitle("")
flashframe.Paint = function(s, w, h)
draw.RoundedBox(4, 0, 0, w, h, Color(5, 5, 5, 150))
end
bar = vgui.Create("DProgress", flashframe)
bar:SetSize(100, 30)
bar:SetBGColor(Color(5, 5, 5, 100))
bar:SetFGColor(Color(245, 245, 255))
bar:SetVisible(false)
bar:SetFraction(charge/10)
bar:SetSkin("BarSkin")
net.Receive( "switchflashlight", function(len)
enabled = net.ReadBool()
charge = net.ReadInt(5)
print("charge " .. charge)
print(enabled)
flashframe:SetVisible(enabled)
bar:SetVisible(enabled)
if enabled then bar:SetFraction(charge/10) end
flashframe:Refresh()
bar:Refresh()
end )
end[/CODE]
I fiddled around with a few things and nothing. In addons/lua/autorun/server/... I have
[CODE]AddCSLuaFile("autorun/client/cl_flashlight.lua")
util.AddNetworkString("switchflashlight")[/CODE]
at the top.
It works fine when I adjust anything inside the client script and it refreshes, so the problem has to be it not running on the client? Nothing prints on the client or anything.
Thanks for your help, I've probably made a stupid mistake that I've gone blind to.
You are running this script too early.
I suggest to do this instead.
[CODE]
hook.Add("PostGamemodeLoaded","switchflashlight",function()
local charge = 10
local enabled = false
local flashframe
local bar
local _skin = { };
function _skin:PaintProgress( panel, w, h )
-- self.tex.ProgressBar.Back( 0, 0, w, h );
self.tex.ProgressBar.Front( 0, 0, w * panel:GetFraction(), h );
end
derma.DefineSkin( "BarSkin", "Bar Skin", _skin );
flashframe = vgui.Create("DFrame")
flashframe:SetSize(100, 30)
flashframe:SetPos(ScrW() - (100 + 50), 50)
flashframe:SetVisible(false)
flashframe:SetDraggable(false)
flashframe:ShowCloseButton(false)
flashframe:SetTitle("")
flashframe.Paint = function(s, w, h)
draw.RoundedBox(4, 0, 0, w, h, Color(5, 5, 5, 150))
end
bar = vgui.Create("DProgress", flashframe)
bar:SetSize(100, 30)
bar:SetBGColor(Color(5, 5, 5, 100))
bar:SetFGColor(Color(245, 245, 255))
bar:SetVisible(false)
bar:SetFraction(charge/10)
bar:SetSkin("BarSkin")
net.Receive( "switchflashlight", function(len)
enabled = net.ReadBool()
charge = net.ReadInt(5)
print("charge " .. charge)
print(enabled)
flashframe:SetVisible(enabled)
bar:SetVisible(enabled)
if enabled then bar:SetFraction(charge/10) end
flashframe:Refresh()
bar:Refresh()
end )
end)
[/CODE]
Sorry, you need to Log In to post a reply to this thread.