Guest User

Untitled

a guest
Jul 25th, 2014
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.12 KB | None | 0 0
  1. function ulx.slaynr( calling_ply, target_ply, num_slay, reason, should_slaynr )
  2.     if not GetConVarString("gamemode") == "terrortown" 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 and reason ~= "" then
  42.                 chat_message = ("#A will slay #T next round for #s.")
  43.             elseif slays_left == 1 then
  44.                 chat_message = ("#A will slay #T next round.")
  45.             elseif slays_left > 1 and reason ~= "" then
  46.                 chat_message = ("#A will slay #T for the next ".. tostring(slays_left) .." rounds for #s.")
  47.             elseif slays_left > 1 then
  48.                 chat_message = ("#A will slay #T for the next ".. tostring(slays_left) .." rounds.")
  49.            
  50.             end
  51.             ulx.fancyLogAdmin( calling_ply, chat_message, target_ply, reason )
  52.         end
  53.     end
  54. end
  55. local slaynr = ulx.command( CATEGORY_NAME, "ulx slaynr", ulx.slaynr, "!slaynr" )
  56. slaynr:addParam{ type=ULib.cmds.PlayerArg }
  57. slaynr:addParam{ type=ULib.cmds.NumArg, default=1, hint="rounds", ULib.cmds.optional, ULib.cmds.round }
  58. slaynr:addParam{ type=ULib.cmds.StringArg, hint="reason",  ULib.cmds.optional}
  59. slaynr:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  60. slaynr:defaultAccess( ULib.ACCESS_ADMIN )
  61. slaynr:help( "Slays target(s) for a number of rounds" )
  62. slaynr:setOpposite( "ulx rslaynr", {_, _, _, _, true}, "!rslaynr" )
  63. --[Helper Functions]---------------------------------------------------------------------------
  64. hook.Add("TTTBeginRound", "SlayPlayersNextRound", function()
  65.     local affected_plys = {}
  66.  
  67.     for _,v in pairs(player.GetAll()) do
  68.         local slays_left = tonumber(v:GetPData("slaynr_slays")) or 0
  69.        
  70.         if v:Alive() and slays_left > 0 then
  71.            
  72.             local slays_left=slays_left -1
  73.  
  74.             if slays_left == 0 then
  75.                 v:RemovePData("slaynr_slays")
  76.                 v:RemovePData("slaynr_reason")
  77.             else                   
  78.                 v:SetPData("slaynr_slays", slays_left)
  79.             end
  80.  
  81.             v:StripWeapons()
  82.  
  83.             table.insert( affected_plys, v )
  84.            
  85.             timer.Create("check" .. v:SteamID(), 0.1, 0, function()
  86.                
  87.                 v:Kill()
  88.  
  89.                 GAMEMODE:PlayerSilentDeath(v)
  90.  
  91.                 local corpse = corpse_find(v)
  92.                 if corpse then
  93.                     v:SetNWBool("body_found", true)
  94.                     if string.find(corpse:GetModel(), "zm_", 6, true) then
  95.                         corpse:Remove()
  96.                     elseif corpse.player_ragdoll then
  97.                         corpse:Remove()
  98.                     end
  99.                 end
  100.  
  101.                 v:SetTeam(TEAM_SPEC)
  102.                 if v:IsSpec() then timer.Destroy("check" .. v:SteamID()) return end
  103.             end)
  104.  
  105.         end
  106.     end
  107.  
  108.     local slay_message
  109.     for i=1, #affected_plys do
  110.         local v = affected_plys[ i ]
  111.         local string_inbetween
  112.  
  113.         if i > 1 and #affected_plys == i then
  114.             string_inbetween=" and "
  115.         elseif i > 1 then
  116.             string_inbetween=", "
  117.         end
  118.  
  119.         string_inbetween = string_inbetween or ""
  120.         slay_message = ( ( slay_message or "") .. string_inbetween )
  121.         slay_message = ( ( slay_message or "") .. v:Nick() )
  122.     end
  123.  
  124.     local slay_message_context
  125.     if #affected_plys == 1 then slay_message_context ="was" else slay_message_context ="were" end
  126.     if #affected_plys ~= 0 then
  127.         ULib.tsay(_, slay_message .. " ".. slay_message_context .." slain.")
  128.     end
  129. end)
  130.  
  131. hook.Add("PlayerSpawn", "Inform" , function(ply)
  132.     local slays_left = tonumber(ply:GetPData("slaynr_slays")) or 0
  133.     local slay_reason = false
  134.        
  135.     if ply:Alive() and slays_left > 0 then
  136.         local chat_message = ""
  137.  
  138.         if slays_left > 0 then
  139.             chat_message = (chat_message .. "You will be slain this round")
  140.         end
  141.         if slays_left > 1 then
  142.             chat_message = (chat_message .. " and ".. (slays_left - 1) .." round(s) after the current round")
  143.         end
  144.         if slay_reason then
  145.             chat_message = (chat_message .. " for \"".. slays_reason .."\".")
  146.         else
  147.             chat_message = (chat_message .. ".")
  148.         end
  149.         ply:ChatPrint(chat_message)
  150.     end
  151. end)
Advertisement
Add Comment
Please, Sign In to add comment