Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.25 KB | None | 0 0
  1. local plyMeta = FindMetaTable("Player")
  2. local finishWarrantRequest
  3. local arrestedPlayers = {}
  4.  
  5. --[[---------------------------------------------------------------------------
  6. Interface functions
  7. ---------------------------------------------------------------------------]]
  8. function plyMeta:warrant(warranter, reason)
  9. if self.warranted then return end
  10. local suppressMsg = hook.Call("playerWarranted", GAMEMODE, self, warranter, reason)
  11.  
  12. self.warranted = true
  13. timer.Simple(GAMEMODE.Config.searchtime, function()
  14. if not IsValid(self) then return end
  15. self:unWarrant(warranter)
  16. end)
  17.  
  18. if suppressMsg then return end
  19.  
  20. local warranterNick = IsValid(warranter) and warranter:Nick() or DarkRP.getPhrase("disconnected_player")
  21. local centerMessage = DarkRP.getPhrase("warrant_approved", self:Nick(), reason, warranterNick)
  22. local printMessage = DarkRP.getPhrase("warrant_ordered", warranterNick, self:Nick(), reason)
  23.  
  24. for _, b in ipairs(player.GetAll()) do
  25. b:PrintMessage(HUD_PRINTCENTER, centerMessage)
  26. b:PrintMessage(HUD_PRINTCONSOLE, printMessage)
  27. end
  28.  
  29. DarkRP.notify(warranter, 0, 4, DarkRP.getPhrase("warrant_approved2"))
  30. end
  31.  
  32. function plyMeta:unWarrant(unwarranter)
  33. if not self.warranted then return end
  34.  
  35. local suppressMsg = hook.Call("playerUnWarranted", GAMEMODE, self, unwarranter)
  36.  
  37. self.warranted = false
  38.  
  39. if suppressMsg then return end
  40.  
  41. DarkRP.notify(unwarranter, 2, 4, DarkRP.getPhrase("warrant_expired", self:Nick()))
  42. end
  43.  
  44. function plyMeta:requestWarrant(suspect, actor, reason)
  45. local question = DarkRP.getPhrase("warrant_request", actor:Nick(), suspect:Nick(), reason)
  46. DarkRP.createQuestion(question, suspect:EntIndex() .. "warrant", self, 40, finishWarrantRequest, actor, suspect, reason)
  47. end
  48.  
  49. function plyMeta:wanted(actor, reason, time)
  50. local suppressMsg = hook.Call("playerWanted", DarkRP.hooks, self, actor, reason)
  51.  
  52. self:setDarkRPVar("wanted", true)
  53. self:setDarkRPVar("wantedReason", reason)
  54.  
  55. timer.Create(self:SteamID64() .. " wantedtimer", time or GAMEMODE.Config.wantedtime, 1, function()
  56. if not IsValid(self) then return end
  57. self:unWanted()
  58. end)
  59.  
  60. if suppressMsg then return end
  61.  
  62. local actorNick = IsValid(actor) and actor:Nick() or DarkRP.getPhrase("disconnected_player")
  63. local centerMessage = DarkRP.getPhrase("wanted_by_police", self:Nick(), reason, actorNick)
  64. local printMessage = DarkRP.getPhrase("wanted_by_police_print", actorNick, self:Nick(), reason)
  65.  
  66. for _, ply in ipairs(player.GetAll()) do
  67. ply:PrintMessage(HUD_PRINTCENTER, centerMessage)
  68. ply:PrintMessage(HUD_PRINTCONSOLE, printMessage)
  69. end
  70.  
  71. DarkRP.log(string.Replace(printMessage, "\n", " "), Color(0, 150, 255))
  72. end
  73.  
  74. function plyMeta:unWanted(actor)
  75. local suppressMsg = hook.Call("playerUnWanted", GAMEMODE, self, actor)
  76. self:setDarkRPVar("wanted", nil)
  77. self:setDarkRPVar("wantedReason", nil)
  78.  
  79. timer.Remove(self:SteamID64() .. " wantedtimer")
  80.  
  81. if suppressMsg then return end
  82.  
  83. local expiredMessage = IsValid(actor) and DarkRP.getPhrase("wanted_revoked", self:Nick(), actor:Nick() or "") or
  84. DarkRP.getPhrase("wanted_expired", self:Nick())
  85.  
  86. DarkRP.log(string.Replace(expiredMessage, "\n", " "), Color(0, 150, 255))
  87.  
  88. for _, ply in ipairs(player.GetAll()) do
  89. ply:PrintMessage(HUD_PRINTCENTER, expiredMessage)
  90. ply:PrintMessage(HUD_PRINTCONSOLE, expiredMessage)
  91. end
  92. end
  93.  
  94. function plyMeta:arrest(time, arrester)
  95. time = time or GAMEMODE.Config.jailtimer or 120
  96.  
  97. hook.Call("playerArrested", DarkRP.hooks, self, time, arrester)
  98. if self:InVehicle() then self:ExitVehicle() end
  99. self:setDarkRPVar("Arrested", true)
  100. arrestedPlayers[self:SteamID()] = true
  101.  
  102. -- Always get sent to jail when Arrest() is called, even when already under arrest
  103. if GAMEMODE.Config.teletojail and DarkRP.jailPosCount() ~= 0 then
  104. self:Spawn()
  105. end
  106. end
  107.  
  108. function plyMeta:unArrest(unarrester)
  109. if not self:isArrested() then return end
  110.  
  111. self:setDarkRPVar("Arrested", nil)
  112. arrestedPlayers[self:SteamID()] = nil
  113. hook.Call("playerUnArrested", DarkRP.hooks, self, unarrester)
  114. end
  115.  
  116. --[[---------------------------------------------------------------------------
  117. Chat commands
  118. ---------------------------------------------------------------------------]]
  119. local function CombineRequest(ply, args)
  120. if args == "" then
  121. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", ""))
  122. return ""
  123. end
  124.  
  125. local DoSay = function(text)
  126. if text == "" then
  127. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", ""))
  128. return
  129. end
  130.  
  131. local col = team.GetColor(ply:Team())
  132. local col2 = Color(255, 0, 0, 255)
  133. local phrase = DarkRP.getPhrase("request")
  134. local name = ply:Nick()
  135. for _, v in ipairs(player.GetAll()) do
  136. if v:isCP() or v == ply then
  137. DarkRP.talkToPerson(v, col, phrase .. " " .. name, col2, text, ply)
  138. end
  139. end
  140. end
  141. return args, DoSay
  142. end
  143. for _, cmd in ipairs{"cr", "911", "999", "112", "000"} do
  144. DarkRP.defineChatCommand(cmd, CombineRequest, 1.5)
  145. end
  146.  
  147. local function warrantCommand(ply, args)
  148. local target = DarkRP.findPlayer(args[1])
  149. local reason = table.concat(args, " ", 2)
  150.  
  151. local canRequest, message = hook.Call("canRequestWarrant", DarkRP.hooks, target, ply, reason)
  152. if not canRequest then
  153. if message then DarkRP.notify(ply, 1, 4, message) end
  154. return ""
  155. end
  156.  
  157. local Team = ply:Team()
  158. if not RPExtraTeams[Team] or not RPExtraTeams[Team].mayor then -- No need to search through all the teams if the player is a mayor
  159. local mayors = {}
  160.  
  161. for k, v in pairs(RPExtraTeams) do
  162. if v.mayor then
  163. table.Add(mayors, team.GetPlayers(k))
  164. end
  165. end
  166.  
  167. if #mayors > 0 then -- Request a warrant if there's a mayor
  168. local mayor = table.Random(mayors)
  169. mayor:requestWarrant(target, ply, reason)
  170. DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("warrant_request2", mayor:Nick()))
  171. return ""
  172. end
  173. end
  174.  
  175. target:warrant(ply, reason)
  176.  
  177. return ""
  178. end
  179. DarkRP.defineChatCommand("warrant", warrantCommand)
  180.  
  181. local function unwarrantCommand(ply, args)
  182. local target = DarkRP.findPlayer(args[1])
  183. local reason = table.concat(args, " ", 2)
  184.  
  185. local canRemove, message = hook.Call("canRemoveWarrant", DarkRP.hooks, target, ply, reason)
  186. if not canRemove then
  187. if message then DarkRP.notify(ply, 1, 4, message) end
  188. return ""
  189. end
  190.  
  191. target:unWarrant(ply, reason)
  192.  
  193. return ""
  194. end
  195. DarkRP.defineChatCommand("unwarrant", unwarrantCommand)
  196.  
  197. local function wantedCommand(ply, args)
  198. local target = DarkRP.findPlayer(args[1])
  199. local reason = table.concat(args, " ", 2)
  200.  
  201. local canWanted, message = hook.Call("canWanted", DarkRP.hooks, target, ply, reason)
  202. if not canWanted then
  203. if message then DarkRP.notify(ply, 1, 4, message) end
  204. return ""
  205. end
  206.  
  207. target:wanted(ply, reason)
  208.  
  209. return ""
  210. end
  211. DarkRP.defineChatCommand("wanted", wantedCommand)
  212.  
  213. local function unwantedCommand(ply, args)
  214. local target = DarkRP.findPlayer(args)
  215.  
  216. local canUnwant, message = hook.Call("canUnwant", DarkRP.hooks, target, ply)
  217. if not canUnwant then
  218. if message then DarkRP.notify(ply, 1, 4, message) end
  219. return ""
  220. end
  221.  
  222. target:unWanted(ply)
  223.  
  224. return ""
  225. end
  226. DarkRP.defineChatCommand("unwanted", unwantedCommand)
  227.  
  228. --[[---------------------------------------------------------------------------
  229. Admin commands
  230. ---------------------------------------------------------------------------]]
  231. local function ccArrest(ply, args)
  232. if DarkRP.jailPosCount() == 0 then
  233. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("no_jail_pos"))
  234. return
  235. end
  236.  
  237. local targets = DarkRP.findPlayers(args[1])
  238.  
  239. if not targets then
  240. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", args[1]))
  241. return
  242. end
  243.  
  244. for _, target in pairs(targets) do
  245. local length = tonumber(args[2])
  246. if length then
  247. target:arrest(length, ply)
  248. else
  249. target:arrest(nil, ply)
  250. end
  251.  
  252. if ply:EntIndex() == 0 then
  253. DarkRP.log("Console force-arrested " .. target:SteamName(), Color(0, 255, 255))
  254. else
  255. DarkRP.log(ply:Nick() .. " (" .. ply:SteamID() .. ") force-arrested " .. target:SteamName(), Color(0, 255, 255))
  256. end
  257. end
  258. end
  259. DarkRP.definePrivilegedChatCommand("arrest", "DarkRP_AdminCommands", ccArrest)
  260.  
  261. local function ccUnarrest(ply, args)
  262. local targets = DarkRP.findPlayers(args[1])
  263.  
  264. if not targets then
  265. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", args[1]))
  266. return
  267. end
  268.  
  269. for _, target in pairs(targets) do
  270. target:unArrest(ply)
  271. if not target:Alive() then target:Spawn() end
  272.  
  273. if ply:EntIndex() == 0 then
  274. DarkRP.log("Console force-unarrested " .. target:SteamName(), Color(0, 255, 255))
  275. else
  276. DarkRP.log(ply:Nick() .. " (" .. ply:SteamID() .. ") force-unarrested " .. target:SteamName(), Color(0, 255, 255))
  277. end
  278. end
  279. end
  280. DarkRP.definePrivilegedChatCommand("unarrest", "DarkRP_AdminCommands", ccUnarrest)
  281.  
  282. --[[---------------------------------------------------------------------------
  283. Callback functions
  284. ---------------------------------------------------------------------------]]
  285. function finishWarrantRequest(choice, mayor, initiator, suspect, reason)
  286. if not tobool(choice) then
  287. DarkRP.notify(initiator, 1, 4, DarkRP.getPhrase("warrant_denied", mayor:Nick()))
  288. return
  289. end
  290. if IsValid(suspect) then
  291. suspect:warrant(initiator, reason)
  292. end
  293. end
  294.  
  295. --[[---------------------------------------------------------------------------
  296. Hooks
  297. ---------------------------------------------------------------------------]]
  298.  
  299. function DarkRP.hooks:canArrest(arrester, arrestee)
  300. if IsValid(arrestee) and arrestee:IsPlayer() and arrestee:isCP() and not GAMEMODE.Config.cpcanarrestcp then
  301. return false, DarkRP.getPhrase("cant_arrest_other_cp")
  302. end
  303.  
  304. if not GAMEMODE.Config.npcarrest and arrestee:IsNPC() then
  305. return false, DarkRP.getPhrase("unable", "arrest", "NPC")
  306. end
  307.  
  308. if GAMEMODE.Config.needwantedforarrest and not arrestee:IsNPC() and not arrestee:getDarkRPVar("wanted") then
  309. return false, DarkRP.getPhrase("must_be_wanted_for_arrest")
  310. end
  311.  
  312. if arrestee:IsPlayer() and arrestee.FAdmin_GetGlobal and arrestee:FAdmin_GetGlobal("fadmin_jailed") then
  313. return false, DarkRP.getPhrase("cant_arrest_fadmin_jailed")
  314. end
  315.  
  316. local jpc = DarkRP.jailPosCount()
  317.  
  318. if not jpc or jpc == 0 then
  319. return false, DarkRP.getPhrase("cant_arrest_no_jail_pos")
  320. end
  321.  
  322. if arrestee.Babygod then
  323. return false, DarkRP.getPhrase("cant_arrest_spawning_players")
  324. end
  325.  
  326. return true
  327. end
  328.  
  329. function DarkRP.hooks:playerArrested(ply, time, arrester)
  330. if ply:isWanted() then ply:unWanted(arrester) end
  331. ply:setDarkRPVar("HasGunlicense", nil)
  332.  
  333. ply:StripWeapons()
  334. ply:StripAmmo()
  335.  
  336. if ply:isArrested() then return end -- hasn't been arrested before
  337.  
  338. ply:PrintMessage(HUD_PRINTCENTER, DarkRP.getPhrase("youre_arrested", time))
  339.  
  340. local phrase = DarkRP.getPhrase("hes_arrested", ply:Nick(), time)
  341. for _, v in ipairs(player.GetAll()) do
  342. if v == ply then continue end
  343. v:PrintMessage(HUD_PRINTCENTER, phrase)
  344. end
  345.  
  346. local steamID = ply:SteamID()
  347. timer.Create(ply:SteamID64() .. "jailtimer", time, 1, function()
  348. if IsValid(ply) then ply:unArrest() end
  349. arrestedPlayers[steamID] = nil
  350. end)
  351. umsg.Start("GotArrested", ply)
  352. umsg.Float(time)
  353. umsg.End()
  354. end
  355.  
  356. function DarkRP.hooks:playerUnArrested(ply, actor)
  357. if ply:InVehicle() then ply:ExitVehicle() end
  358.  
  359. if ply.Sleeping then
  360. DarkRP.toggleSleep(ply, "force")
  361. end
  362.  
  363. if not ply:Alive() and not GAMEMODE.Config.respawninjail then
  364. ply.NextSpawnTime = CurTime()
  365. end
  366.  
  367. gamemode.Call("PlayerLoadout", ply)
  368. if GAMEMODE.Config.telefromjail then
  369. local ent, pos = hook.Call("PlayerSelectSpawn", GAMEMODE, ply)
  370. timer.Simple(0, function() if IsValid(ply) then ply:SetPos(pos or ent:GetPos()) end end) -- workaround for SetPos in weapon event bug
  371. end
  372.  
  373. timer.Remove(ply:SteamID64() .. "jailtimer")
  374. DarkRP.notifyAll(0, 4, DarkRP.getPhrase("hes_unarrested", ply:Nick()))
  375. end
  376.  
  377. hook.Add("PlayerInitialSpawn", "Arrested", function(ply)
  378. if not arrestedPlayers[ply:SteamID()] then return end
  379. local time = GAMEMODE.Config.jailtimer
  380. -- Delay the actual arrest by a single frame to allow
  381. -- the player to initialise
  382. timer.Simple(0, function()
  383. -- In case the timer ended right this tick
  384. if not IsValid(ply) or not arrestedPlayers[ply:SteamID()] then return end
  385.  
  386. ply:arrest(time)
  387. end)
  388. DarkRP.notify(ply, 0, 5, DarkRP.getPhrase("jail_punishment", time))
  389. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement