• Global Variables
    3 replies, posted
I have this code in a clientside file: [CODE]local AllDoors = ents.FindByClass("func_door*") AllDoors = table.Add(AllDoors, ents.FindByClass("prop_door_rotating")) Doors = {} for k, v in pairs(AllDoors) do if v.Entity:IsValid() then Doors[v:EntIndex()] = { name = "", owners = {}, doortype = "ownable", userjobs = {}, doortext = "" } UpdateDoorText(v:EntIndex()) end end Doors[732] = { name = "", owners = {}, doortype = "job", userjobs = {JobBuilder, JobGunDealer}, doortext = "" } Doors[687] = { name = "", owners = {}, doortype = "notownable", userjobs = {}, doortext = "" } Doors[219] = { name = "", doortype = "ownable", userjobs = {}, owners = {"STEAM_0:0:14158507", "STEAM_0:0:0"}, doortext = "" }[/CODE] But when I use: [CODE]lua_run_cl PrintTable(Doors)[/CODE] In console, it only shows the table items that I entered manually. [CODE]219: userjobs: name = owners: 1 = STEAM_0:0:14158507 2 = STEAM_0:0:0 doortype = ownable doortext = 687: userjobs: name = owners: doortype = notownable doortext = 732: userjobs: 1: Max = 2 RunSpeed = 200 Title = Builder Model = models/humans/group01/male_02.mdl Id = 2 Weapons: TitlePlural = Builders WalkSpeed = 150 2: Max = 2 RunSpeed = 200 Title = Gun Dealer Model = models/humans/group01/female_03.mdl Id = 9 Weapons: TitlePlural = Gun Dealers WalkSpeed = 150 name = owners: doortype = job doortext = [/CODE]
[lua] for k, v in pairs(AllDoors) do if v.Entity:IsValid() then [/lua] Change that to [lua] for k, v in pairs(AllDoors) do if v:IsValid() then [/lua]
I have changed it but for some reason it does not find any doors when loaded either by the client or the server. When I run gamemode_reload the table Doors is filled for both the client and the server. I am running a server using Garry's Mod with "Create Server" if that makes a difference. [B]EDIT[/B] Doors is now set by a function SetupDoors() [CODE]function SetupDoors() local AllDoors = ents.FindByClass("func_door*") AllDoors = table.Add(AllDoors, ents.FindByClass("prop_door_rotating")) local Output = {} for k, v in pairs(AllDoors) do if v:IsValid() then Output[v:EntIndex()] = { name = "", owners = {}, doortype = "ownable", userjobs = {}, doortext = "" } end end print("Doors function here!") PrintTable(Output) print("End Doors") return Output end[/CODE] Then Doors = SetupDoors() in the cl_doors and sv_doors file. The function shows this (twice for SV and CL): Doors function here! End Doors!
You need to call SetupDoors in InitPostEntity, after the entities have been created.
Sorry, you need to Log In to post a reply to this thread.