Aek177

ulx admin

Jun 1st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.99 KB | None | 0 0
  1. --[=[-------------------------------------------------------------------------------------------
  2. ║ Trouble in Terrorist Town Commands ║
  3. ║ By: Skillz and Bender180 ║
  4. ║ ╔═════════╗╔═════════╗╔═════════╗ ║
  5. ║ ║ ╔═╗ ╔═╗ ║║ ╔═╗ ╔═╗ ║║ ╔═╗ ╔═╗ ║ ║
  6. ║ ╚═╝ ║ ║ ╚═╝╚═╝ ║ ║ ╚═╝╚═╝ ║ ║ ╚═╝ ║
  7. ║──────────────────────────────────║ ║────────║ ║────────║ ║───────────────────────────────────║
  8. ║──────────────────────────────────║ ║────────║ ║────────║ ║───────────────────────────────────║
  9. ║──────────────────────────────────╚═╝────────╚═╝────────╚═╝───────────────────────────────────║
  10. ║ All code included is completely original or extracted ║
  11. ║ from the base ttt files that are provided with the ttt gamemode. ║
  12. ║ ║
  13. ---------------------------------------------------------------------------------------------]=]
  14. local CATEGORY_NAME = "TTT Admin"
  15. local gamemode_error = "The current gamemode is not trouble in terrorist town!"
  16.  
  17.  
  18.  
  19. --[Ulx Completes]------------------------------------------------------------------------------
  20. ulx.target_role = {}
  21. function updateRoles()
  22. table.Empty( ulx.target_role )
  23.  
  24. table.insert(ulx.target_role,"traitor")
  25. table.insert(ulx.target_role,"detective")
  26. table.insert(ulx.target_role,"innocent")
  27. end
  28. hook.Add( ULib.HOOK_UCLCHANGED, "ULXRoleNamesUpdate", updateRoles )
  29. updateRoles()
  30. --[End]----------------------------------------------------------------------------------------
  31.  
  32.  
  33.  
  34. --[Global Helper Functions][Used by more than one command.]------------------------------------
  35. --[[send_messages][Sends messages to player(s)]
  36. @param {[PlayerObject]} v [The player(s) to send the message to.]
  37. @param {[String]} message [The message that will be sent.]
  38. --]]
  39. function send_messages(v, message)
  40. if type(v) == "Players" then
  41. v:ChatPrint(message)
  42. elseif type(v) == "table" then
  43. for i=1, #v do
  44. v[i]:ChatPrint(message)
  45. end
  46. end
  47. end
  48.  
  49. --[[corpse_find][Finds the corpse of a given player.]
  50. @param {[PlayerObject]} v [The player that to find the corpse for.]
  51. --]]
  52. function corpse_find(v)
  53. for _, ent in pairs( ents.FindByClass( "prop_ragdoll" )) do
  54. if ent.uqid == v:UniqueID() and IsValid(ent) then
  55. return ent or false
  56. end
  57. end
  58. end
  59.  
  60. --[[corpse_remove][removes the corpse given.]
  61. @param {[Ragdoll]} corpse [The corpse to be removed.]
  62. --]]
  63. function corpse_remove(corpse)
  64. CORPSE.SetFound(corpse, false)
  65. if string.find(corpse:GetModel(), "zm_", 6, true) then
  66. player.GetByUniqueID( corpse.uqid ):SetNWBool( "body_found", false )
  67. corpse:Remove()
  68. SendFullStateUpdate()
  69. elseif corpse.player_ragdoll then
  70. player.GetByUniqueID( corpse.uqid ):SetNWBool( "body_found", false )
  71. corpse:Remove()
  72. SendFullStateUpdate()
  73. end
  74. end
  75.  
  76. --[[corpse_identify][identifies the given corpse.]
  77. @param {[Ragdoll]} corpse [The corpse to be identified.]
  78. --]]
  79. function corpse_identify(corpse)
  80. if corpse then
  81. local ply = player.GetByUniqueID(corpse.uqid)
  82. ply:SetNWBool("body_found", true)
  83. CORPSE.SetFound(corpse, true)
  84. end
  85. end
  86. --[End]----------------------------------------------------------------------------------------
  87.  
  88.  
  89.  
  90.  
  91. --[Force role]---------------------------------------------------------------------------------
  92. --[[ulx.force][Forces <target(s)> to become a specified role.]
  93. @param {[PlayerObject]} calling_ply [The player who used the command.]
  94. @param {[PlayerObject]} target_plys [The player(s) who will have the effects of the command applied to them.]
  95. @param {[Number]} target_role [The role that target player(s) will have there role set to.]
  96. @param {[Boolean]} should_silent [Hidden, determines weather the output will be silent or not.]
  97. --]]
  98. --[[function ulx.slaynr( calling_ply, target_ply, num_slay, should_slaynr )
  99. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  100. local affected_plys = {}
  101. local slays_left = tonumber(target_ply:GetPData("slaynr_slays")) or 0
  102. local current_slay
  103. local new_slay
  104.  
  105.  
  106. if ulx.getExclusive( target_ply, calling_ply ) then
  107. ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
  108. elseif num_slay < 0 then
  109. ULib.tsayError( calling_ply, "Invalid integer:\"" .. num_slay .. "\" specified.", true )
  110. else
  111. current_slay = tonumber(target_ply:GetPData("slaynr_slays")) or 0
  112. if not should_slaynr then
  113. new_slay = current_slay + num_slay
  114. else
  115. new_slay = current_slay - num_slay
  116. end
  117.  
  118. --local slay_reason = reason
  119. --if slay_reason == "reason" then
  120. -- slay_reason = false
  121. --end
  122.  
  123. if new_slay > 0 then
  124. target_ply:SetPData("slaynr_slays", new_slay)
  125. --target_ply:SetPData("slaynr_reason", slay_reason)
  126. else
  127. target_ply:RemovePData("slaynr_slays")
  128. --target_ply:RemovePData("slaynr_reason")
  129. end
  130.  
  131. local slays_left = tonumber(target_ply:GetPData("slaynr_slays")) or 0
  132. local slays_removed = ( current_slay - slays_left ) or 0
  133.  
  134. if slays_removed==0 then
  135. chat_message = ("#T will not be slain next round.")
  136. elseif slays_removed > 0 then
  137. chat_message = ("#A removed ".. slays_removed .." round(s) of slaying from #T.")
  138. elseif slays_left == 1 then
  139. chat_message = ("#A will slay #T next round.")
  140. elseif slays_left > 1 then
  141. chat_message = ("#A will slay #T for the next ".. tostring(slays_left) .." rounds.")
  142. end
  143. ulx.fancyLogAdmin( calling_ply, chat_message, target_ply, reason )
  144. end
  145. end
  146. end
  147. local slaynr = ulx.command( CATEGORY_NAME, "ulx slaynr", ulx.slaynr, "!slaynr" )
  148. slaynr:addParam{ type=ULib.cmds.PlayerArg }
  149. slaynr:addParam{ type=ULib.cmds.NumArg, max=100, default=1, hint="rounds", ULib.cmds.optional, ULib.cmds.round }
  150. --slaynr:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional}
  151. slaynr:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  152. slaynr:defaultAccess( ULib.ACCESS_ADMIN )
  153. slaynr:help( "Slays target(s) for a number of rounds" )
  154. slaynr:setOpposite( "ulx rslaynr", {_, _, _, true}, "!rslaynr" )
  155. --[Helper Functions]---------------------------------------------------------------------------
  156. hook.Add("TTTBeginRound", "SlayPlayersNextRound", function()
  157. local affected_plys = {}
  158.  
  159. for _,v in pairs(player.GetAll()) do
  160. local slays_left = tonumber(v:GetPData("slaynr_slays")) or 0
  161.  
  162. if v:Alive() and slays_left > 0 then
  163. local slays_left=slays_left -1
  164.  
  165. if slays_left == 0 then
  166. v:RemovePData("slaynr_slays")
  167. v:RemovePData("slaynr_reason")
  168. else
  169. v:SetPData("slaynr_slays", slays_left)
  170. end
  171.  
  172. v:StripWeapons()
  173.  
  174. table.insert( affected_plys, v )
  175.  
  176. timer.Create("check" .. v:SteamID(), 0.1, 0, function() --workaround for issue with tommys damage log
  177.  
  178. v:Kill()
  179.  
  180. GAMEMODE:PlayerSilentDeath(v)
  181.  
  182. local corpse = corpse_find(v)
  183. if corpse then
  184. v:SetNWBool("body_found", true)
  185. SendFullStateUpdate()
  186.  
  187. if string.find(corpse:GetModel(), "zm_", 6, true) then
  188. corpse:Remove()
  189. elseif corpse.player_ragdoll then
  190. corpse:Remove()
  191. end
  192. end
  193.  
  194. v:SetTeam(TEAM_SPEC)
  195. if v:IsSpec() then timer.Destroy("check" .. v:SteamID()) return end
  196. end)
  197.  
  198. timer.Create("traitorcheck" .. v:SteamID(), 1, 0, function() --have to wait for gamemode before doing this
  199. if v:GetRole() == ROLE_TRAITOR then
  200. SendConfirmedTraitors( GetInnocentFilter( false ) ) -- Update innocent's list of traitors.
  201. SCORE:HandleBodyFound( v, v )
  202. end
  203. end)
  204. end
  205. end
  206.  
  207. local slay_message
  208. for i=1, #affected_plys do
  209. local v = affected_plys[ i ]
  210. local string_inbetween
  211.  
  212. if i > 1 and #affected_plys == i then
  213. string_inbetween=" and "
  214. elseif i > 1 then
  215. string_inbetween=", "
  216. end
  217.  
  218. string_inbetween = string_inbetween or ""
  219. slay_message = ( ( slay_message or "") .. string_inbetween )
  220. slay_message = ( ( slay_message or "") .. v:Nick() )
  221. end
  222.  
  223. local slay_message_context
  224. if #affected_plys == 1 then slay_message_context ="was" else slay_message_context ="were" end
  225. if #affected_plys ~= 0 then
  226. ULib.tsay(_, slay_message .. " ".. slay_message_context .." slain.")
  227. end
  228. end)
  229.  
  230. hook.Add("PlayerSpawn", "Inform" , function(ply)
  231. local slays_left = tonumber(ply:GetPData("slaynr_slays")) or 0
  232. local slay_reason = false
  233.  
  234. if ply:Alive() and slays_left > 0 then
  235. local chat_message = ""
  236.  
  237. if slays_left > 0 then
  238. chat_message = (chat_message .. "You will be slain this round")
  239. end
  240. if slays_left > 1 then
  241. chat_message = (chat_message .. " and ".. (slays_left - 1) .." round(s) after the current round")
  242. end
  243. if slay_reason then
  244. chat_message = (chat_message .. " for \"".. slays_reason .."\".")
  245. else
  246. chat_message = (chat_message .. ".")
  247. end
  248. ply:ChatPrint(chat_message)
  249. end
  250. end)]]
  251.  
  252. --[End]----------------------------------------------------------------------------------------
  253.  
  254.  
  255. --[Force role]---------------------------------------------------------------------------------
  256. --[[ulx.force][Forces <target(s)> to become a specified role.]
  257. @param {[PlayerObject]} calling_ply [The player who used the command.]
  258. @param {[PlayerObject]} target_plys [The player(s) who will have the effects of the command applied to them.]
  259. @param {[Number]} target_role [The role that target player(s) will have there role set to.]
  260. @param {[Boolean]} should_silent [Hidden, determines weather the output will be silent or not.]
  261. --]]
  262. function ulx.force( calling_ply, target_plys, target_role, should_silent )
  263. ULib.tsayError(calling_ply, "This command has been disabled!", true)
  264. /*if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  265.  
  266. local affected_plys = {}
  267. local starting_credits=GetConVarNumber("ttt_credits_starting")
  268.  
  269. local role
  270. local role_grammar
  271. local role_string
  272. local role_credits
  273.  
  274. if target_role == "traitor" or target_role == "t" then role, role_grammar, role_string, role_credits = ROLE_TRAITOR, "a ", "traitor", starting_credits end
  275. if target_role == "detective" or target_role == "d" then role, role_grammar, role_string, role_credits = ROLE_DETECTIVE, "a ", "detective", starting_credits end
  276. if target_role == "innocent" or target_role == "i" then role, role_grammar, role_string, role_credits = ROLE_INNOCENT, "an ", "innocent", 0 end
  277.  
  278. for i=1, #target_plys do
  279. local v = target_plys[ i ]
  280. local current_role = v:GetRole()
  281.  
  282. if ulx.getExclusive( v, calling_ply ) then
  283. ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
  284. elseif GetRoundState() == 1 or GetRoundState() == 2 then
  285. ULib.tsayError( calling_ply, "The round has not begun!", true )
  286. elseif role == nil then
  287. ULib.tsayError( calling_ply, "Invalid role :\"" .. target_role .. "\" specified", true )
  288. elseif not v:Alive() then
  289. ULib.tsayError( calling_ply, v:Nick() .. " is dead!", true )
  290. elseif current_role == role then
  291. ULib.tsayError( calling_ply, v:Nick() .. " is already " .. role_string, true )
  292. else
  293. v:ResetEquipment()
  294. RemoveLoadoutWeapons(v)
  295. RemoveBoughtWeapons(v)
  296.  
  297. v:SetRole(role)
  298. v:SetCredits(role_credits)
  299. SendFullStateUpdate()
  300.  
  301. GiveLoadoutItems(v)
  302. GiveLoadoutWeapons(v)
  303.  
  304. table.insert( affected_plys, v )
  305. end
  306. end
  307. ulx.fancyLogAdmin( calling_ply, should_silent, "#A forced #T to become the role of " .. role_grammar .."#s.", affected_plys, role_string )
  308. send_messages(affected_plys, "Your role has been set to " .. role_string .. "." )
  309. end*/
  310. end
  311. local force = ulx.command( CATEGORY_NAME, "ulx force", ulx.force, "!force" )
  312. force:addParam{ type=ULib.cmds.PlayersArg }
  313. force:addParam{ type=ULib.cmds.StringArg, completes=ulx.target_role, hint="Role" }
  314. force:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  315. force:defaultAccess( ULib.ACCESS_SUPERADMIN )
  316. force:setOpposite( "ulx sforce", {_, _, _, true}, "!sforce", true )
  317. force:help( "Force <target(s)> to become a specified role." )
  318.  
  319. --[Helper Functions]---------------------------------------------------------------------------
  320. --[[GetLoadoutWeapons][Returns the loadout weapons ]
  321. @param {[Number]} r [The role of the loadout weapons to be returned]
  322. @return {[table]} [A table of loadout weapons for the given role.]
  323. --]]
  324. function GetLoadoutWeapons(r)
  325. local tbl = {
  326. [ROLE_INNOCENT] = {},
  327. [ROLE_TRAITOR] = {},
  328. [ROLE_DETECTIVE]= {}
  329. };
  330. for k, w in pairs(weapons.GetList()) do
  331. if w and type(w.InLoadoutFor) == "table" then
  332. for _, wrole in pairs(w.InLoadoutFor) do
  333. table.insert(tbl[wrole], WEPS.GetClass(w))
  334. end
  335. end
  336. end
  337. return tbl[r]
  338. end
  339.  
  340. --[[RemoveBoughtWeapons][Removes previously bought weapons from the shop.]
  341. @param {[PlayerObject]} ply [The player who will have their bought weapons removed.]
  342. --]]
  343. function RemoveBoughtWeapons(ply)
  344. for _, wep in pairs(weapons.GetList()) do
  345. local wep_class = WEPS.GetClass(wep)
  346. if wep and type(wep.CanBuy) == "table" then
  347. for _, weprole in pairs(wep.CanBuy) do
  348. if weprole == ply:GetRole() and ply:HasWeapon(wep_class) then
  349. ply:StripWeapon(wep_class)
  350. end
  351. end
  352. end
  353. end
  354. end
  355.  
  356. --[[RemoveLoadoutWeapons][Removes all loadout weapons for the given player.]
  357. @param {[PlayerObject]} ply [The player who will have their loadout weapons removed.]
  358. --]]
  359. function RemoveLoadoutWeapons(ply)
  360. local weps = GetLoadoutWeapons( GetRoundState() == ROUND_PREP and ROLE_INNOCENT or ply:GetRole() )
  361. for _, cls in pairs(weps) do
  362. if ply:HasWeapon(cls) then
  363. ply:StripWeapon(cls)
  364. end
  365. end
  366. end
  367.  
  368. --[[GiveLoadoutWeapons][Gives the loadout weapons for that player.]
  369. @param {[PlayerObject]} ply [The player who will have their loadout weapons given.]
  370. --]]
  371. function GiveLoadoutWeapons(ply)
  372. local r = GetRoundState() == ROUND_PREP and ROLE_INNOCENT or ply:GetRole()
  373. local weps = GetLoadoutWeapons(r)
  374. if not weps then return end
  375.  
  376. for _, cls in pairs(weps) do
  377. if not ply:HasWeapon(cls) then
  378. ply:Give(cls)
  379. end
  380. end
  381. end
  382.  
  383. --[[GiveLoadoutItems][Gives the default loadout items for that role.]
  384. @param {[PlayerObject]} ply [The player who the equipment will be given to.]
  385. --]]
  386. function GiveLoadoutItems(ply)
  387. local items = EquipmentItems[ply:GetRole()]
  388. if items then
  389. for _, item in pairs(items) do
  390. if item.loadout and item.id then
  391. ply:GiveEquipmentItem(item.id)
  392. end
  393. end
  394. end
  395. end
  396. --[End]----------------------------------------------------------------------------------------
  397.  
  398.  
  399.  
  400. --[Respawn]------------------------------------------------------------------------------------
  401. --[[ulx.respawn][Respawns <target(s)>]
  402. @param {[PlayerObject]} calling_ply [The player who used the command.]
  403. @param {[PlayerObject]} target_plys [The player(s) who will have the effects of the command applied to them.]
  404. @param {[Boolean]} should_silent [Hidden, determines weather the output will be silent or not.]
  405. --]]
  406. function ulx.respawn( calling_ply, target_plys, should_silent )
  407. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  408. local affected_plys = {}
  409.  
  410. for i=1, #target_plys do
  411. local v = target_plys[ i ]
  412.  
  413. if ulx.getExclusive( v, calling_ply ) then
  414. ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
  415. elseif GetRoundState() == 1 then
  416. ULib.tsayError( calling_ply, "Waiting for players!", true )
  417.  
  418. elseif v:Alive() and v:IsSpec() then -- players arent really dead when they are spectating, we need to handle that correctly
  419. timer.Destroy("traitorcheck" .. v:SteamID())
  420. v:ConCommand("ttt_spectator_mode 0") -- just incase they are in spectator mode take them out of it
  421. timer.Create("respawndelay", 0.1, 0, function() --seems to be a slight delay from when you leave spec and when you can spawn this should get us around that
  422. local corpse = corpse_find(v) -- run the normal respawn code now
  423. if corpse then corpse_remove(corpse) end
  424.  
  425. v:SpawnForRound( true )
  426. v:SetCredits( ( (v:GetRole() == ROLE_INNOCENT) and 0 ) or GetConVarNumber("ttt_credits_starting") )
  427.  
  428. table.insert( affected_plys, v )
  429.  
  430. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned #T!", affected_plys )
  431. send_messages(affected_plys, "You have been respawned.")
  432.  
  433. if v:Alive() then timer.Destroy("respawndelay") return end
  434. end)
  435.  
  436. elseif v:Alive() then
  437. ULib.tsayError( calling_ply, v:Nick() .. " is already alive!", true )
  438. else
  439. timer.Destroy("traitorcheck" .. v:SteamID())
  440. local corpse = corpse_find(v)
  441. if corpse then corpse_remove(corpse) end
  442.  
  443. v:SpawnForRound( true )
  444. v:SetCredits( ( (v:GetRole() == ROLE_INNOCENT) and 0 ) or GetConVarNumber("ttt_credits_starting") )
  445.  
  446. table.insert( affected_plys, v )
  447. end
  448. end
  449. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned #T!", affected_plys )
  450. send_messages(affected_plys, "You have been respawned.")
  451. end
  452. end
  453. local respawn = ulx.command( CATEGORY_NAME, "ulx respawn", ulx.respawn, "!respawn")
  454. respawn:addParam{ type=ULib.cmds.PlayersArg }
  455. respawn:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  456. respawn:defaultAccess( ULib.ACCESS_SUPERADMIN )
  457. respawn:setOpposite( "ulx srespawn", {_, _, true}, "!srespawn", true )
  458. respawn:help( "Respawns <target(s)>." )
  459. --[End]----------------------------------------------------------------------------------------
  460.  
  461.  
  462.  
  463. --[Respawn teleport]---------------------------------------------------------------------------
  464. --[[ulx.respawntp][Respawns <target(s)>]
  465. @param {[PlayerObject]} calling_ply [The player who used the command.]
  466. @param {[PlayerObject]} target_ply [The player who will have the effects of the command applied to them.]
  467. @param {[Boolean]} should_silent [Hidden, determines weather the output will be silent or not.]
  468. --]]
  469. function ulx.respawntp( calling_ply, target_ply, should_silent )
  470. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  471.  
  472. local affected_ply = {}
  473. if not calling_ply:IsValid() then
  474. Msg( "You are the console, you can't teleport or teleport others since you can't see the world!\n" )
  475. return
  476. elseif ulx.getExclusive( target_ply, calling_ply ) then
  477. ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
  478. elseif GetRoundState() == 1 then
  479. ULib.tsayError( calling_ply, "Waiting for players!", true )
  480.  
  481. elseif target_ply:Alive() and target_ply:IsSpec() then
  482. timer.Destroy("traitorcheck" .. target_ply:SteamID())
  483. target_ply:ConCommand("ttt_spectator_mode 0")
  484. timer.Create("respawntpdelay", 0.1, 0, function() --have to wait for gamemode before doing this
  485. local t = {}
  486. t.start = calling_ply:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  487. t.endpos = calling_ply:GetPos() + calling_ply:EyeAngles():Forward() * 16384
  488. t.filter = target_ply
  489. if target_ply ~= calling_ply then
  490. t.filter = { target_ply, calling_ply }
  491. end
  492. local tr = util.TraceEntity( t, target_ply )
  493.  
  494. local pos = tr.HitPos
  495.  
  496. local corpse = corpse_find(target_ply)
  497. if corpse then corpse_remove(corpse) end
  498.  
  499. target_ply:SpawnForRound( true )
  500. target_ply:SetCredits( ((target_ply:GetRole() == ROLE_INNOCENT) and 0) or GetConVarNumber("ttt_credits_starting") )
  501.  
  502. target_ply:SetPos( pos )
  503. table.insert( affected_ply, target_ply )
  504.  
  505. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned and teleported #T!", affected_ply )
  506. send_messages(target_ply, "You have been respawned and teleported.")
  507.  
  508. if target_ply:Alive() then timer.Destroy("respawntpdelay") return end
  509. end)
  510.  
  511. elseif target_ply:Alive() then
  512. ULib.tsayError( calling_ply, target_ply:Nick() .. " is already alive!", true )
  513. else
  514. timer.Destroy("traitorcheck" .. target_ply:SteamID())
  515. local t = {}
  516. t.start = calling_ply:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  517. t.endpos = calling_ply:GetPos() + calling_ply:EyeAngles():Forward() * 16384
  518. t.filter = target_ply
  519. if target_ply ~= calling_ply then
  520. t.filter = { target_ply, calling_ply }
  521. end
  522. local tr = util.TraceEntity( t, target_ply )
  523.  
  524. local pos = tr.HitPos
  525.  
  526. local corpse = corpse_find(target_ply)
  527. if corpse then corpse_remove(corpse) end
  528.  
  529. target_ply:SpawnForRound( true )
  530. target_ply:SetCredits( ((target_ply:GetRole() == ROLE_INNOCENT) and 0) or GetConVarNumber("ttt_credits_starting") )
  531.  
  532. target_ply:SetPos( pos )
  533. table.insert( affected_ply, target_ply )
  534. end
  535. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned and teleported #T!", affected_ply )
  536. send_messages(affected_plys, "You have been respawned and teleported.")
  537. end
  538. end
  539. local respawntp = ulx.command( CATEGORY_NAME, "ulx respawntp", ulx.respawntp, "!respawntp")
  540. respawntp:addParam{ type=ULib.cmds.PlayerArg }
  541. respawntp:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  542. respawntp:defaultAccess( ULib.ACCESS_SUPERADMIN )
  543. respawntp:setOpposite( "ulx srespawntp", {_, _, true}, "!srespawntp", true )
  544. respawntp:help( "Respawns <target> to a specific location." )
  545. --[End]----------------------------------------------------------------------------------------
  546.  
  547.  
  548.  
  549. --[Karma]--------------------------------------------------------------------------------------
  550. --[[ulx.karma][Sets the <target(s)> karma to a given amount.]
  551. @param {[PlayerObject]} calling_ply [The player who used the command.]
  552. @param {[PlayerObject]} target_plys [The player(s) who will have the effects of the command applied to them.]
  553. @param {[Number]} amount [The number the target's karma will be set to.]
  554. --]]
  555. function ulx.karma( calling_ply, target_plys, amount )
  556. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  557. for i=1, #target_plys do
  558. target_plys[ i ]:SetBaseKarma( amount )
  559. target_plys[ i ]:SetLiveKarma( amount )
  560. end
  561. end
  562. ulx.fancyLogAdmin( calling_ply, "#A set the karma for #T to #i", target_plys, amount )
  563. end
  564. local karma = ulx.command( CATEGORY_NAME, "ulx karma", ulx.karma, "!karma" )
  565. karma:addParam{ type=ULib.cmds.PlayersArg }
  566. karma:addParam{ type=ULib.cmds.NumArg, min=0, max=10000, default=1000, hint="Karma", ULib.cmds.optional, ULib.cmds.round }
  567. karma:defaultAccess( ULib.ACCESS_ADMIN )
  568. karma:help( "Changes the <target(s)> Karma." )
  569. --[End]----------------------------------------------------------------------------------------
  570.  
  571.  
  572.  
  573. --[Toggle spectator]---------------------------------------------------------------------------
  574. --[[ulx.spec][Forces <target(s)> to and from spectator.]
  575. @param {[PlayerObject]} calling_ply [The player who used the command.]
  576. @param {[PlayerObject]} target_plys [The player(s) who will have the effects of the command applied to them.]
  577. --]]
  578. function ulx.tttspec( calling_ply, target_plys, should_unspec )
  579. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  580.  
  581. for i=1, #target_plys do
  582. local v = target_plys[ i ]
  583.  
  584. if should_unspec then
  585. v:ConCommand("ttt_spectator_mode 0")
  586. else
  587. v:ConCommand("ttt_spectator_mode 1")
  588. v:ConCommand("ttt_cl_idlepopup")
  589. end
  590. end
  591. if should_unspec then
  592. ulx.fancyLogAdmin( calling_ply, "#A has forced #T to join the world of the living next round.", target_plys )
  593. else
  594. ulx.fancyLogAdmin( calling_ply, "#A has forced #T to spectate.", target_plys )
  595. end
  596. end
  597. end
  598. local tttspec = ulx.command( CATEGORY_NAME, "ulx fspec", ulx.tttspec, "!fspec" )
  599. tttspec:addParam{ type=ULib.cmds.PlayersArg }
  600. tttspec:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  601. tttspec:defaultAccess( ULib.ACCESS_ADMIN )
  602. tttspec:setOpposite( "ulx unspec", {_, _, true}, "!unspec" )
  603. tttspec:help( "Forces the <target(s)> to/from spectator." )
  604. --[End]----------------------------------------------------------------------------------------
  605.  
  606. ------------------------------ Next Round ------------------------------
  607. ulx.next_round = {}
  608. local function updateNextround()
  609. table.Empty( ulx.next_round ) -- Don't reassign so we don't lose our refs
  610.  
  611. table.insert(ulx.next_round,"traitor") -- Add "traitor" to the table.
  612. table.insert(ulx.next_round,"detective") -- Add "detective" to the table.
  613. table.insert(ulx.next_round,"unmark") -- Add "unmark" to the table.
  614.  
  615. end
  616. hook.Add( ULib.HOOK_UCLCHANGED, "ULXNextRoundUpdate", updateNextround )
  617. updateNextround() -- Init
  618.  
  619.  
  620. local PlysMarkedForTraitor = {}
  621. local PlysMarkedForDetective = {}
  622. function ulx.nextround( calling_ply, target_plys, next_round )
  623. ULib.tsayError(calling_ply, "This command has been disabled!", true)
  624. /*if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  625. local affected_plys = {}
  626. local unaffected_plys = {}
  627. for i=1, #target_plys do
  628. local v = target_plys[ i ]
  629. local ID = v:UniqueID()
  630.  
  631. if next_round == "traitor" then
  632. if PlysMarkedForTraitor[ID] == true or PlysMarkedForDetective[ID] == true then
  633. ULib.tsayError( calling_ply, "that player is already marked for the next round", true )
  634. else
  635. PlysMarkedForTraitor[ID] = true
  636. table.insert( affected_plys, v )
  637. end
  638. end
  639. if next_round == "detective" then
  640. if PlysMarkedForTraitor[ID] == true or PlysMarkedForDetective[ID] == true then
  641. ULib.tsayError( calling_ply, "that player is already marked for the next round!", true )
  642. else
  643. PlysMarkedForDetective[ID] = true
  644. table.insert( affected_plys, v )
  645. end
  646. end
  647. if next_round == "unmark" then
  648. if PlysMarkedForTraitor[ID] == true then
  649. PlysMarkedForTraitor[ID] = false
  650. table.insert( affected_plys, v )
  651. end
  652. if PlysMarkedForDetective[ID] == true then
  653. PlysMarkedForDetective[ID] = false
  654. table.insert( affected_plys, v )
  655. end
  656. end
  657. end
  658.  
  659. if next_round == "unmark" then
  660. ulx.fancyLogAdmin( calling_ply, true, "#A has unmarked #T ", affected_plys )
  661. else
  662. ulx.fancyLogAdmin( calling_ply, true, "#A marked #T to be #s next round.", affected_plys, next_round )
  663. end
  664. end*/
  665. end
  666. local nxtr= ulx.command( CATEGORY_NAME, "ulx forcenr", ulx.nextround, "!nr" )
  667. nxtr:addParam{ type=ULib.cmds.PlayersArg }
  668. nxtr:addParam{ type=ULib.cmds.StringArg, completes=ulx.next_round, hint="Next Round", error="invalid role \"%s\" specified", ULib.cmds.restrictToCompletes }
  669. nxtr:defaultAccess( ULib.ACCESS_SUPERADMIN )
  670. nxtr:help( "Forces the target to be a detective/traitor in the following round." )
  671.  
  672. local function TraitorMarkedPlayers()
  673. for k, v in pairs(PlysMarkedForTraitor) do
  674. if v then
  675. ply = player.GetByUniqueID(k)
  676. ply:SetRole(ROLE_TRAITOR)
  677. ply:AddCredits(GetConVarNumber("ttt_credits_starting"))
  678. ply:ChatPrint("You have been made a traitor by an admin this round.")
  679. PlysMarkedForTraitor[k] = false
  680. end
  681. end
  682. end
  683. hook.Add("TTTBeginRound", "Admin_Round_Traitor", TraitorMarkedPlayers)
  684.  
  685. local function DetectiveMarkedPlayers()
  686. for k, v in pairs(PlysMarkedForDetective) do
  687. if v then
  688. ply = player.GetByUniqueID(k)
  689. ply:SetRole(ROLE_DETECTIVE)
  690. ply:AddCredits(GetConVarNumber("ttt_credits_starting"))
  691. ply:Give("weapon_ttt_wtester")
  692. ply:ChatPrint("You have been made a detective by an admin this round.")
  693. PlysMarkedForDetective[k] = false
  694. end
  695. end
  696. end
  697. hook.Add("TTTBeginRound", "Admin_Round_Detective", DetectiveMarkedPlayers)
  698.  
  699. ---[Identify Corpse Thanks Neku]----------------------------------------------------------------------------
  700. function ulx.identify( calling_ply, target_ply, unidentify )
  701. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  702. body = corpse_find( target_ply )
  703. if not body then ULib.tsayError( calling_ply, "This player's corpse does not exist!", true ) return end
  704.  
  705. if not unidentify then
  706. ulx.fancyLogAdmin( calling_ply, "#A identified #T's body!", target_ply )
  707. CORPSE.SetFound( body, true )
  708. target_ply:SetNWBool("body_found", true)
  709.  
  710. if target_ply:GetRole() == ROLE_TRAITOR then
  711. -- update innocent's list of traitors
  712. SendConfirmedTraitors(GetInnocentFilter(false))
  713. SCORE:HandleBodyFound( calling_ply, target_ply )
  714. end
  715.  
  716. else
  717. ulx.fancyLogAdmin( calling_ply, "#A unidentified #T's body!", target_ply )
  718. CORPSE.SetFound( body, false )
  719. target_ply:SetNWBool("body_found", false)
  720. SendFullStateUpdate()
  721. end
  722. end
  723. end
  724. local identify = ulx.command( CATEGORY_NAME, "ulx identify", ulx.identify, "!identify")
  725. identify:addParam{ type=ULib.cmds.PlayerArg }
  726. identify:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  727. identify:defaultAccess( ULib.ACCESS_SUPERADMIN )
  728. identify:setOpposite( "ulx unidentify", {_, _, true}, "!unidentify", true )
  729. identify:help( "Identifies a target's body." )
  730.  
  731. ---[Remove Corpse Thanks Neku]----------------------------------------------------------------------------
  732. function ulx.removebody( calling_ply, target_ply )
  733. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  734. body = corpse_find( target_ply )
  735. if not body then ULib.tsayError( calling_ply, "This player's corpse does not exist!", true ) return end
  736. ulx.fancyLogAdmin( calling_ply, "#A removed #T's body!", target_ply )
  737. if string.find( body:GetModel(), "zm_", 6, true ) then
  738. body:Remove()
  739. elseif body.player_ragdoll then
  740. body:Remove()
  741. end
  742. end
  743. end
  744. local removebody = ulx.command( CATEGORY_NAME, "ulx removebody", ulx.removebody, "!removebody")
  745. removebody:addParam{ type=ULib.cmds.PlayerArg }
  746. removebody:defaultAccess( ULib.ACCESS_SUPERADMIN )
  747. removebody:help( "Removes a target's body." )
  748.  
  749. ---[Impair Next Round - Concpet and some code from Decicus next round slap]----------------------------------------------------------------------------
  750. function ulx.inr( calling_ply, target_ply, amount )
  751.  
  752. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  753.  
  754. local ImpairBy = target_ply:GetPData("ImpairNR", 0 )
  755.  
  756. if amount == 0 then
  757. target_ply:RemovePData("ImpairNR")
  758. chat_message = "#A will not impair #T health next round."
  759.  
  760. else
  761.  
  762. if amount == ImpairBy then
  763. ULib.tsayError( calling_ply, calling_ply:Nick() .. " will already be impaired for that amount of health." )
  764.  
  765. else
  766.  
  767. target_ply:SetPData( "ImpairNR", amount )
  768. chat_message = "#A will have #T impaired by " .. amount .. " health next round."
  769.  
  770. end
  771. end
  772. end
  773. ulx.fancyLogAdmin( calling_ply, chat_message, target_ply )
  774. end
  775. local impair = ulx.command( CATEGORY_NAME, "ulx impairnr", ulx.inr, "!impairnr" )
  776. impair:addParam{ type=ULib.cmds.PlayerArg }
  777. impair:addParam{ type=ULib.cmds.NumArg, min=0, max=99, default=5, hint="Amount of health to remove.", ULib.cmds.optional, ULib.cmds.round }
  778. impair:defaultAccess( ULib.ACCESS_ADMIN )
  779. impair:help( "Impair the targets health the following round. Set to 0 to remove impairment" )
  780.  
  781. ---[impair Next Round Helper Functions ]----------------------------------------------------------------------------
  782.  
  783. hook.Add("PlayerSpawn", "InformImpair" , function(ply)
  784.  
  785. local ImpairDamage = tonumber(ply:GetPData("ImpairNR")) or 0
  786.  
  787. if ply:Alive() and ImpairDamage > 0 then
  788. local chat_message = ""
  789.  
  790. if ImpairDamage > 0 then
  791. chat_message = (chat_message .. "You will be impaird by " ..ImpairDamage.. " health this round")
  792. end
  793. ply:ChatPrint(chat_message)
  794. end
  795. end)
  796.  
  797.  
  798. function ImpairPlayers()
  799.  
  800. for _, ply in ipairs( player.GetAll() ) do
  801.  
  802. local impairDamage = tonumber( ply:GetPData( "ImpairNR" ) ) or 0
  803.  
  804. if ply:Alive() and impairDamage > 0 then
  805. local name = ply:Nick()
  806. ply:TakeDamage(impairDamage)
  807. ply:EmitSound("player/pl_pain5.wav")
  808. ply:ChatPrint("You have been impaird by " ..impairDamage.. " health this round")
  809. ply:RemovePData( "ImpairNR" )
  810. ULib.tsay(nil, name .. " was impaired by ".. impairDamage .." health this round.", false)
  811. end
  812.  
  813. end
  814.  
  815. end
  816. hook.Add( "TTTBeginRound", "ImpairPlayers", ImpairPlayers )
Advertisement
Add Comment
Please, Sign In to add comment