Advertisement
Guest User

Untitled

a guest
May 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. function ulx.slaynr( calling_ply, target_ply, num_slay, should_slaynr )
  2. if not GetConVarString("gamemode") == "jailbreak" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  3. local affected_plys = {}
  4. local slays_left = tonumber(target_ply:GetPData("slaynr_slays")) or 0
  5. local current_slay
  6. local new_slay
  7.  
  8.  
  9. if ulx.getExclusive( target_ply, calling_ply ) then
  10. ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
  11. elseif num_slay < 0 then
  12. ULib.tsayError( calling_ply, "Invalid integer:\"" .. num_slay .. "\" specified.", true )
  13. else
  14. current_slay = tonumber(target_ply:GetPData("slaynr_slays")) or 0
  15. if not should_slaynr then
  16. new_slay = current_slay + num_slay
  17. else
  18. new_slay = current_slay - num_slay
  19. end
  20.  
  21. --local slay_reason = reason
  22. --if slay_reason == "reason" then
  23. -- slay_reason = false
  24. --end
  25.  
  26. if new_slay > 0 then
  27. target_ply:SetPData("slaynr_slays", new_slay)
  28. --target_ply:SetPData("slaynr_reason", slay_reason)
  29. else
  30. target_ply:RemovePData("slaynr_slays")
  31. --target_ply:RemovePData("slaynr_reason")
  32. end
  33.  
  34. local slays_left = tonumber(target_ply:GetPData("slaynr_slays")) or 0
  35. local slays_removed = ( current_slay - slays_left ) or 0
  36.  
  37. if slays_removed==0 then
  38. chat_message = ("#T will not be slain next round.")
  39. elseif slays_removed > 0 then
  40. chat_message = ("#A removed ".. slays_removed .." round(s) of slaying from #T.")
  41. elseif slays_left == 1 then
  42. chat_message = ("#A will slay #T next round.")
  43. elseif slays_left > 1 then
  44. chat_message = ("#A will slay #T for the next ".. tostring(slays_left) .." rounds.")
  45. end
  46. ulx.fancyLogAdmin( calling_ply, chat_message, target_ply, reason )
  47. end
  48. end
  49. end
  50. local slaynr = ulx.command( "Jailbreak", "ulx slaynr", ulx.slaynr, "!slaynr" )
  51. slaynr:addParam{ type=ULib.cmds.PlayerArg }
  52. slaynr:addParam{ type=ULib.cmds.NumArg, max=100, default=1, hint="rounds", ULib.cmds.optional, ULib.cmds.round }
  53. --slaynr:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional}
  54. slaynr:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  55. slaynr:defaultAccess( ULib.ACCESS_ADMIN )
  56. slaynr:help( "Slays target(s) for a number of rounds" )
  57. slaynr:setOpposite( "ulx rslaynr", {_, _, _, true}, "!rslaynr" )
  58. --[Helper Functions]---------------------------------------------------------------------------
  59. hook.Add("JailBreakRoundStart", "SlayPlayersNextRound", function()
  60. local affected_plys = {}
  61.  
  62. for _,v in pairs(player.GetAll()) do
  63. local slays_left = tonumber(v:GetPData("slaynr_slays")) or 0
  64.  
  65. if v:Alive() and slays_left > 0 then
  66. local slays_left=slays_left -1
  67.  
  68. if slays_left == 0 then
  69. v:RemovePData("slaynr_slays")
  70. v:RemovePData("slaynr_reason")
  71. else
  72. v:SetPData("slaynr_slays", slays_left)
  73. end
  74.  
  75. v:StripWeapons()
  76.  
  77. table.insert( affected_plys, v )
  78.  
  79. timer.Create("check" .. v:SteamID(), 0.1, 0, function() --workaround for issue with tommys damage log
  80.  
  81. v:Kill()
  82.  
  83. GAMEMODE:PlayerSilentDeath(v)
  84.  
  85. local corpse = corpse_find(v)
  86. if corpse then
  87. v:SetNWBool("body_found", true)
  88. SendFullStateUpdate()
  89.  
  90. if string.find(corpse:GetModel(), "zm_", 6, true) then
  91. corpse:Remove()
  92. elseif corpse.player_ragdoll then
  93. corpse:Remove()
  94. end
  95. end
  96.  
  97. v:SetTeam(TEAM_SPEC)
  98. if v:IsSpec() then timer.Destroy("check" .. v:SteamID()) return end
  99. end)
  100.  
  101. timer.Create("traitorcheck" .. v:SteamID(), 1, 0, function() --have to wait for gamemode before doing this
  102. if v:GetRole() == ROLE_TRAITOR then
  103. SendConfirmedTraitors( GetInnocentFilter( false ) ) -- Update innocent's list of traitors.
  104. SCORE:HandleBodyFound( v, v )
  105. end
  106. end)
  107. end
  108. end
  109.  
  110. local slay_message
  111. for i=1, #affected_plys do
  112. local v = affected_plys[ i ]
  113. local string_inbetween
  114.  
  115. if i > 1 and #affected_plys == i then
  116. string_inbetween=" and "
  117. elseif i > 1 then
  118. string_inbetween=", "
  119. end
  120.  
  121. string_inbetween = string_inbetween or ""
  122. slay_message = ( ( slay_message or "") .. string_inbetween )
  123. slay_message = ( ( slay_message or "") .. v:Nick() )
  124. end
  125.  
  126. local slay_message_context
  127. if #affected_plys == 1 then slay_message_context ="was" else slay_message_context ="were" end
  128. if #affected_plys ~= 0 then
  129. ULib.tsay(_, slay_message .. " ".. slay_message_context .." slain.")
  130. end
  131. end)
  132.  
  133. hook.Add("PlayerSpawn", "Inform" , function(ply)
  134. local slays_left = tonumber(ply:GetPData("slaynr_slays")) or 0
  135. local slay_reason = false
  136.  
  137. if ply:Alive() and slays_left > 0 then
  138. local chat_message = ""
  139.  
  140. if slays_left > 0 then
  141. chat_message = (chat_message .. "You will be slain this round")
  142. end
  143. if slays_left > 1 then
  144. chat_message = (chat_message .. " and ".. (slays_left - 1) .." round(s) after the current round")
  145. end
  146. if slay_reason then
  147. chat_message = (chat_message .. " for \"".. slays_reason .."\".")
  148. else
  149. chat_message = (chat_message .. ".")
  150. end
  151. ply:ChatPrint(chat_message)
  152. end
  153. end)
  154. --[End]----------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement