Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalwk77 committed Jul 13, 2023
1 parent 56298f4 commit a9e9be6
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 16 deletions.
3 changes: 2 additions & 1 deletion INDEV/Battle Royale/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ Loot crates will spawn randomly around the map, containing weapons, ammo, and ot
# Known bugs:
- ~~Energy weapons from loot crates don't have battery power.~~
- ~~Receiving a weapon from a loot crate that you already have caused the server to crash.~~
- Game doesn't end with the last man standing
- ~Game doesn't end with the last man standing~
- ~~Time remaining HUD keeps resetting when the zone shrinks.~~
- ~~Nuke is crashing the server.~~
- ~~Players are given too many golden bullets. Needs to be limited to 3 max?~~
- ~Players can spawn outside the safe zone.~
- When receiving an overshield from a loot crate, you won't see the shield bar change until you take damage.<br/>
Unfortunately, this is a limitation of Halo's net code.

Expand Down
24 changes: 15 additions & 9 deletions INDEV/Battle Royale/countdown/pre_game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,36 @@ function timer:phaseCheck(quit, player)
local required_players = self.required_players
local game_started = (self.pre_game_timer and self.pre_game_timer.started)


-- Enough players have joined the game, start the pre-game timer:
if (count >= required_players and not self.pre_game_timer) then
self.pre_game_timer = self:new()
self.pre_game_timer:start()


-- Player has joined mid-game:
elseif (not quit and player and count >= required_players and game_started) then
if (self.new_player_spectate) then
player.spectator = true
player:setSpectatorBits()
player:newMessage('You have joined mid-game, you will be able to play next round', 5)
end
-- Player has joined mid-game. Put into spectator mode if enabled:
elseif (not quit and player and count >= required_players and game_started and self.new_player_spectate) then
player.spectator = true
player:setSpectatorBits()
player:newMessage('You have joined mid-game, you will be able to play next round', 5)


-- A player has quit the game before the pre-game timer has elapsed. Reset the timer:
-- A player has quit the game before the pre-game timer has elapsed.
-- Reset the timer:
elseif (quit and self.pre_game_timer and not self.pre_game_timer.started) then
self.pre_game_timer = nil


-- The game has started but there is only one player left, end the game:
elseif (quit and count == 1 and game_started) then
execute_command('sv_map_next')
print('[VICTORY] Game ended - last player wins!')
print('[BATTLE ROYALE] Game ended - last player wins!')


-- No players left:
elseif (quit and count == 0) then
execute_command('sv_map_next')
print('[BATTLE ROYALE] Game ended - no players left!')
end
end

Expand Down
26 changes: 26 additions & 0 deletions INDEV/Battle Royale/events/on_death.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
local event = {}

local function endGame(self)

local lives = {}
for i,v in pairs(self.players) do
if (v.lives > 0) then
lives[#lives + 1] = v
end
end

if (#lives == 1) then
execute_command('sv_end_game')
local winner = lives[1]
self:say(string.format('[VICTORY] %s has won the game!', winner.name), true)
return true
end

return false
end

function event:onDeath(victim)

if (not self.pre_game_timer or not self.pre_game_timer.started) then
Expand All @@ -20,9 +39,16 @@ function event:onDeath(victim)
if (player.lives <= 0) then
player.spectator = true
player:setSpectatorBits()

local game_over = endGame(self)
if (game_over) then
return
end

for _, v in pairs(self.players) do
v:newMessage(player.name .. ' has been eliminated', 5)
end

return
end

Expand Down
3 changes: 2 additions & 1 deletion INDEV/Battle Royale/events/on_pre_spawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function event:onPreSpawn(id)
return
end

self.players[id]:teleport() -- sky spawning system / only works if the pre-game timer has elapsed.
-- @args: god, height
self.players[id]:teleport(true, true)
end

register_callback(cb['EVENT_PRESPAWN'], 'OnPreSpawn')
Expand Down
56 changes: 56 additions & 0 deletions INDEV/Battle Royale/events/on_spawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,62 @@ function event:onSpawn(id)
execute_command('hp ' .. id .. ' ' .. self.health)
execute_command('wdel ' .. id)
execute_command('s ' .. id .. ' ' .. self.default_running_speed)

--
-- Prevents players from spawning outside the safe zone:
-- Only in effect during game play.
--

if (player.god) then
return
end

-- Gets all sky-spawn points:
local spawns = self:getSpawns()

-- Safe zone X, Y, Z and radius:
local radius = self.safe_zone_size
local bX, bY, bZ = self.safe_zone.x, self.safe_zone.y, self.safe_zone.z

-- Saves all points inside the circle:
local candidates = {}
for i = 1, #spawns do
local point = spawns[i]

local x = point[1]
local y = point[2]
local z = point[3]

local distance = self:getDistance(x, y, z, bX, bY, bZ)
if (distance <= radius) then
candidates[#candidates + 1] = point
end
end

-- If there are no points inside the circle, then we'll pick the closest one to the centre of the circle:
if (#candidates == 0) then

local closest
local closest_distance
for i = 1, #spawns do

local point = spawns[i]
local x = point[1]
local y = point[2]
local z = point[3]

local distance = self:getDistance(x, y, z, bX, bY, bZ)
if (not closest or distance < closest_distance) then
closest = point
closest_distance = distance
end
end
player.spawn = closest
else
player.spawn = candidates[rand(1, #candidates + 1)]
end

player:teleport(false, false)
end

register_callback(cb['EVENT_SPAWN'], 'OnSpawn')
Expand Down
4 changes: 3 additions & 1 deletion INDEV/Battle Royale/safe zone/hurt_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ local safe_zone = {}

function safe_zone:hurt(player)

if (not player.kill_timer) then
if (self.spectator) then
return
elseif (not player.kill_timer) then
player.kill_timer = self:new()
player.kill_timer:start()
end
Expand Down
8 changes: 5 additions & 3 deletions INDEV/Battle Royale/sky spawning/teleport.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local player = {}

function player:teleport()
function player:teleport(god, height)

local dyn = get_dynamic_player(self.id)
if (dyn == 0) then
Expand All @@ -10,13 +10,15 @@ function player:teleport()
local x, y, z = self.spawn[1], self.spawn[2], self.spawn[3]

local rotation = self.spawn[4]
local height = self.spawn[5]
height = (height and self.spawn[5]) or 0

write_vector3d(dyn + 0x5C, x, y, z + height)
write_vector3d(dyn + 0x74, math.cos(rotation), math.sin(rotation), 0)
--print('Spawned: ' .. x .. ', ' .. y .. ', ' .. z, rotation)

self.god = self:new() -- god mode timer
if (god) then
self.god = self:new() -- god mode timer
end
end

return player
3 changes: 3 additions & 0 deletions INDEV/Battle Royale/spectator/spectate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function spectator:spectate()

-- Force the player into camoflauge mode:
execute_command('camo ' .. self.id .. ' 1')

-- Force the player into god mode:
execute_command('god ' .. self.id)
end

function spectator:setSpectatorBits()
Expand Down
2 changes: 1 addition & 1 deletion INDEV/Battle Royale/weight/weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function weight:getSpeed()

local speed = self.default_running_speed
local dyn = get_dynamic_player(self.id)
if (dyn == 0 or not player_alive(self.id)) then
if (dyn == 0 or not player_alive(self.id) or self.spectator) then
return speed
end

Expand Down

0 comments on commit a9e9be6

Please sign in to comment.