NetworkVar help

Well I’m writing a script and was going to use DTVar, but it is depreciated now, so I tried NetworkVar and it doesn’t work.
I can’t find anything wrong with this.



hook.Add( "SetupDataTables", "initalize", function( ply ) 
	ply:NetworkVar("Bool", 0, "Detected")
	ply:NetworkVar("Bool", 0, "Received")
end);
hook.Add( "PlayerSpawn", "bac", function( ply ) 
	if !ply:GetDetected() then -- line 66 in case you could not figure it out...
            --do stuff
        end
end)


Error:


[ERROR] lua/autorun/server/derp.lua:66: attempt to call method 'GetDetected' (a nil value)
  1. v - lua/autorun/server/derp.lua:66
   2. unknown - lua/includes/modules/hook.lua:82


I used the wiki: http://wiki.garrysmod.com/page/Entity/NetworkVar
http://wiki.garrysmod.com/page/ENTITY/SetupDataTables

Any help is appreciated.

[editline]9th July 2013[/editline]

Well I’m stupid



ply:NetworkVar("Bool", 0, "Detected")
ply:NetworkVar("Bool", 0, "Received")


The wiki says,
“Each network var has to have a unique slot. The slot is per type - so you can have an int in slot 0, a bool in slot 0 and a float in slot 0 etc. The max slots right now are 4 - so you should pick a number between 0-3”

I have 2 bools on the slot 0.

[editline]9th July 2013[/editline]

EDIT: Lied, that still didn’t fix it, but I’m sure it would have been a problem anyways :stuck_out_tongue:

EDIT9001: Turns out NetworkVar only works on entities and not players.

You can’t use NetworkVar on player unless you call ply:InstallDataTables() first… it may or may not have an S on the end, so try both.

There is no hook for SetupDataTables on the player, so call it in InitialSpawn or something.

I just tried this



hook.Add( "PlayerInitialSpawn", "initalize", function( ply )
	ply:InstallDataTable()
	ply:NetworkVar("Bool", 0, "Detected")
	ply:NetworkVar("Bool", 0, "Received")
end);
hook.Add( "PlayerSpawn", "bac", function( ply ) 
	if !ply:GetDetected() then
        end
end)


[del]Give me 2 minutes[/del]
WORKS :smiley: FINALLY

[editline]9th July 2013[/editline]
NEW ISSUE

Ok so it works but i’m getting spammed with this: (Client sided)



Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6Couldn't write type 6--RAC(cl) recieved, back to server
[Pandaman09|26|STEAM_0:1:33982761] Lua Error:
Couldn't write type 6
[Pandaman09|26|STEAM_0:1:33982761] Lua Error:
Couldn't write type 6
[Pandaman09|26|STEAM_0:1:33982761] Lua Error:
Couldn't write type 6
[Pandaman09|26|STEAM_0:1:33982761] Lua Error:
Couldn't write type 6
[Pandaman09|26|STEAM_0:1:33982761] Lua Error:
Couldn't write type 6


So why can I not do this?



        local CNCMDS = concommand.GetTable()
        net.Start( "return" );
	        net.WriteTable(CNCMDS)--the console commands
        net.SendToServer();


You can’t send functions via the net library.

ok then why do I still get the console command



[22:30:22][CONCMD] 'Pandaman09' [STEAM_0:1:33982761] Client has a console command of -snap : the server does not.

[22:30:22][CONCMD] 'Pandaman09' [STEAM_0:1:33982761] Client has a console command of derma_controls : the server does not.

[22:30:22][CONCMD] 'Pandaman09' [STEAM_0:1:33982761] Client has a console command of snap_dev_saveoffset : the server does not.

[22:30:22][CONCMD] 'Pandaman09' [STEAM_0:1:33982761] Client has a console command of snaplock : the server does not.

[22:30:22][CONCMD] 'Pandaman09' [STEAM_0:1:33982761] Client has a console command of gmod_tool_auto : the server does not.

[22:30:22][CONCMD] 'Pandaman09' [STEAM_0:1:33982761] Client has a console command of e2helper : the server does not.


EDIT: using this:
This is server side ONLY



for k,v in pairs(CNCMDS) do
	if !table.HasValue(concommand.GetTable(), v) and !table.HasValue(SafeConCmds, v) then
		local text = "Client has a console command of "..v.." : the server does not.
"
		LogCheater(ply, text, "concmd")
		--print("Client has Console command that server does not: "..v)
		ply:SetDetected(true)
	end
end


EDIT 2: is there a way to “strip the function” but keep the console command?

Why are you using Data Tables to track them? Don’t tell the client that they are detected, track it on the player-side server table.

I will, but it doesn’t matter because I already have then logged and will ban them.
EDIT: Data tables just made sense to me so I used them. Don’t know why I wouldn’t just think of pushing them to a table.

actually, why don’t you just ban them on detect? there’s no point in setting a variable on the player.

Because my detection method may be a false positive, anyways can you help me with the concommand.gettable problem?

Well I just realized that the information is stored by a key, the key being the console command.
Solved.