EOR client side opt out help, so close to working!

Pants: Pants: http://pastebin.com/XRY6400L

Pants: is what I have

Pants: I’m trying to implement http://puu.sh/7KGhF.txt

Pants: the convar is working but it isn’t stopping the sounds and the messages aren’t appearing I don’t think it’s calling.

so you’re trying to make it stream the music?

Pants: I’m trying to add a client side option to disable EOR music

Pants: so I’m trying to make it call and see what they have ttt_eor_disabled set to

Pants: and if it’s 1 I want it to stop or not send

I think you’re over-complicating things. Just create a new convar called ttt_eor_disabled, and wrap wherever you’re playing/sending music with


if ( ttt_eor_disabled == 0 )
    --code
end

[editline]26th March 2014[/editline]

Unless I’m missing something.

edit: removed all old edits since they weren’t counting as new posts it looked too cluttered. Here is a clearer post.

I am trying to add a client side option to disable EOR music. (cobalt wrote most of my edits just not where they go)

I’m going to post the whole document in the next post so it isn’t so cluttered here
too big, here’s pastebin http://pastebin.com/AGnLEPg1

So I am creating the convar with


CreateConVar("ttt_eor_disabled", "0", FCVAR_ARCHIVE)

and adding it into the f1 menu with


 local function BasedRejax( dtabs )
 
local musicsettings = vgui.Create("DPanelList", dtabs)
musicsettings:StretchToParent(0,0,padding,0)
musicsettings:EnableVerticalScrollbar(true)
musicsettings:SetPadding(10)
musicsettings:SetSpacing(10)
   
   local setting = nil
   
        local Music = vgui.Create("DForm", musicsettings)
        Music:SetName( "End Round Music" )
 
        setting = Music:CheckBox( "Disable End Round Music", "ttt_eor_disabled")
        setting:SetTooltip("Disable EOR Music")
 
        musicsettings:AddItem(Music)
 
        dtabs:AddSheet("EOR Music", musicsettings, "icon16/music.png", false, false, "End Round Music Settings")
end
hook.Add( "TTTSettingsTabs", "Rejax2Based", BasedRejax )


That part is entirely functional.

I’ve narrowed it down the convar needs to go in
– Serverside Networking
if ( SERVER ) then so I believe it should be similar to this.


-- Serverside Networking
if (ttt_eor_disabled == 0 ) then
if ( SERVER ) then
	util.AddNetworkString( "RequestTables" )
	util.AddNetworkString( "RequestTablesCallback" )
	util.AddNetworkString( "SendQueueInfo" )
	util.AddNetworkString( "RequestQueue" )
	util.AddNetworkString( "RequestQueueCallback" )
	util.AddNetworkString( "Queue_Remove" )
	util.AddNetworkString( "SendCooldownInfo" )
	
	local QueueTable = {}
		hook.Add( "TTTEndRound", "PlayMusicOnEndRound", function( win )
		
			if table.Count( QueueTable ) > 0 then
			
				local toPlay = QueueTable[ 1 ]
				
				umsg.Start( "playurl", player.GetAll() )
					umsg.String( toPlay[ 3 ] )
				umsg.End()
				
				umsg.Start( "SendSongName", player.GetAll() )
					umsg.String( toPlay[ 2 ] )
				umsg.End()
				
				ulx.fancyLog( player.GetAll(), "Playing queued song #s requested by #s", toPlay[ 2 ], toPlay[ 1 ] )
				
				table.remove( QueueTable, 1 )
				
			else
			
				if win == WIN_INNOCENT then
				
					local toPlay = table.Random( innowinsounds )
					
					umsg.Start( "playurl", player.GetAll() )
						umsg.String( toPlay[ 1 ] )
					umsg.End()
					
					umsg.Start( "SendSongName", player.GetAll() )
						umsg.String( toPlay[ 2 ] )
					umsg.End()
					
				elseif win == WIN_TRAITOR then
				
					local toPlay = table.Random( traitorwinsounds )
					
					umsg.Start( "playurl", player.GetAll() )
						umsg.String( toPlay[ 1 ] )
					umsg.End()
					
					umsg.Start( "SendSongName", player.GetAll() )
						umsg.String( toPlay[ 2 ] )
					umsg.End()
					
				elseif win == WIN_TIMELIMIT then
				
					local toPlay = table.Random( timelimitsounds )
					
					umsg.Start( "playurl", player.GetAll() )
						umsg.String( toPlay[ 1 ] )
					umsg.End()
					
					umsg.Start( "SendSongName", player.GetAll() )
						umsg.String( toPlay[ 2 ] )
					umsg.End()
					
				end
				
			end
			
		end )
	end 
		elseif 	(ttt_eor_disabled == 1 ) then
	return 
	end

But for some reason no matter what it doesn’t play music if I leave it like that, works perfect without the convar check.

It also presents this error now(doesn’t without convar)


[ERROR] addons/ulx/lua/ulx/modules/sh/endroundmusic.lua:243: attempt to index global 'umsg' (a nil value)
  1. oldFunc - addons/ulx/lua/ulx/modules/sh/endroundmusic.lua:243
   2. fn - addons/dbugr-master/lua/dbugr/util/modules/sh_func.lua:77
    3. Call - addons/ulib/lua/ulib/shared/hook.lua:183
     4. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:136
      5. oldFunc - gamemodes/terrortown/gamemode/cl_init.lua:214
       6. func - addons/dbugr-master/lua/dbugr/util/modules/sh_func.lua:77
        7. unknown - lua/includes/modules/net.lua:31

line 241-249 =


		hook.Add( "TTTPrepareRound", "StopSounds", function()
			
			umsg.Start( "stop_preround", player.GetAll() )
			umsg.End() 
			
			umsg.Start( "StopHUDPaint", player.GetAll() )
			umsg.End()
			
		end )

Can anyone PLEASE help me, this is driving me crazy haha

edit: attempt 7236286283 http://pastebin.com/kc7m1iyF I tried making both the if server and if client toggleable so the whole thing could just be bypassed and it did the same thing but has no errors.

I figured out the error.

But now it doesn’t work AND doesn’t have an error =/

Here is the newest attempt, same thing. Convar working fine but now music just won’t play no matter what. (this is only partial and the section we’re working in since it’s so long if you want to read the full one http://puu.sh/7MraO.txt


-- Serverside Networking


if ( SERVER ) then

	util.AddNetworkString( "RequestTables" )
	util.AddNetworkString( "RequestTablesCallback" )
	util.AddNetworkString( "SendQueueInfo" )
	util.AddNetworkString( "RequestQueue" )
	util.AddNetworkString( "RequestQueueCallback" )
	util.AddNetworkString( "Queue_Remove" )
	util.AddNetworkString( "SendCooldownInfo" )
	
	local QueueTable = {}
	
	if GetConVar( "gamemode" ):GetString() == "terrortown" then
	
		hook.Add( "TTTEndRound", "PlayMusicOnEndRound", function( win )
		
		local filter = RecipientFilter()
			for k, v in next, player.GetAll() do
				if v:GetInfo( "ttt_eor_disabled" ) == "1" then
					filter:AddPlayer( v )
					ULib.tsay( nil, tostring( v ) )
    end
    end

		
			if table.Count( QueueTable ) > 0 then
			
				local toPlay = QueueTable[ 1 ]
				
				
				umsg.Start( "playurl", filter )
					umsg.String( toPlay[ 3 ] )
				umsg.End()
				
				umsg.Start( "SendSongName", filter )
					umsg.String( toPlay[ 2 ] )
				umsg.End()
				
				ulx.fancyLog( player.GetAll(), "Playing queued song #s requested by #s", toPlay[ 2 ], toPlay[ 1 ] )
				
				table.remove( QueueTable, 1 )
				
			else
			
				if win == WIN_INNOCENT then
				
					local toPlay = table.Random( innowinsounds )
					
					umsg.Start( "playurl", filter )
						umsg.String( toPlay[ 1 ] )
					umsg.End()
					
					umsg.Start( "SendSongName", filter)
						umsg.String( toPlay[ 2 ] )
					umsg.End()
					
				elseif win == WIN_TRAITOR then
				
					local toPlay = table.Random( traitorwinsounds )
					
					umsg.Start( "playurl", filter )
						umsg.String( toPlay[ 1 ] )
					umsg.End()
					
					umsg.Start( "SendSongName", filter)
						umsg.String( toPlay[ 2 ] )
					umsg.End()
					
				elseif win == WIN_TIMELIMIT then
				
					local toPlay = table.Random( timelimitsounds )
					
					umsg.Start( "playurl", filter)
						umsg.String( toPlay[ 1 ] )
					umsg.End()
					
					umsg.Start( "SendSongName", filter )
						umsg.String( toPlay[ 2 ] )
					umsg.End()
					
				end
				
			end
			
		end )
		
		hook.Add( "TTTPrepareRound", "StopSounds", function()
			
			umsg.Start( "stop_preround", filter )
			umsg.End() 
			
			umsg.Start( "StopHUDPaint", filter )
			umsg.End()
			
		end )
		
	end	

	concommand.Add( "endround_menu", function( ply, cmd, args )
	
		umsg.Start( "open_endround_menu", ply )
		umsg.End()
		
	end )
	
	net.Receive( "RequestTables", function( len, ply )
		
		net.Start( "RequestTablesCallback" )
			net.WriteTable( innowinsounds )
			net.WriteTable( traitorwinsounds )
			net.WriteTable( timelimitsounds )
			net.WriteTable( extrasounds )
		net.Send( ply )
		
	end )
	
	net.Receive( "SendQueueInfo", function( len, ply )
	
		local sName = net.ReadString()
		local sUrl = net.ReadString()
		
		if sName:len() > 0 and sUrl:len() > 0 then
			table.insert( QueueTable, { ply:Nick(), sName, sUrl } )
		end
		
		ulx.fancyLog( player.GetAll(), "#s queued song #s", ply:Nick(), sName )
		
	end )
	
	net.Receive( "RequestQueue", function( len, ply )
	
		if ply:IsValid() then
		
			net.Start( "RequestQueueCallback" )
				net.WriteTable( QueueTable )
			net.Send( ply )
			
		end
		
	end )
	
	net.Receive( "Queue_Remove", function( len, ply )
		
		if not ply:IsAdmin() then
			ply:ChatPrint( "You don't have access to this command, " .. ply:Nick() .. "!" )
			return
		end
		
		local name = net.ReadString()
		local pos = net.ReadDouble()
		
		table.remove( QueueTable, pos )
		
		ulx.fancyLog( player.GetAll(), "#s removed song #s from the queue", ply:Nick(), name )
		
	end )
	
	net.Receive( "SendCooldownInfo", function( len, ply )
	
		ply:SetPData( "Cooldown", 3 )
		
	end )
	
	timer.Create( "CooldownTimer", 60, 0, function()
	
		for k, v in pairs( player.GetAll() ) do
		
			if v:GetPData( "Cooldown" ) and tonumber( v:GetPData( "Cooldown" ) ) > 0  then
			
				if tonumber( v:GetPData( "Cooldown" ) ) - 1 == 0 then	
				
					v:RemovePData( "Cooldown" )
					v:ChatPrint( "You are now able to request a song again." )	
					
				else
					v:SetPData( "Cooldown", tonumber( v:GetPData( "Cooldown" ) ) - 1 )
				end
				
			end
			
		end
		
	end )

end


-- Clientside networking and GUI
if ( CLIENT ) then
	CreateClientConVar("ttt_eor_disabled", "0", true, true)
	
	if not file.Exists( "radio", "DATA" ) then
		file.CreateDir( "radio" )
	end
	
	if not file.Exists( "radio/stations.txt", "DATA" ) then
		file.Write( "radio/stations.txt" )
	end
	
	usermessage.Hook( "playurlcl", function( um )
	
		local url = um:ReadString()
		local ply = LocalPlayer()
		
		if ply.channel and IsValid( ply.channel ) then
			ply.channel:Stop()
        end
		
        sound.PlayURL( url, "", function( station )		
			if station and IsValid( station ) then			
				station:Play()
				LocalPlayer().channel = station				
			end			
        end )
		
	end )