Okay, i am trying to make an entity that when you press a certain button on the derma that opens when you use the entity, send information to the server, which works, and then send it to ALL clients, i am trying to write a boolean that when it is set to true it draws a certain hud, here is what i have:
CLIENTSIDE: This works fine, so it sends the info to the server and it prints the chat if you are government.
if ( table.HasValue( jobslol, LocalPlayer():Team() ) ) then
LocalPlayer():ChatPrint("Successfully claimed the territory.")
net.Start("GovernmentIsControlling")
net.WriteBool(true)
net.SendToServer()
end
SERVERSIDE: This works fine aswell, prints it to all players.
net.Receive("GovernmentIsControlling",function(len,ply)
local isControllingGov = net.ReadBool()
if IsValid( ply ) and (isControllingGov) then
for k, ply in pairs( player.GetAll() ) do
ply:ChatPrint( "The area is now controlled by the Government." )
end
net.Start("GovernmentIsControlling2")
net.WriteBool(true)
net.Broadcast()
end
end)
Clientside derma: This doesnt work, its meant to show up as "Bla bla bla is controlling this territory" in the derma if the bool is true.
net.Receive("GovernmentIsControlling2",function()
local teststring = net.ReadBool()
end)
local frame = vgui.Create( "DFrame" )
frame:SetPos( ScrW() / 3 + 100, ScrH() / 3 )
frame:SetSize( 300, 200 )
frame:SetTitle( " " )
frame:SetDraggable( false )
frame:MakePopup()
frame:ShowCloseButton( true )
frame.Paint = function(s , w , h)
draw.RoundedBox(0,0,0,w,h,Color(10,10,10, 230))
draw.SimpleText("abc Area:","AngryBirds2",40,30,Color( 255, 255, 255, 255 ))
if teststring then
draw.SimpleText("Government Territory","AngryBirds2",118,30,Color( 255, 0, 0, 255 ))
end
end
I don't seem to find why it is not showing up the way it should, any help would be appreciated.
Your teststring is local for net.Receive and it seems like you are creating that frame when file loads
Is there a way to draw the frame and then only draw the text "Government Territory" when lets say we make an if function the frame is drawn. Otherwise adding the frame all the time is just loads.
2 line changes to the code that you have will give you what you want. Since you declare and define the teststring variable inside the net.Receive function, the scope of that variable ends when that function ends. The solution is to declare your variable in a location where it will have a wider scope (above the rest of the code in the file):
local teststring = false
net.Receive("GovernmentIsControlling2",function()
teststring = net.ReadBool()
end)
local frame = vgui.Create( "DFrame" )
frame:SetPos( ScrW() / 3 + 100, ScrH() / 3 )
frame:SetSize( 300, 200 )
frame:SetTitle( " " )
frame:SetDraggable( false )
frame:MakePopup()
frame:ShowCloseButton( true )
frame.Paint = function(s , w , h)
draw.RoundedBox(0,0,0,w,h,Color(10,10,10, 230))
draw.SimpleText("abc Area:","AngryBirds2",40,30,Color( 255, 255, 255, 255 ))
if teststring then
draw.SimpleText("Government Territory","AngryBirds2",118,30,Color( 255, 0, 0, 255 ))
end
end
Doesn't seem to work, may this be because i am using an entity and a script that i execute with lua_openscript_cl?
It will need to have been ran before the server calls net.Broadcast.
No errors anywhere in console?
Sorry, you need to Log In to post a reply to this thread.