• Code Not Working - Networking doesn't go as planned
    0 replies, posted
Okay. What I want to do is network a float to the client so they can see the remaining time left before a wave of enemies spawns. This is how it works serverside: [code]--shitty way to do something like this, but at least it should work --we need to network our wave timer, we'll do it here function networktimer( ply ) net.Start( "NetworkTimer" ) net.WriteFloat( GAMEMODE:GetNextWave() ) net.Send( ply ) end hook.Add( "PlayerSpawn", "GamemodePlayerSpawn", function( ply ) if !ply.initialSpawned and !GetGlobalBool( "InWave" ) then --this logic is shitting up my head, but I'm trying my best networktimer( ply ) print("networked") ply.initialSpawned = true end end )[/code] GAMEMODE:GetNextWave() being a convenience func I made to get my nextwave var. Clientside: [code]local IndivRndTime = 0 net.Receive( "NetworkTimer", function( len ) IndivRndTime = net.ReadFloat() print(IndivRndTime-CurTime()) end ) local svs_hud = {} function svs_hud:PaintRoundStatusBar( bot ) if bot then return end --don't draw if we're a bot if IndivRndTime != 0 then local str = string.format( "Time: %i", IndivRndTime ) end surface.SetDrawColor( 0, 0, 205, 25 ) --background surface.DrawRect( ScrW() / 25, ScrH() / 1.3, 0.20 * ScrW(), 91 ) surface.SetDrawColor( 70, 220, 8, 215 ) --border surface.DrawOutlinedRect( ScrW() / 25, ScrH() / 1.3, 0.20 * ScrW(), 91 ) surface.SetFont( "DermaDefaultBold" ) surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( ScrW() / 16, ScrH() / 1.23 ) surface.DrawText( GetGlobalBool( "InWave" ) and "Status: In Wave" or str --[[or "None"]] ) end function GM:HUDPaint() if LocalPlayer():Alive() then svs_hud.PaintRoundStatusBar( LocalPlayer():IsBot() ) end end[/code] Also, note that !GetGlobalBool( "InWave" ) shows whether we're in the preparation stage or not. Now, I get the following error with the code: [code][ERROR] addons/spysvssoldiers/gamemodes/svs/gamemode/cl_exts.lua:39: bad argument #1 to 'DrawText' (string expected, got nil) 1. DrawText - [C]:-1 2. PaintRoundStatusBar - addons/spiesvssoldiers/gamemodes/svs/gamemode/cl_exts.lua:39 3. unknown - addons/spiesvssoldiers/gamemodes/svs/gamemode/cl_exts.lua:45 [/code] What went wrong?
Sorry, you need to Log In to post a reply to this thread.