Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local util_AddNetworkString = util.AddNetworkString
- local table_Random = table.Random
- local net_Receive = net.Receive
- local hook_Add = hook.Add
- local timer_Simple = timer.Simple
- local team_GetName = team.GetName
- local SetGlobalEntity = SetGlobalEntity
- local GetGlobalEntity = GetGlobalEntity
- local SetNWEntity = SetNWEntity
- local GetNWEntity = GetNWEntity
- util_AddNetworkString('hit.Accept')
- util_AddNetworkString('hit.Deny')
- util_AddNetworkString('hit.newOffer')
- util_AddNetworkString('hit.Active')
- local function AddMoney(pl)
- local amount = table_Random(cfg_Jacket_Money)
- if DarkRP.notify then
- pl:addMoney(amount)
- DarkRP.notify(pl, 4, 4,cfg_Jacket_AddMoney..DarkRP.formatMoney(amount)..'!')
- elseif rp.Notify then
- pl:AddMoney(amount)
- rp.Notify(pl, NOTIFY_GENERIC, cfg_Jacket_AddMoney..rp.FormatMoney(amount)..'!')
- end
- end
- local function Notify(pl, text)
- if DarkRP.notify then DarkRP.notify(pl, 4, 4, text) elseif rp.Notify then rp.Notify(pl, NOTIFY_GENERIC, text) end
- end
- local jacket = FindMetaTable('Player')
- function jacket:isJacket()
- return team_GetName(self:Team()) == cfg_Jacket_JobName
- end
- local checked = {}
- local function timer_check()
- local team_jacket = team.GetPlayers(TEAM_JACKET)[1]
- if not team_jacket then return end
- local pls = player.GetAll()
- if #pls <= сfg_Jacket_PlayersLimit then
- Notify(team_jacket, сfg_Jacket_Limit)
- return
- end
- local index = 1
- for i = 1, #pls do
- local pl = pls[i]
- if not pl:isJacket() then
- checked[index] = pl
- index = index+1
- end
- end
- local victim = table_Random(checked)
- if not victim:IsPlayer() then return end
- SetGlobalEntity('hit.Offer', victim)
- net.Start('hit.newOffer')
- net.WriteEntity(victim)
- net.Send(team_jacket)
- team_jacket:ConCommand('play npc/metropolice/vo/off1.wav')
- end
- timer.Create('hit.Timer', cfg_Jacket_Timer1*60, 0, function()
- if GetGlobalEntity('hit.Offer'):IsPlayer() then return end
- timer_check()
- end)
- function jacket:accept(victim)
- if not self:isJacket() then return end
- if not victim then Notify(self, cfg_Jacket_Fail) end
- self.hasHit = true
- self:SetNWEntity('hit.Target',victim)
- net.Start('hit.Active')
- net.WriteEntity(self:GetNWEntity('hit.Target'))
- net.WriteBool(true)
- net.Send(self)
- end
- function jacket:deny()
- SetGlobalEntity('hit.Offer', nil)
- timer_Simple(cfg_Jacket_Timer2, function()
- timer_check()
- end)
- end
- net_Receive('hit.Accept', function(l, pl) pl:accept(net.ReadEntity()) end)
- net_Receive('hit.Deny', function(l, pl) pl:deny() end)
- function jacket:finish(success)
- net.Start('hit.Active')
- net.WriteEntity(self:GetNWEntity('hit.Target'))
- net.WriteBool(false)
- net.Send(self)
- SetGlobalEntity('hit.Offer', nil)
- self.hasHit = false
- self:SetNWEntity('hit.Target', nil)
- self:ConCommand('play npc/metropolice/vo/off1.wav')
- end
- hook_Add('PlayerDeath', 'hit.hook.death', function(pl, wep, killer)
- if pl:isJacket() then
- pl:finish(false)
- Notify(pl, cfg_Jacket_Fail2)
- end
- local team_jacket = team.GetPlayers(TEAM_JACKET)[1]
- if team_jacket then
- if pl == team_jacket:GetNWEntity('hit.Target') and killer != team_jacket then
- team_jacket:finish(false)
- Notify(team_jacket, cfg_Jacket_Wrong)
- timer_Simple(cfg_Jacket_Timer2, function()
- timer_check()
- end)
- end
- end
- if not killer:IsPlayer() then return end
- if pl == killer:GetNWEntity('hit.Target') and killer:isJacket() and (killer ~= pl) then
- killer:finish(true)
- Notify(killer,cfg_Jacket_Success)
- AddMoney(killer)
- end
- end)
- hook_Add('PlayerDisconnected', 'hit.hook.disconnect', function(pl)
- local team_jacket = team.GetPlayers(TEAM_JACKET)[1]
- if pl == GetGlobalEntity('hit.Offer') then
- SetGlobalEntity('hit.Offer', nil)
- end
- if not team_jacket then return end
- if pl == team_jacket:GetNWEntity('hit.Target') then
- team_jacket:finish(false)
- end
- if pl == team_jacket then
- SetGlobalEntity('hit.Offer', nil)
- end
- end)
- hook_Add('OnPlayerChangedTeam', 'hit.hook.changedjob', function(pl, old, new)
- if not team_GetName(old) == cfg_Jacket_JobName then return end
- if pl.hasHit then pl:finish(false) end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement