• SetupDataTables() on game.GetWorld()
    4 replies, posted
When can you call SetupDataTables on the worldspawn entity? Players are a bit easier since you can just [code] local PLAYER = FindMetaTable("Player") function PLAYER:SetupDataTables() self:NetworkVar( "Entity", 0, "Zone" ) self:NetworkVar( "String", 0, "ZonePrintName" ) self:NetworkVar( "Int", 0, "InfectionZone" ) end hook.Add( "OnEntityCreated", "GAMEMODE_SetupPlayerDataTables", function( ent ) if ent:IsPlayer() then ent:InstallDataTable() ent:SetupDataTables() end end )[/code] in a shared file.. What about the worldspawn entity?
You shouldn't have the need for this. You have net library and SetGlobal* for storing data that is shared between all players.
[QUOTE=kklouzal23;51455682]When can you call SetupDataTables on the worldspawn entity? Players are a bit easier since you can just [code] local PLAYER = FindMetaTable("Player") function PLAYER:SetupDataTables() self:NetworkVar( "Entity", 0, "Zone" ) self:NetworkVar( "String", 0, "ZonePrintName" ) self:NetworkVar( "Int", 0, "InfectionZone" ) end hook.Add( "OnEntityCreated", "GAMEMODE_SetupPlayerDataTables", function( ent ) if ent:IsPlayer() then ent:InstallDataTable() ent:SetupDataTables() end end )[/code] in a shared file.. What about the worldspawn entity?[/QUOTE] Replace IsPlayer with IsWorld? Not sure if that would work, but you should have tried that first. If not there are function like [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/SetGlobalEntity]SetGlobalEntity[/url] that you can use. I wouldn't recommend doing whatever you're doing like this though.
[code]hook.Add( "OnEntityCreated", "GAMEMODE_SetupDataTables", function( ent ) if ent:IsPlayer() then ent:InstallDataTable() ent:NetworkVar( "Entity", 0, "Zone" ) ent:NetworkVar( "Entity", 1, "Base" ) ent:NetworkVar( "Int", 0, "InfectionZone" ) ent:NetworkVar( "Int", 1, "InfectionBase" ) elseif ent:IsWorld() then ent:InstallDataTable() ent:NetworkVar( "Int", 0, "InfectionTotal" ) end end )[/code] Works like a charm! Now the real question, is this safe to use?
[QUOTE=kklouzal23;51456197][code]hook.Add( "OnEntityCreated", "GAMEMODE_SetupDataTables", function( ent ) if ent:IsPlayer() then ent:InstallDataTable() ent:NetworkVar( "Entity", 0, "Zone" ) ent:NetworkVar( "Entity", 1, "Base" ) ent:NetworkVar( "Int", 0, "InfectionZone" ) ent:NetworkVar( "Int", 1, "InfectionBase" ) elseif ent:IsWorld() then ent:InstallDataTable() ent:NetworkVar( "Int", 0, "InfectionTotal" ) end end )[/code] Works like a charm! Now the real question, is this safe to use?[/QUOTE] Safe, probably. Wrong implementation, definitely. You should be using net.* library for stuff like this, as RB suggested. Especially since, my assumption, is that those values aren't changing often, if at all.
Sorry, you need to Log In to post a reply to this thread.