shadowndacorner

Untitled

Sep 27th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. AddCSLuaFile( "cl_init.lua" )
  2. AddCSLuaFile( "shared.lua" )
  3.  
  4. include('shared.lua')
  5.  
  6. /*---------------------------------------------------------
  7.    Name: Initialize
  8.    Desc: First function called. Use to set up your entity
  9. ---------------------------------------------------------*/
  10. function ENT:Initialize()
  11.     self.Players = {}
  12.     self.Progress = 0
  13.     self.Ownerteam = 0
  14.     self:SetNWInt("Ownerteam",0)
  15.     self.Status = "Not captured."
  16.     self.CapStatus = 0
  17. end
  18.  
  19. function ENT:PassesTriggerFilters(ent)
  20.     return true
  21. end
  22.  
  23. function ENT:StartTouch(ent)
  24.     if ent:IsPlayer() and ent:Team() != 0 then
  25.         table.insert(self.Players,ent)
  26.         umsg.Start("CapZone",ent)
  27.             umsg.Bool(true)
  28.         umsg.End()
  29.         if table.HasValue(self.Players,ent) then
  30.             TimerMoneyAndXP(ent)
  31.         end
  32.     elseif ent:IsPlayer() then
  33.         ent:ChatPrint("Gangless cannot hold capture points...")
  34.     end
  35. end
  36.  
  37. function TimerMoneyAndXP(ply)
  38.     ply:AddMoney(10)
  39.     ply:AddExp(15)
  40.     timer.Simple(1,TimerMoneyAndXP,ply)
  41. end
  42.  
  43. function ENT:EndTouch(ent)
  44.     if ent:IsPlayer() and ent:Team() != 0 then
  45.         for k,v in pairs(self.Players) do
  46.             if v == ent then
  47.                 table.remove(self.Players,k)
  48.                 break
  49.             end
  50.         end
  51.         umsg.Start("CapZone",ent)
  52.             umsg.Bool(false)
  53.         umsg.End()
  54.     elseif ent:IsPlayer() then
  55.         ent:ChatPrint("Gangless cannot hold capture points.")
  56.     end
  57. end
  58.  
  59. function ENT:Think()
  60.     if table.Count(self.Players) > 0 then
  61.         local singleteam = true
  62.         if not (self.Players[1] and self.Players[1]:IsValid()) then table.remove(self.Players,1) return end
  63.         local curteam = self.Players[1]:Team()
  64.         local teamless = false
  65.        
  66.         for k,v in pairs(self.Players) do
  67.             if not (v and v:IsValid()) then
  68.                 table.remove(self.Players,k)
  69.             end
  70.             if v:Team() != curteam then
  71.                 singleteam = false
  72.             end
  73.         end
  74.        
  75.         if singleteam then
  76.             if curteam != self.Ownerteam then
  77.                 if self.Progress > 0 and self.CapStatus == 2 then
  78.                     self.Progress = self.Progress - table.Count(self.Players)
  79.                     self.Status = "Being compromised..."
  80.                 else
  81.                     if self.Progress < 100 then
  82.                         self.Ownerteam = 0
  83.                         self:SetNWInt("Ownerteam",0)
  84.                         self.Progress = self.Progress + table.Count(self.Players)
  85.                         self.Status = "Being captured..."
  86.                         self.CapStatus = 1
  87.                     else
  88.                         self.Progress = 100
  89.                         self.Ownerteam = curteam
  90.                         self:SetNWInt("Ownerteam",curteam)
  91.                         self.Status = "Fully captured."
  92.                         self.CapStatus = 2
  93.                     end
  94.                 end
  95.             else
  96.                 if self.Progress < 100 then
  97.                     self.Progress = self.Progress + table.Count(self.Players)
  98.                     self.Status = "Reinforcing..."
  99.                     self.CapStatus = 3
  100.                 else
  101.                     self.Status = "Fully captured."
  102.                     self.CapStatus = 2
  103.                 end
  104.             end
  105.         else
  106.             self.Status = "Under attack."
  107.             if self.CapStatus == 1 then
  108.                 if self.Progress > 0 then
  109.                     self.Progress = self.Progress - 1
  110.                 end
  111.             end
  112.         end
  113.        
  114.         for k,v in pairs(self.Players) do
  115.             umsg.Start("CapZoneData",v)
  116.                 umsg.Short(self.Ownerteam)
  117.                 umsg.Short(self.Progress)
  118.                 umsg.String(self.Status)
  119.             umsg.End()
  120.         end
  121.     else
  122.         if self.CapStatus == 1 then
  123.             self.Progress = 0
  124.         end
  125.     end
  126.    
  127.     if self.Ownerteam != 0 then
  128.         team.GetAllTeams()[self.Ownerteam].CapScore = team.GetAllTeams()[self.Ownerteam].CapScore + 1
  129.         umsg.Start("TeamCapScore")
  130.             umsg.Short(self.Ownerteam)
  131.             umsg.Short(team.GetAllTeams()[self.Ownerteam].CapScore)
  132.         umsg.End()
  133.     end
  134.    
  135.     self:NextThink(CurTime()+0.5)
  136.     return true
  137. end
  138.  
  139.  
Advertisement
Add Comment
Please, Sign In to add comment