• How to send a Server side variable to the client?
    8 replies, posted
Example: if SERVER then self.Variable = 9000 else draw.SimpleText("The power level is over"..self.Variable.."!!!".Variable, "default", 0, -15, Color(255,0,0,100), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) end Obviously that wouldn't work The Variable HAS to be server side though. So i'm wondering if there's a way to send the server-side variable to the client. Thanks in advance!
usermessages, look them up on the wiki.
Did not work....
[QUOTE=LegoGuy;33140473]Did not work....[/QUOTE] show us the code
[QUOTE=Banana Lord.;33141066]show us the code[/QUOTE] Actually The function is called, but the HUD don't react to the chaining vars Relevant code [Lua] if CLIENT then function SWEP.ScreenUpdate( um, self ) self.CFireMode1 = um:ReadShort() self.CFireMode2 = um:ReadFloat() Msg("Screen Updated\n") end usermessage.Hook( "swep.FireMode", SWEP.ScreenUpdate, SWEP ) function SWEP.ScreenUpdateO( um, self ) self.LightsCanFire = um:ReadShort() Msg("Leds Can Fire\n") end usermessage.Hook( "swep.LightsCanFire", SWEP.ScreenUpdateO, SWEP ) function SWEP:Think() self.VElements["Charge"].draw_func = function( weapon ) -- x = side | y = up/down | right = pos | left = neg | up = neg | down = pos | draw.SimpleText("Primary: "..self.CFireMode1, "default", 0, -15, Color(255,0,0,100), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) draw.SimpleText("Secondary: "..self.CFireMode2, "default", 0, -5, Color(255,0,0,100), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) end if self.Lights <= CurTime() then self.VElements["Led3"].color = Color(0, 0, math.random(-1,1)*255, 255) self.VElements["Led4"].color = Color(0, 0, math.random(-1,1)*255, 255) self.VElements["Led5"].color = Color(0, 0, math.random(-1,1)*255, 255) self.Lights = CurTime() + .1 end if self.LightsCanFire >= CurTime() then self.VElements["Led1"].color = Color(0, 0, 0, 255) self.VElements["Led2"].color = Color(255, 0, 0, 255) else self.VElements["Led1"].color = Color(0, 255, 0, 255) self.VElements["Led2"].color = Color(0, 0, 0, 255) end end end --------Rest is Server-side--------------------------- function SWEP:Think() if self.ScreenUpdate <= CurTime() then umsg.Start( "swep.FireMode" ) umsg.Float( self.SecondaryFireMode ) umsg.Short( self.PrimaryFireMode ) umsg.End() self.ScreenUpdate = CurTime() + 1 end end ------------------------------------------------------ --The following just happenes in different parts of the code (all server-side) umsg.Start( "swep.LightsCanFire" ) umsg.Short( CurTime() + 1 ) --The Delay is different depending on where this bit of code is umsg.End() [/lua] A orange 'Screen Updated' Does show up in the console every second the game is not paused. And 'Leds Can Fire' Does show when the function is being called.
okay.. lol. don't update the damn firemode every think, especially with a usermessage. so something like this [code] ------- -- Serverside ------- -- Make sure you pass only a string. function SWEP:SetFireMode( strMode ) umsg.Start( "swepfModeUpdate", self.Owner ); umsg.String( strMode ); umsg.End(); end --------- -- clientside --------- usermessage.Hook( "swepfModeUpdate", function(um) local fmode = um:ReadString(); SWEP.fMode = fmode; end); [/code] set it once, it doesn't need to be drawn every second. and please, indent your code..
[QUOTE=LauScript;33141718]okay.. lol. --stuff-- [/QUOTE] OK, I don't think you understand. The fire-mode, and what the SWEP does depending on the firemode, is server-side. I would like the NUMBER of the fire-mode to be shown on the 'self.VElements["Charge"]' thing [editline]5th November 2011[/editline] And the firemode was updated every second, and it was DRAWN at every tick ...Just so you know.
why would you update the firemode every second, even when it hasn't changed. does that make sense to you? network it [b]once[/b] when it's changed, put that in a clientside var on the swep or something and then have it draw that var. also what?.. it's pretty obvious why it's not drawing.. [b]self.VElements["Charge"].draw_func = function( weapon )[/b] [code] function SWEP:Think() self.VElements["Charge"].draw_func = function( weapon ) -- x = side | y = up/down | right = pos | left = neg | up = neg | down = pos | draw.SimpleText("Primary: "..self.CFireMode1, "default", 0, -15, Color(255,0,0,100), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) draw.SimpleText("Secondary: "..self.CFireMode2, "default", 0, -5, Color(255,0,0,100), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) end if self.Lights <= CurTime() then self.VElements["Led3"].color = Color(0, 0, math.random(-1,1)*255, 255) self.VElements["Led4"].color = Color(0, 0, math.random(-1,1)*255, 255) self.VElements["Led5"].color = Color(0, 0, math.random(-1,1)*255, 255) self.Lights = CurTime() + .1 end if self.LightsCanFire >= CurTime() then self.VElements["Led1"].color = Color(0, 0, 0, 255) self.VElements["Led2"].color = Color(255, 0, 0, 255) else self.VElements["Led1"].color = Color(0, 255, 0, 255) self.VElements["Led2"].color = Color(0, 0, 0, 255) end end [/code] not to be an ass but you're the one who clearly doesn't understand.
[QUOTE=LauScript;33142020]why would you update the firemode every second, even when it hasn't changed. does that make sense to you? network it [b]once[/b] when it's changed, put that in a clientside var on the swep or something and then have it draw that var. also what?.. it's pretty obvious why it's not drawing.. [b]self.VElements["Charge"].draw_func = function( weapon )[/b] --Stuff-- not to be an ass but you're the one who clearly doesn't understand.[/QUOTE] It is drawing. [filename] [IMG]http://dl.dropbox.com/u/14940709/looks-drawn-to-me.jpg[/IMG] The problem is it never updates. [editline]5th November 2011[/editline] (the var is set to 0 in the init function to prevent lua spam. [editline]5th November 2011[/editline] FIX'D! FINALLY FIGURED SOMETHING OUT! [editline]5th November 2011[/editline] Need no more help
Sorry, you need to Log In to post a reply to this thread.