• How to do a table of entities.
    9 replies, posted
I am trying to allow certain entities for certain teams but it does not work. Any ideas? local AllowedTeamsForTardis = {     [TEAM_CITIZEN] = true,     [TEAM_COMPANION] = true } local TardisEntities = {     ["sent_tardis"] = true,     ["gmod_tardis"] = true } hook.Add("PlayerSpawnSent", "blocktardisfortimelord", function(ply, ent)     if(AllowedTeamsForTardis[ply:Team()] && TardisEntities[ent]) then         return true     end end)
Pretty sure that it should be "PlayerSpawnSENT" and not "PlayerSpawnSent". SANDBOX/PlayerSpawnSENT
Yes, noticed that. Also my other one which is for VIP does not work and it has PlayerSpawnSENT as the hook. No typo there. local VIPEntities = {     ["gmt_instrument_piano"] = true,     ["sfi_pkin"] = true } hook.Add("PlayerSpawnSENT", "vipentities", function(ply, class)     if(VIPEntities[class] && VIPGroups[ply:GetNWString("usergroup")]) then         return true     end end)
Make debug: When hook called print ply, ply usergroup, class, VIPEntities[class] (returns boolean) and VIPGroups[ply:GetNWString("usergroup")] (returns boolean)
Figured it out. local AllowedTeamsForTardis = {     [TEAM_CITIZEN] = true,     [TEAM_COMPANION] = true } local TardisEntities = {     ["sent_tardis"] = true,     ["gmod_tardis"] = true } hook.Add("PlayerSpawnSENT", "blocktardisfortimelord", function(ply, ent)     if(AllowedTeamsForTardis[ply:Team()] && TardisEntities[ent]) then         return true     end end)
Use one if for optimisation if VIPGroups[ply:GetNWString("usergroup")] and VIPEntities[ent] then print("No!") return false end
Thanks. I also tried doing it with teams but it seems to just pop up with table index is nil? local AllowedTeamsForTardis = {     [TEAM_CITIZEN] = true,     [TEAM_COMPANION] = true, } local TardisEntities = {     ["item_ammo_357_large"] = true,     ["item_ammo_357"] = true, } hook.Add("PlayerSpawnSENT", "blocktardisfortimelord", function(ply, ent)     if AllowedTeamsForTardis[ply:Team()] && TardisEntities[ent] then         return true     end end)
Maybe you have different function to return player's team for your gamemode. As I know, DarkRP has.
playerentity:Team() returns a number value, used by Garry's Mod's own team system. DarkRP may use it for all of DarkRP's roles, but it returns a number, not a string. Find the comparative team each name is supposed to work with. This may help: team.GetAllTeams
Was me being very silly. TEAM_CP did not exist. In my head it did though :P
Sorry, you need to Log In to post a reply to this thread.