Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalwk77 committed Jul 10, 2023
1 parent 5e63524 commit 49b9141
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 57 deletions.
34 changes: 30 additions & 4 deletions INDEV/Battle Royale/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Battle Royale (WIP)

Planned features:
### Description:
Battle Royale is a game mode inspired by the popular game *PlayerUnknown's Battlegrounds* (PUBG).
The game mode is currently in development and is not ready for public release.

Eliminate all other opponents while avoiding being trapped outside a shrinking "safe area",
with the winner being the last player alive.

Players start with no weapons and must find them scattered around the map.
Loot crates will spawn randomly around the map, containing weapons, ammo, and other items.

## Planned features:

- [x] Shrinking "safe zone" boundary
- [x] The safe zone will shrink over time, forcing players to move closer together.
Expand Down Expand Up @@ -39,15 +49,31 @@ Planned features:
- [x] Players will start with no weapons.
- [x] You will have to find weapon *parts* to repair damaged weapons.
- [x] Different types of ammo:
- [x] Armoured-piercing,
- [x] Explosive
- [x] Armoured-piercing bullets,
- [x] Explosive bullets
- [x] Golden bullets (one-shot kill)
- [x] Support for these all stock maps:
- [x] Support for these stock maps:
- `timberland`, `bloodgulch`,
- `dangercanyon`, `icefields`
- `infinity`, `sidewinder`
- `deathisland`, `gephyrophobia`

# Coming in a future update:
- [ ] Custom commands to spawn loot crates on demand (for host testing purposes)
- [ ] Loot crate locations will be randomized every time they respawn.
- [ ] Tweaks to loot crate respawn time:<br/>
*All loot crates currently have the same respawn time (albeit configurable), across all maps (30 seconds).
Some spawn near weapons - these need to have a longer respawn time.*

# 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
- ~~Time remaining HUD keeps resetting when the zone shrinks.~~
- ~~Nuke is crashing the server.~~
- 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.

# [CODE](https://github.com/Chalwk77/HALO-SCRIPT-PROJECTS/tree/master/INDEV)

![alt text](https://progress-bar.dev/95/?title=Progress)
3 changes: 3 additions & 0 deletions INDEV/Battle Royale/countdown/pre_game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function timer:preGameTimer()
self.safe_zone_timer = self:new()
self.safe_zone_timer:start()

self.game_timer = self:new()
self.game_timer:start()

self:spawnLoot(self.looting.objects, 'loot')
self:spawnLoot(self.looting.crates, 'crates')

Expand Down
1 change: 1 addition & 0 deletions INDEV/Battle Royale/events/on_end.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local event = {}

function event:onEnd()
self.game_timer = nil
self.pre_game_timer = nil
self.post_game_carnage_report = true
end
Expand Down
34 changes: 6 additions & 28 deletions INDEV/Battle Royale/events/on_object_spawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,11 @@ function event:onObjectSpawn(player, map_id, parent_id, object_id, sapp_spawning
end
end

-- Just in case (to prevent rare projectile glitch):
local function delete(rocket)
local object = get_object_memory(rocket)
if (object ~= 0) then
destroy_object(rocket)
end
end

local function translate(rocket, object, x, y, z)
local function translate(object, x, y, z)
write_vector3d(object + 0x5C, x, y, z)
write_float(object + 0x68, 0) -- x velocity
write_float(object + 0x6C, 0) -- y velocity
write_float(object + 0x70, -9999) -- z velocity
delete(rocket)
write_float(object + 0x70, -99999) -- z velocity
end

local function createNuke(total, radius, projectile, cx, cy, cz)
Expand All @@ -59,33 +50,27 @@ local function createNuke(total, radius, projectile, cx, cy, cz)

-- Rockets with no spread but spawn in a circle:
for _ = 1, total do

local x = cx + (math.cos(angle) * radius)
local y = cy + (math.sin(angle) * radius)
local z = cz

local rocket = spawn_projectile(projectile, 0, x, y, z)
local object = get_object_memory(rocket)

translate(rocket, object, x, y, z)

translate(object, x, y, z)
angle = angle + angle_step
end

-- Rockets with random spread:
--Rockets with random spread:
for _ = 1, 5 do

local rocket = spawn_projectile(projectile, 0, cx, cy, cz)
local object = get_object_memory(rocket)

local x = cx + rand(-radius, radius + 1)
local y = cy + rand(-radius, radius + 1)
local z = cz

translate(rocket, object, x, y, z)
translate(object, x, y, z)
end
end

-- called every tick:
function event:trackNuke()

local nukes = self.nukes
Expand All @@ -94,23 +79,16 @@ function event:trackNuke()
end

for k, v in pairs(self.nukes) do

local object = get_object_memory(v.meta_id)
if (object == 0) then

self.nukes[k] = nil
self:modifyRocket()

createNuke(5, 5, v.projectile, v.x, v.y, v.z)
createNuke(5, 10, v.projectile, v.x, v.y, v.z)

self:rollbackRocket()

goto next
end

v.x, v.y, v.z = read_vector3d(object + 0x5C)

:: next ::
end
end
Expand Down
6 changes: 4 additions & 2 deletions INDEV/Battle Royale/events/on_start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ function event:onStart()
-- nuke:
self.nukes = {}

-- safe zone timer and total game time:
self.total_time = self:getTotalGameTime()
-- Sets initial radius of the safe zone and the total game time:
self.total_time = self:setSafeZone()

self.game_timer = self:new()

local h, m, s = self:secondsToTime(self.total_time)
timer(33, 'pluginLogo', h, m, s, self.end_after * 60)
Expand Down
5 changes: 3 additions & 2 deletions INDEV/Battle Royale/hud/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ function hud:getPrimaryHUD(distance)
distance = floor(distance)
local size = self.safe_zone_size
local timer = self.safe_zone_timer
local game_time = self.game_timer -- total game time

local time_elapsed = timer:get()
local time_elapsed = timer:get() -- time remaining until the next shrink
time_elapsed = self.duration - time_elapsed

local time_remaining = self.total_time - timer:get()
local time_remaining = self.total_time - game_time:get() -- game time remaining
local h, m, s = self:secondsToTime(time_remaining)

return format('Safe Zone: %s/%s | Zone Shrink: %.2f | Time Remaining: %s:%s:%s',
Expand Down
2 changes: 1 addition & 1 deletion INDEV/Battle Royale/loot/spoils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function spoils:giveNuke(args)
local id = self.id
assign_weapon(self:spawnObject(self.rocket_launcher, 0, 0, 0), id)

self.nuke_created = true
self.has_nuke = true
self:newMessage('You unlocked ' .. args.label, 5)

return true
Expand Down
8 changes: 4 additions & 4 deletions INDEV/Battle Royale/map settings/bloodgulch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ return {
-- How much the safe zone will shrink by (in world units):
-- Default (5)
--
shrink_amount = 5,
shrink_amount = 15,


--- End after:
Expand All @@ -41,15 +41,15 @@ return {
-- The minimum amount of players required to start the game:
-- Default: (2)
--
required_players = 2,
required_players = 1,


--- Game start delay:
-- The amount of time (in seconds) to wait before starting the game:
-- The start delay will not begin until the required players have joined.
-- Default (30)
--
start_delay = 30,
start_delay = 1,


--- Lives:
Expand Down Expand Up @@ -223,7 +223,7 @@ return {
spoils = {

--- NUKE:
[1] = {
[1000000] = {
label = 'Nuke',
radius = 10, -- kills all players within this radius
_function_ = 'giveNuke'
Expand Down
2 changes: 1 addition & 1 deletion INDEV/Battle Royale/safe zone/safe_zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function SafeZone:outsideSafeZone()
end
end

function SafeZone:getTotalGameTime()
function SafeZone:setSafeZone()

local min_size, max_size = self.safe_zone.min, self.safe_zone.max
local reduction_rate, reduction_amount = self.duration, self.shrink_amount
Expand Down
34 changes: 19 additions & 15 deletions INDEV/Battle Royale/weapons/weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function weapons:newWeapon()
setmetatable(self.weapons[object], self)
self.__index = self

if (self.nuke_created) then
self.nuke_created = false
if (self.has_nuke) then
self.has_nuke = false
self.weapons[object]:setAmmoType(6) -- nuke
self.weapons[object]:setAmmoDamage(100) -- damage multiplier
write_word(object + 0x2B8, 1) -- primary
Expand Down Expand Up @@ -223,14 +223,6 @@ function weapons:jamWeapon(player, dyn)
return false
end

local function getRandomKey(t)
local keys = {}
for k, _ in pairs(t) do
keys[#keys + 1] = k
end
return keys[rand(1, #keys + 1)]
end

local function hasThisWeapon(self, meta_id)

local id = self.id
Expand All @@ -245,7 +237,7 @@ local function hasThisWeapon(self, meta_id)
local weapon = read_dword(dyn + 0x2F8 + i * 4)
local object = get_object_memory(weapon)
if (weapon ~= 0xFFFFFFFF and object ~= 0) then
count = i + 1
count = count + 1
local tag_id = read_dword(object)
if (tag_id == meta_id) then
return true, count
Expand All @@ -266,18 +258,29 @@ local function giveWeapon(self, key, weapon, args)
assign_weapon(weapon, id)

local object = get_object_memory(weapon)
if (primary) then
write_word(object + 0x2B8, primary) -- primary
write_float(object + 0x240, primary) -- battery
end
write_word(object + 0x2B8, primary) -- primary

-- This is not working for some reason:
--write_float(object + 0x240, primary) -- battery
execute_command('battery ' .. id .. ' ' .. primary .. ' 0')

if (reserve) then
write_word(object + 0x2B6, reserve) -- reserve
end

sync_ammo(weapon)

self:newMessage('[Unlocked] ' .. args.label, 5)
end

local function getRandomKey(t)
local keys = {}
for k, _ in pairs(t) do
keys[#keys + 1] = k
end
return keys[rand(1, #keys + 1)]
end

function weapons:getRandomWeapon(args)

local random_weapons = self.random_weapons
Expand All @@ -294,6 +297,7 @@ function weapons:getRandomWeapon(args)
while (has_weapon) do
key = getRandomKey(random_weapons)
weapon = random_weapons[key]
has_weapon = hasThisWeapon(self, key)
end

giveWeapon(self, key, weapon, args)
Expand Down

0 comments on commit 49b9141

Please sign in to comment.