Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. local util_AddNetworkString = util.AddNetworkString
  2. local table_Random = table.Random
  3. local net_Receive = net.Receive
  4. local hook_Add = hook.Add
  5. local timer_Simple = timer.Simple
  6. local team_GetName = team.GetName
  7.  
  8. local SetGlobalEntity = SetGlobalEntity
  9. local GetGlobalEntity = GetGlobalEntity
  10. local SetNWEntity = SetNWEntity
  11. local GetNWEntity = GetNWEntity
  12.  
  13. util_AddNetworkString('hit.Accept')
  14. util_AddNetworkString('hit.Deny')
  15. util_AddNetworkString('hit.newOffer')
  16. util_AddNetworkString('hit.Active')
  17.  
  18. local function AddMoney(pl)
  19. local amount = table_Random(cfg_Jacket_Money)
  20. if DarkRP.notify then
  21. pl:addMoney(amount)
  22. DarkRP.notify(pl, 4, 4,cfg_Jacket_AddMoney..DarkRP.formatMoney(amount)..'!')
  23. elseif rp.Notify then
  24. pl:AddMoney(amount)
  25. rp.Notify(pl, NOTIFY_GENERIC, cfg_Jacket_AddMoney..rp.FormatMoney(amount)..'!')
  26. end
  27. end
  28.  
  29. local function Notify(pl, text)
  30. if DarkRP.notify then DarkRP.notify(pl, 4, 4, text) elseif rp.Notify then rp.Notify(pl, NOTIFY_GENERIC, text) end
  31. end
  32.  
  33. local jacket = FindMetaTable('Player')
  34. function jacket:isJacket()
  35. return team_GetName(self:Team()) == cfg_Jacket_JobName
  36. end
  37.  
  38. local checked = {}
  39. local function timer_check()
  40. local team_jacket = team.GetPlayers(TEAM_JACKET)[1]
  41. if not team_jacket then return end
  42. local pls = player.GetAll()
  43. if #pls <= сfg_Jacket_PlayersLimit then
  44. Notify(team_jacket, сfg_Jacket_Limit)
  45. return
  46. end
  47.  
  48. local index = 1
  49.  
  50. for i = 1, #pls do
  51. local pl = pls[i]
  52.  
  53. if not pl:isJacket() then
  54. checked[index] = pl
  55. index = index+1
  56. end
  57. end
  58.  
  59. local victim = table_Random(checked)
  60. if not victim:IsPlayer() then return end
  61.  
  62. SetGlobalEntity('hit.Offer', victim)
  63. net.Start('hit.newOffer')
  64. net.WriteEntity(victim)
  65. net.Send(team_jacket)
  66. team_jacket:ConCommand('play npc/metropolice/vo/off1.wav')
  67. end
  68.  
  69. timer.Create('hit.Timer', cfg_Jacket_Timer1*60, 0, function()
  70. if GetGlobalEntity('hit.Offer'):IsPlayer() then return end
  71. timer_check()
  72. end)
  73.  
  74. function jacket:accept(victim)
  75. if not self:isJacket() then return end
  76. if not victim then Notify(self, cfg_Jacket_Fail) end
  77. self.hasHit = true
  78. self:SetNWEntity('hit.Target',victim)
  79.  
  80. net.Start('hit.Active')
  81. net.WriteEntity(self:GetNWEntity('hit.Target'))
  82. net.WriteBool(true)
  83. net.Send(self)
  84. end
  85.  
  86. function jacket:deny()
  87. SetGlobalEntity('hit.Offer', nil)
  88.  
  89. timer_Simple(cfg_Jacket_Timer2, function()
  90. timer_check()
  91. end)
  92. end
  93.  
  94. net_Receive('hit.Accept', function(l, pl) pl:accept(net.ReadEntity()) end)
  95. net_Receive('hit.Deny', function(l, pl) pl:deny() end)
  96.  
  97. function jacket:finish(success)
  98. net.Start('hit.Active')
  99. net.WriteEntity(self:GetNWEntity('hit.Target'))
  100. net.WriteBool(false)
  101. net.Send(self)
  102.  
  103. SetGlobalEntity('hit.Offer', nil)
  104. self.hasHit = false
  105. self:SetNWEntity('hit.Target', nil)
  106. self:ConCommand('play npc/metropolice/vo/off1.wav')
  107. end
  108.  
  109. hook_Add('PlayerDeath', 'hit.hook.death', function(pl, wep, killer)
  110. if pl:isJacket() then
  111. pl:finish(false)
  112. Notify(pl, cfg_Jacket_Fail2)
  113. end
  114.  
  115. local team_jacket = team.GetPlayers(TEAM_JACKET)[1]
  116. if team_jacket then
  117. if pl == team_jacket:GetNWEntity('hit.Target') and killer != team_jacket then
  118. team_jacket:finish(false)
  119. Notify(team_jacket, cfg_Jacket_Wrong)
  120. timer_Simple(cfg_Jacket_Timer2, function()
  121. timer_check()
  122. end)
  123. end
  124. end
  125.  
  126. if not killer:IsPlayer() then return end
  127.  
  128. if pl == killer:GetNWEntity('hit.Target') and killer:isJacket() and (killer ~= pl) then
  129. killer:finish(true)
  130. Notify(killer,cfg_Jacket_Success)
  131. AddMoney(killer)
  132. end
  133. end)
  134.  
  135. hook_Add('PlayerDisconnected', 'hit.hook.disconnect', function(pl)
  136. local team_jacket = team.GetPlayers(TEAM_JACKET)[1]
  137. if pl == GetGlobalEntity('hit.Offer') then
  138. SetGlobalEntity('hit.Offer', nil)
  139. end
  140.  
  141. if not team_jacket then return end
  142.  
  143. if pl == team_jacket:GetNWEntity('hit.Target') then
  144. team_jacket:finish(false)
  145. end
  146.  
  147. if pl == team_jacket then
  148. SetGlobalEntity('hit.Offer', nil)
  149. end
  150. end)
  151.  
  152. hook_Add('OnPlayerChangedTeam', 'hit.hook.changedjob', function(pl, old, new)
  153. if not team_GetName(old) == cfg_Jacket_JobName then return end
  154. if pl.hasHit then pl:finish(false) end
  155. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement