Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////
- // server code below
- ///////////////////////////////////////////////////
- local function BossKilled( npc, killer )
- if Bossfight_ON && npc:GetClass() == BossTable.BossEntity then
- if IsValid(killer) then
- killer:addMoney( BossTable.RP_Cash )
- DarkRP.notify( killer, 2, 6, "You have received " .. BossTable.RP_Cash .. " XP for participating in the boss fight!" )
- DarkRP.notify( killer, 2, 6, "You have received " .. DarkRP.formatMoney( BossTable.XP_Gain ) .. " for participating in the boss fight!" )
- end
- // These hooks handle our event, make sure to rid of them when the boss dies
- hook.Remove("OnNPCKilled", "RP.BoosFights.OnNPCKilledFight" )
- hook.Remove("Think", "RP.BossFights.CheckIfAllAreGone" )
- hook.Remove("PlayerSpawn", "RP.BossFight.PlayerDiedSpawn" )
- for k, v in pairs( BossPlayers ) do
- v:Spawn()
- end
- BossTable = {} // Empty our boss selection
- BossPlayers = {} // Empty our table
- Bossfight_ON = false
- end
- end
- local function BossThink( npc, killer )
- if Bossfight_ON then
- if #BossPlayers == 0 then
- Bossfight_ON = false
- DarkRP.notifyAll( 1, 5, "The boss fight has ended!" )
- // These hooks handle our event, make sure to rid of them when the boss dies
- hook.Remove("OnNPCKilled", "RP.BoosFights.OnNPCKilledFight" )
- hook.Remove("Think", "RP.BossFights.CheckIfAllAreGone" )
- hook.Remove("PlayerSpawn", "RP.BossFight.PlayerDiedSpawn" )
- end
- end
- end
- local function PlayerSpawnBoss( ply )
- if Bossfight_ON && ply.BossFightSpawn then
- timer.Simple( 0, function()
- ply:SetPos( ply.BossFightSpawn )
- end )
- end
- end
- local function doBossFight()
- if #BossPlayers == 0 then
- DarkRP.notifyAll( 1, 5, "No one entered the boss fight!" )
- return
- end
- local NPC_ENT = ents.Create( BossTable.BossEntity )
- NPC_ENT:SetHealth( BossTable.Health )
- NPC_ENT:SetPos( BossConfig.BossSpawnLocation.Location )
- NPC_ENT:SetAngles( BossConfig.BossSpawnLocation.Rotation )
- NPC_ENT:Spawn()
- Bossfight_ON = true
- for k, v in pairs( BossPlayers ) do
- v:ChatPrint( tostring(v) )
- v.BossFightSpawn = BossConfig.RandomBossLocations[v:EntIndex()].Location
- v:SetPos( v.BossFightSpawn )
- v:StripWeapons()
- v:Give( BossConfig.Weapons )
- for i = 1, 3 do
- v:GiveAmmo( BossConfig.AmmoAmount, BossConfig.AmmoType, false )
- end
- end
- hook.Add("OnNPCKilled", "RP.BoosFights.OnNPCKilledFight", BossKilled )
- hook.Add("PlayerSpawn", "RP.BossFight.PlayerDiedSpawn", PlayerSpawnBoss )
- hook.Add("Think", "RP.BossFights.CheckIfAllAreGone", BossThink )
- end
- local function doBossFightQuestion(answer, player, initiator, target, Trigger)
- if tobool(answer) && !BossPlayers[player:EntIndex()] && ( #BossPlayers != #BossConfig.RandomBossLocations ) then
- BossPlayers[player:EntIndex()] = player
- player:ChatPrint("You have entered the fight!")
- elseif answer ~= nil and !BossPlayers[player:EntIndex()] or ( #BossPlayers == #BossConfig.RandomBossLocations ) then
- BossPlayers[player:EntIndex()] = nil // Possible fall back to possible future bullshit
- player:ChatPrint("You have chosen not to fight!")
- end
- if tobool( Trigger ) then
- doBossFight()
- end
- end
- local function questionEnterBossFight()
- if Bossfight_ON then return end // Do not run the event twice!
- BossTable = BossConfig.BossFights[math.random(#BossConfig.BossFights)]
- BossAmount = BossTable.NumberOfBoss // How many are we spawning?
- for k, v in pairs( player.GetAll() ) do
- v:ChatPrint( "Boss: " .. BossTable.Name )
- v:ChatPrint( "Cash Reward: " .. DarkRP.formatMoney( BossTable.RP_Cash ) )
- v:ChatPrint( "XP Gain: " .. BossTable.XP_Gain )
- DarkRP.createQuestion("Enter Boss Fight?", "rp.boosfights_", v, BossConfig.QuestionTimerExecute or 15, doBossFightQuestion, nil, nil)
- end
- timer.Create("BossFights_RP", BossConfig.QuestionTimerExecute or 15, 1, function() doBossFightQuestion( nil, nil, nil, nil, true ) end)
- end
- timer.Create("RP.BoosFights.CheckQuestion", BossConfig.RandomEvenTimerDelay or 5, 0, function()
- questionEnterBossFight()
- end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement