Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1.  
  2. ///////////////////////////////////////////////////
  3. // server code below
  4. ///////////////////////////////////////////////////
  5.  
  6. local function BossKilled( npc, killer )
  7.  
  8. if Bossfight_ON && npc:GetClass() == BossTable.BossEntity then
  9.  
  10. if IsValid(killer) then
  11. killer:addMoney( BossTable.RP_Cash )
  12. DarkRP.notify( killer, 2, 6, "You have received " .. BossTable.RP_Cash .. " XP for participating in the boss fight!" )
  13. DarkRP.notify( killer, 2, 6, "You have received " .. DarkRP.formatMoney( BossTable.XP_Gain ) .. " for participating in the boss fight!" )
  14. end
  15.  
  16. // These hooks handle our event, make sure to rid of them when the boss dies
  17. hook.Remove("OnNPCKilled", "RP.BoosFights.OnNPCKilledFight" )
  18. hook.Remove("Think", "RP.BossFights.CheckIfAllAreGone" )
  19. hook.Remove("PlayerSpawn", "RP.BossFight.PlayerDiedSpawn" )
  20.  
  21. for k, v in pairs( BossPlayers ) do
  22. v:Spawn()
  23. end
  24.  
  25. BossTable = {} // Empty our boss selection
  26. BossPlayers = {} // Empty our table
  27. Bossfight_ON = false
  28.  
  29. end
  30.  
  31. end
  32.  
  33. local function BossThink( npc, killer )
  34.  
  35. if Bossfight_ON then
  36.  
  37. if #BossPlayers == 0 then
  38.  
  39. Bossfight_ON = false
  40. DarkRP.notifyAll( 1, 5, "The boss fight has ended!" )
  41.  
  42. // These hooks handle our event, make sure to rid of them when the boss dies
  43. hook.Remove("OnNPCKilled", "RP.BoosFights.OnNPCKilledFight" )
  44. hook.Remove("Think", "RP.BossFights.CheckIfAllAreGone" )
  45. hook.Remove("PlayerSpawn", "RP.BossFight.PlayerDiedSpawn" )
  46.  
  47. end
  48.  
  49. end
  50.  
  51. end
  52.  
  53. local function PlayerSpawnBoss( ply )
  54. if Bossfight_ON && ply.BossFightSpawn then
  55. timer.Simple( 0, function()
  56. ply:SetPos( ply.BossFightSpawn )
  57. end )
  58. end
  59. end
  60.  
  61.  
  62. local function doBossFight()
  63.  
  64. if #BossPlayers == 0 then
  65. DarkRP.notifyAll( 1, 5, "No one entered the boss fight!" )
  66. return
  67. end
  68.  
  69. local NPC_ENT = ents.Create( BossTable.BossEntity )
  70. NPC_ENT:SetHealth( BossTable.Health )
  71. NPC_ENT:SetPos( BossConfig.BossSpawnLocation.Location )
  72. NPC_ENT:SetAngles( BossConfig.BossSpawnLocation.Rotation )
  73. NPC_ENT:Spawn()
  74. Bossfight_ON = true
  75.  
  76. for k, v in pairs( BossPlayers ) do
  77.  
  78. v:ChatPrint( tostring(v) )
  79. v.BossFightSpawn = BossConfig.RandomBossLocations[v:EntIndex()].Location
  80. v:SetPos( v.BossFightSpawn )
  81. v:StripWeapons()
  82. v:Give( BossConfig.Weapons )
  83. for i = 1, 3 do
  84. v:GiveAmmo( BossConfig.AmmoAmount, BossConfig.AmmoType, false )
  85. end
  86.  
  87. end
  88.  
  89. hook.Add("OnNPCKilled", "RP.BoosFights.OnNPCKilledFight", BossKilled )
  90. hook.Add("PlayerSpawn", "RP.BossFight.PlayerDiedSpawn", PlayerSpawnBoss )
  91. hook.Add("Think", "RP.BossFights.CheckIfAllAreGone", BossThink )
  92.  
  93. end
  94.  
  95. local function doBossFightQuestion(answer, player, initiator, target, Trigger)
  96.  
  97. if tobool(answer) && !BossPlayers[player:EntIndex()] && ( #BossPlayers != #BossConfig.RandomBossLocations ) then
  98.  
  99. BossPlayers[player:EntIndex()] = player
  100. player:ChatPrint("You have entered the fight!")
  101.  
  102. elseif answer ~= nil and !BossPlayers[player:EntIndex()] or ( #BossPlayers == #BossConfig.RandomBossLocations ) then
  103.  
  104. BossPlayers[player:EntIndex()] = nil // Possible fall back to possible future bullshit
  105. player:ChatPrint("You have chosen not to fight!")
  106. end
  107.  
  108.  
  109. if tobool( Trigger ) then
  110.  
  111. doBossFight()
  112.  
  113. end
  114.  
  115. end
  116.  
  117. local function questionEnterBossFight()
  118.  
  119. if Bossfight_ON then return end // Do not run the event twice!
  120.  
  121. BossTable = BossConfig.BossFights[math.random(#BossConfig.BossFights)]
  122. BossAmount = BossTable.NumberOfBoss // How many are we spawning?
  123.  
  124. for k, v in pairs( player.GetAll() ) do
  125.  
  126. v:ChatPrint( "Boss: " .. BossTable.Name )
  127. v:ChatPrint( "Cash Reward: " .. DarkRP.formatMoney( BossTable.RP_Cash ) )
  128. v:ChatPrint( "XP Gain: " .. BossTable.XP_Gain )
  129.  
  130. DarkRP.createQuestion("Enter Boss Fight?", "rp.boosfights_", v, BossConfig.QuestionTimerExecute or 15, doBossFightQuestion, nil, nil)
  131.  
  132. end
  133.  
  134. timer.Create("BossFights_RP", BossConfig.QuestionTimerExecute or 15, 1, function() doBossFightQuestion( nil, nil, nil, nil, true ) end)
  135.  
  136. end
  137.  
  138. timer.Create("RP.BoosFights.CheckQuestion", BossConfig.RandomEvenTimerDelay or 5, 0, function()
  139. questionEnterBossFight()
  140. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement