Hello! I am new to lua and I am trying to make an entity that only a certain team can access. This entity when pressed E on will spectate someone.
I am trying to use metafunctions to do this.
I do not have errors yet since I simply have not done it.
It is split up into
Init.lua:
util.AddNetworkString( "Spec" )
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "Shared.lua" )
AddCSLuaFile( "Team_SetUp.lua" )
include ( "shared.lua" )
include ( "Team_SetUp.lua" )
local ply = FindMetaTable ( "Player" )
function ENT:Initialize()
self:SetModel( "models/hunter/blocks/cube025x025x025.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
endendfunction ENT:Use( active , caller )if (ply.team == active.team and IsValid( active )) then
net.Start ( "Spec" )
net.Send ( "active" )
endend
cl_init.lua
NOTE: Also how do I find the variable of the player I want to spectate in this code section:
include( "Shared.lua" )
function ENT:Draw()
self:DrawModel()
end
net.Receive( "Spec" , function()
:Spectate( 4 )
end)
I am stuck here from the note above:
:Spectate( 4 )
Also Shared.lua
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Spectate"
ENT.Spawnable = true
ENT.Author = "DramaLlama"
team.SetUp ( 0 , "Red" , Color ( 255 , 0 , 0) )
team.SetUp ( 1 , "Blue" , Color ( 0 , 0 , 255) )
and my team system:
Team_SetUp.lua
local ply = FindMetaTable ( "Player" )
local teams = {}
teams[0] = {
name = "Red" ,
colour = Vector ( 1.0 , 0 , 0 )
}
teams[1] = {
name = "Blue" ,
colour = Vector ( 0 , 0 , 1.0 )
}
function ply:SetupTeam ( n )if ( not teams [ n ] ) thenreturnend
self:SetTeam ( n )
self:SetPlayerColor ( teams[ n ].colour )
end
I am sorry if I am not clear and ask any questions.
Thanks!
Player/Spectate
That runs on the server, no need for the net messages in this.
Thank you but now how do I check team using a meta table?
Why are you using metatables in the first place? You should be checking if active.team equals a certain team_name.
I heard it was the best way of doing things such as this. I think I have figured my problem out anyway.
Thanks for the input!
Sorry, you need to Log In to post a reply to this thread.