Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile( "cl_init.lua" )
- AddCSLuaFile( "shared.lua" )
- include('shared.lua')
- /*---------------------------------------------------------
- Name: Initialize
- Desc: First function called. Use to set up your entity
- ---------------------------------------------------------*/
- function ENT:Initialize()
- self.Players = {}
- self.Progress = 0
- self.Ownerteam = 0
- self:SetNWInt("Ownerteam",0)
- self.Status = "Not captured."
- self.CapStatus = 0
- end
- function ENT:PassesTriggerFilters(ent)
- return true
- end
- function ENT:StartTouch(ent)
- if ent:IsPlayer() and ent:Team() != 0 then
- table.insert(self.Players,ent)
- umsg.Start("CapZone",ent)
- umsg.Bool(true)
- umsg.End()
- self:TimerMoneyAndXP(ent)
- elseif ent:IsPlayer() then
- ent:ChatPrint("Gangless cannot hold capture points...")
- end
- end
- function ENT:TimerMoneyAndXP(ply)
- if table.HasValue(self.Players,ply) then
- ply:AddMoney(10)
- ply:AddExp(15)
- timer.Simple(1,self:TimerMoneyAndXP,ply)
- end
- end
- function ENT:EndTouch(ent)
- if ent:IsPlayer() and ent:Team() != 0 then
- for k,v in pairs(self.Players) do
- if v == ent then
- table.remove(self.Players,k)
- break
- end
- end
- umsg.Start("CapZone",ent)
- umsg.Bool(false)
- umsg.End()
- elseif ent:IsPlayer() then
- ent:ChatPrint("Gangless cannot hold capture points.")
- end
- end
- function ENT:Think()
- if table.Count(self.Players) > 0 then
- local singleteam = true
- if not (self.Players[1] and self.Players[1]:IsValid()) then table.remove(self.Players,1) return end
- local curteam = self.Players[1]:Team()
- local teamless = false
- for k,v in pairs(self.Players) do
- if not (v and v:IsValid()) then
- table.remove(self.Players,k)
- end
- if v:Team() != curteam then
- singleteam = false
- end
- end
- if singleteam then
- if curteam != self.Ownerteam then
- if self.Progress > 0 and self.CapStatus == 2 then
- self.Progress = self.Progress - table.Count(self.Players)
- self.Status = "Being compromised..."
- else
- if self.Progress < 100 then
- self.Ownerteam = 0
- self:SetNWInt("Ownerteam",0)
- self.Progress = self.Progress + table.Count(self.Players)
- self.Status = "Being captured..."
- self.CapStatus = 1
- else
- self.Progress = 100
- self.Ownerteam = curteam
- self:SetNWInt("Ownerteam",curteam)
- self.Status = "Fully captured."
- self.CapStatus = 2
- end
- end
- else
- if self.Progress < 100 then
- self.Progress = self.Progress + table.Count(self.Players)
- self.Status = "Reinforcing..."
- self.CapStatus = 3
- else
- self.Status = "Fully captured."
- self.CapStatus = 2
- end
- end
- else
- self.Status = "Under attack."
- if self.CapStatus == 1 then
- if self.Progress > 0 then
- self.Progress = self.Progress - 1
- end
- end
- end
- for k,v in pairs(self.Players) do
- umsg.Start("CapZoneData",v)
- umsg.Short(self.Ownerteam)
- umsg.Short(self.Progress)
- umsg.String(self.Status)
- umsg.End()
- end
- else
- if self.CapStatus == 1 then
- self.Progress = 0
- end
- end
- if self.Ownerteam != 0 then
- team.GetAllTeams()[self.Ownerteam].CapScore = team.GetAllTeams()[self.Ownerteam].CapScore + 1
- umsg.Start("TeamCapScore")
- umsg.Short(self.Ownerteam)
- umsg.Short(team.GetAllTeams()[self.Ownerteam].CapScore)
- umsg.End()
- end
- self:NextThink(CurTime()+0.5)
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment