shadowndacorner

fixed

Oct 10th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 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.         //ent:ChatPrint("Beginning cap thing...")
  26.         table.insert(self.Players,ent)
  27.         umsg.Start("CapZone",ent)
  28.             umsg.Bool(true)
  29.         umsg.End()
  30.         if table.HasValue(self.Players,ent) then
  31.             //TimerMoneyAndXP(ent)
  32.             timer.Create(ent:SteamID().."_capxptimer", 2, 0, TimerMoneyAndXP,ent,self)
  33.         end
  34.     elseif ent:IsPlayer() then
  35.         ent:ChatPrint("Gangless cannot hold capture points...")
  36.     end
  37. end
  38.  
  39. function TimerMoneyAndXP(ply,ent)
  40.     if table.HasValue(ent.Players, ply) and ent:GetNWInt("Ownerteam")!=ply:Team() then
  41.         ply:AddMoney(100)
  42.         ply:AddExp(21)
  43.     else
  44.         timer.Destroy(ply:SteamID().."_capxptimer")
  45.     end
  46. end
  47.  
  48. function ENT:EndTouch(ent)
  49.     if ent:IsPlayer() and ent:Team() != 0 then
  50.         //ent:ChatPrint("Ending touch thing")
  51.         for k,v in pairs(self.Players) do
  52.             if v == ent then
  53.                 table.remove(self.Players,k)
  54.                 break
  55.             end
  56.         end
  57.         umsg.Start("CapZone",ent)
  58.             umsg.Bool(false)
  59.         umsg.End()
  60. //      if table.HasValue(self.Players,ent) then
  61. //          timer.Destroy(ent:SteamID().."_capxptimer")
  62. //      end
  63.     elseif ent:IsPlayer() then
  64.         ent:ChatPrint("Gangless cannot hold capture points.")
  65.     end
  66. end
  67.  
  68. function ENT:Think()
  69.     if table.Count(self.Players) > 0 then
  70.         local singleteam = true
  71.         if not (self.Players[1] and self.Players[1]:IsValid()) then table.remove(self.Players,1) return end
  72.         local curteam = self.Players[1]:Team()
  73.         local teamless = false
  74.        
  75.         for k,v in pairs(self.Players) do
  76.             if not (v and v:IsValid()) then
  77.                 table.remove(self.Players,k)
  78.             end
  79.             if v:Team() != curteam then
  80.                 singleteam = false
  81.             end
  82.         end
  83.        
  84.         if singleteam then
  85.             if curteam != self.Ownerteam then
  86.                 if self.Progress > 0 and self.CapStatus == 2 then
  87.                     self.Progress = self.Progress - table.Count(self.Players)
  88.                     self.Status = "Being compromised..."
  89.                 else
  90.                     if self.Progress < 100 then
  91.                         self.Ownerteam = 0
  92.                         self:SetNWInt("Ownerteam",0)
  93.                         self.Progress = self.Progress + table.Count(self.Players)
  94.                         self.Status = "Being captured..."
  95.                         self.CapStatus = 1
  96.                     else
  97.                         self.Progress = 100
  98.                         self.Ownerteam = curteam
  99.                         self:SetNWInt("Ownerteam",curteam)
  100.                         self.Status = "Fully captured."
  101.                         self.CapStatus = 2
  102.                     end
  103.                 end
  104.             else
  105.                 if self.Progress < 100 then
  106.                     self.Progress = self.Progress + table.Count(self.Players)
  107.                     self.Status = "Reinforcing..."
  108.                     self.CapStatus = 3
  109.                 else
  110.                     self.Status = "Fully captured."
  111.                     self.CapStatus = 2
  112.                 end
  113.             end
  114.         else
  115.             self.Status = "Under attack."
  116.             if self.CapStatus == 1 then
  117.                 if self.Progress > 0 then
  118.                     self.Progress = self.Progress - 1
  119.                 end
  120.             end
  121.         end
  122.        
  123.         for k,v in pairs(self.Players) do
  124.             umsg.Start("CapZoneData",v)
  125.                 umsg.Short(self.Ownerteam)
  126.                 umsg.Short(self.Progress)
  127.                 umsg.String(self.Status)
  128.             umsg.End()
  129.         end
  130.     else
  131.         if self.CapStatus == 1 then
  132.             self.Progress = 0
  133.         end
  134.     end
  135.    
  136.     if self.Ownerteam != 0 then
  137.         team.GetAllTeams()[self.Ownerteam].CapScore = team.GetAllTeams()[self.Ownerteam].CapScore + 1
  138.         umsg.Start("TeamCapScore")
  139.             umsg.Short(self.Ownerteam)
  140.             umsg.Short(team.GetAllTeams()[self.Ownerteam].CapScore)
  141.         umsg.End()
  142.     end
  143.    
  144.     self:NextThink(CurTime()+0.5)
  145.     return true
  146. end
  147.  
  148.  
Advertisement
Add Comment
Please, Sign In to add comment