Advertisement
Purfect

pointshop2/modules/ttt_integration/sv_ttthooks.lua

Aug 28th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. local S = function( id )
  2. return Pointshop2.GetSetting( "TTT Integration", id )
  3. end
  4.  
  5. local delayedRewards = {}
  6. local function delayReward( ply, points, message, small )
  7. if S("Kills.DelayReward") then
  8. table.insert( delayedRewards, { ply = ply, points = points, message = message, small = small } )
  9. else
  10. ply:PS2_AddStandardPoints( points, message, small )
  11. end
  12. end
  13.  
  14. local function applyDelayedRewards( )
  15. for k, v in ipairs( delayedRewards ) do
  16. v.ply:PS2_AddStandardPoints( v.points, v.message, v.small )
  17. end
  18.  
  19. delayedRewards = {}
  20. end
  21.  
  22. local playersInRound = {}
  23. hook.Add( "TTTBeginRound", "PS2_TTTBeginRound", function( )
  24. for k, v in pairs( player.GetAll( ) ) do
  25. if not v:IsSpec( ) then
  26. playersInRound[k] = v
  27. end
  28. end
  29. end )
  30.  
  31. hook.Add( "TTTEndRound", "PS2_TTTEndRound", function( result )
  32. Pointshop2.StandardPointsBatch:begin( )
  33.  
  34. applyDelayedRewards( )
  35.  
  36. local prevRoles = {
  37. [ROLE_INNOCENT] = {},
  38. [ROLE_TRAITOR] = {},
  39. [ROLE_DETECTIVE] = {}
  40. };
  41.  
  42. if not GAMEMODE.LastRole then GAMEMODE.LastRole = {} end
  43.  
  44. if result == WIN_INNOCENT then
  45. for k, v in pairs( player.GetAll( ) ) do
  46. if not table.HasValue( playersInRound, v ) then
  47. continue
  48. end
  49.  
  50. if v:IsTraitor( ) then
  51. continue
  52. end
  53.  
  54. if v:IsSpec( ) then
  55. continue
  56. end
  57.  
  58. if v:GetCleanRound( ) and S("RoundWin.CleanRound") then
  59. v:PS2_AddStandardPoints( S("RoundWin.CleanRound"), "Clean round bonus", true )
  60. end
  61. if v:Alive( ) and not ( v.IsGhost and v:IsGhost() ) and S("RoundWin.InnocentAlive") then
  62. v:PS2_AddStandardPoints( S("RoundWin.InnocentAlive"), "Alive bonus", true )
  63. end
  64. if S("RoundWin.Innocent") then
  65. v:PS2_AddStandardPoints( S("RoundWin.Innocent"), "Winning the round" )
  66. end
  67.  
  68. end
  69. elseif result == WIN_TRAITOR then
  70. for k, v in pairs( player.GetAll( ) ) do
  71. if not v:IsTraitor( ) then
  72. continue
  73. end
  74.  
  75. if ( v:Alive( ) and not v:IsSpec( ) ) and not ( v.IsGhost and v:IsGhost( ) ) and S("RoundWin.TraitorAlive") then
  76. v:PS2_AddStandardPoints( S("RoundWin.TraitorAlive"), "Alive bonus", true )
  77. end
  78. if S("RoundWin.Traitor") then
  79. v:PS2_AddStandardPoints( S("RoundWin.Traitor"), "Winning the round" )
  80. end
  81. end
  82. end
  83. playersInRound = {}
  84.  
  85. Pointshop2.StandardPointsBatch:finish( )
  86.  
  87. hook.Call( "Pointshop2GmIntegration_RoundEnded" )
  88. end )
  89. function DisguiserHatRemover(ply) if (ply:GetNWBool("disguised") == true) then return false end end hook.Add("PS2_PlayermodelShouldShow","DisguiserHatRemove",DisguiserHatRemover) hook.Add("PS2_VisualsShouldShow","DisguiserHatRemove",DisguiserHatRemover) hook.Add("PS2_WeaponShouldSpawn","DisguiserHatRemove",DisguiserHatRemover)
  90.  
  91. hook.Add( "TTTFoundDNA", "PS2_TTTFoundDNA", function( ply, dnaOwner, ent )
  92. ply.hasDnaOn = ply.hasDnaOn or {}
  93. if S("Detective.DnaFound") and not ply.hasDnaOn[dnaOwner] then
  94. ply:PS2_AddStandardPoints( S("Detective.DnaFound"), "Retrieved DNA", true )
  95. end
  96. ply.hasDnaOn[dnaOwner] = true
  97. end )
  98.  
  99. hook.Add( "PlayerDeath", "PS2_PlayerDeath", function( victim, inflictor, attacker )
  100. victim.hasDnaOn = {}
  101. if victim == attacker then
  102. return
  103. end
  104. if (attacker.IsGhost and attacker:IsGhost()) then return end --SpecDM Support.
  105.  
  106. if not victim.GetRole then
  107. return
  108. end
  109. local victimRole = victim:GetRole( )
  110.  
  111. if not attacker.GetRole then
  112. return
  113. end
  114. local attackerRole = attacker:GetRole( )
  115.  
  116. if attackerRole == ROLE_TRAITOR then
  117. if victimRole == ROLE_INNOCENT and S("Kills.TraitorKillsInno") then
  118. attacker:PS2_AddStandardPoints( S("Kills.TraitorKillsInno"), "Killed Innocent" )
  119. elseif victimRole == ROLE_DETECTIVE and S("Kills.TraitorKillsDetective") then
  120. attacker:PS2_AddStandardPoints( S("Kills.TraitorKillsDetective"), "Killed Detective" )
  121. end
  122. elseif attackerRole == ROLE_DETECTIVE then
  123. if victimRole == ROLE_TRAITOR and S("Kills.DetectiveKillsTraitor") then
  124. if attacker.hasDnaOn and attacker.hasDnaOn[victim] then
  125. delayReward( attacker, S("Kills.DetectiveDnaBonus"), "DNA bonus" )
  126. end
  127. delayReward( attacker, S("Kills.DetectiveKillsTraitor"), "Killed Traitor" )
  128. end
  129. elseif attackerRole == ROLE_INNOCENT then
  130. if victimRole == ROLE_TRAITOR and S("Kills.InnoKillsTraitor") then
  131. delayReward( attacker, S("Kills.InnoKillsTraitor"), "Killed Traitor" )
  132. end
  133. end
  134. end )
  135.  
  136. hook.Add( "PS2_WeaponShouldSpawn", "PreventForSpectators", function( ply )
  137. if ply:Team( ) == TEAM_SPECTATOR then
  138. return false
  139. end
  140. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement