• Setting Networked Variable on player
    6 replies, posted
Been trying to create a very simple gamemode, Here is the code that isn't working. (Please ignore my Swedish comments) [lua] PropTable = pl:GetNetworkedVar( "PropList" ) -- Hämtar NWvar if PropTable == null then PropTable = {} -- Ifall det inte finns så sätt det till tomt ({}) end table.insert(PropTable,Sak) -- Lägg in objektet i listan pl:SetNetWorkedVar( "PropList", PropTable ) -- Skicka iväg [/lua] This is in the function that is called each time someone spawns something. "Sak" is the entity they are spawning. "pl" is the player. This is how I'm thinking it: 1. Player spawns something. 2. Checks if the networked var PropList is empty, If it isn't it sets PropTable to it, If it is it sets PropTable to{}. 3. Insert "Sak", The entity, to the list. 4. Set the networked var. Basically I'm trying to create a table for every player that includes everything they've spawned. The error I'm getting is: [code] attempt to call method 'SetNetWorkedVar' (a nil value) gamemodes/kush/gamemode/init.lua:63 [/code] This is in Gmod 13 but I'm sure that's not related to the error. Line 63 is line 6 in the above code snippet. [editline]13th May 2012[/editline] Problem solved, Thanks for anyone reading it though. Was a stupid spelling mistake. [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index18b7.html?title=Entity.SetNetworkedVar[/url] Here it's called NetWorked var, Whereas in the other sections, Like GetNetworked var it's written correctly. This is what you get for copy and pasting i guess. [editline]13th May 2012[/editline] I do have another problem though, I can't network tables apparently. Any tips on another way to do this? I suppose I could network the owner of each entity but that seems dumb because then i would be setting hundreds of networked variables instead of maybe 12.
Store the player's values serverside and then send them through a usermessage and reconstruct the table clientside, is what I'd think. [editline]13th May 2012[/editline] Create a serverside table called 'proptable' and then set proptable[guys steamID here] to a table of his props (inception tables ftw). Then you can send his table when the client needs it. [editline]13th May 2012[/editline] You can create a console command serverside that triggers sending a umsg of the player's props to the client and then create a menu that shows his props (or whatever you want to do) in the usermessage hook. [editline]13th May 2012[/editline] Or if you need to show the owner for a specific prop (like when you look at it or something), you can do a concommand with Entity.EntIndex as one of its arguments and then do a umsg which sends it's owner.
Thanks a lot. Works perfect. This is what I'm using now if anyone else wonders about this sometime. [lua]--Prop List (Sak is the entity) if PropList[pl:UniqueID()] == nil then PropList[pl:UniqueID()] = {} end table.insert(PropList[pl:UniqueID()],Sak)[/lua]
Also make sure to delete a player's part of the table when he disconnects.
[QUOTE=cis.joshb;35943946]Also make sure to delete a player's part of the table when he disconnects.[/QUOTE] [lua]function CleanUpProps(pl,command,args) if PropList[pl] then for k,v in pairs(PropList[pl]) do v:Remove() end PropList[pl] = nil end end concommand.Add("GM_CleanUp",CleanUpProps)[/lua] I can't work on it right now but I'm guessing that all I need to do is hook this function I wrote for a cleanup command to whenever someone disconnects with perhaps a delay or something. Should work fine right? Thanks.
Use SetNetworkedVar instead of SetNetWorkedVar
[QUOTE=kp3;35946189][lua]function CleanUpProps(pl,command,args) if PropList[pl] then for k,v in pairs(PropList[pl]) do v:Remove() end PropList[pl] = nil end end concommand.Add("GM_CleanUp",CleanUpProps)[/lua] I can't work on it right now but I'm guessing that all I need to do is hook this function I wrote for a cleanup command to whenever someone disconnects with perhaps a delay or something. Should work fine right? Thanks.[/QUOTE] Yeah, that looks good.
Sorry, you need to Log In to post a reply to this thread.