Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalwk77 committed Jul 8, 2023
1 parent 0721e08 commit 3962cfe
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 37 deletions.
11 changes: 6 additions & 5 deletions INDEV/Battle Royale/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Planned features:
- [ ] Stun grenades
- [ ] Air Strike ability
- [x] Weapon parts (for weapon repair system)
- [ ] Ammo (different types)
- [x] Ammo (different types)
- [ ] Weapons (different types)
- [ ] Grenade launcher
- [x] Health boost (50%, 100%, 150%, 200%)
Expand All @@ -36,9 +36,10 @@ Planned features:
- [x] Weapons (general):
- [x] Players will start with no weapons.
- [x] You will have to find weapon *parts* to repair damaged weapons.
- [ ] Different types of ammo (**WIP**)
- Armoured-piercing, explosive, nukes
- Golden bullets (one-shot kill)
- [x] Different types of ammo:
- [x] Armoured-piercing,
- [x] Explosive
- [x] Golden bullets (one-shot kill)
- [ ] Support for all stock maps: (**WIP**)
- It currently supports:
- `timberland`, `bloodgulch`,
Expand All @@ -47,4 +48,4 @@ Planned features:
- `deathisland`, `gephyrophobia`

# Progress:
![alt text](https://progress-bar.dev/70/?title=Progress)
![alt text](https://progress-bar.dev/75/?title=Progress)
13 changes: 13 additions & 0 deletions INDEV/Battle Royale/events/on_object_spawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ local event = {}
function event:onObjectSpawn(player, map_id, parent_id, object_id, sapp_spawning)

if (not sapp_spawning) then
-- not currently used
end

local dyn = get_dynamic_player(player.id)
if (player > 0 and dyn ~= 0) then
player = self.players[player]

local this_weapon = read_dword(dyn + 0x118)
local object = get_object_memory(this_weapon)

local weapon = self:getWeapon(object)
if (weapon and weapon.ammo_type == 3) then
return false, player:createExplosiveBullet(dyn)
end
end

return true
Expand Down
2 changes: 2 additions & 0 deletions INDEV/Battle Royale/events/on_start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function event:onStart()

self.weapons = {}

self.rocket_projectile = self:getTag('proj', 'weapons\\rocket launcher\\rocket')

self.loot = nil
self.loot_crates = nil

Expand Down
1 change: 1 addition & 0 deletions INDEV/Battle Royale/hud/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function hud:setHUD(HUD, distance)
end

function hud:newMessage(content, duration)
duration = duration or 5
self.messages[#self.messages + 1] = {
content = content,
finish = time() + duration,
Expand Down
5 changes: 4 additions & 1 deletion INDEV/Battle Royale/loot/crates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ function crates:openCrate()
return
end

self[f](self, spoils)
local success = self[f](self, spoils)
if (not success) then
self:newMessage('Something went wrong. Unable to unlock spoils.')
end
end

-- Test the loot system:
Expand Down
32 changes: 21 additions & 11 deletions INDEV/Battle Royale/loot/spoils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ end
function spoils:giveWeaponParts(args)
self.weapon_parts = true
self:newMessage('You unlocked ' .. args.label, 5)
return true
end

function spoils:giveRandomWeapon(args)
self:newMessage('You unlocked ' .. args.label, 5)
return true
end

function spoils:giveSpeedBoost(args)
Expand All @@ -48,52 +50,60 @@ function spoils:giveSpeedBoost(args)

label = label:gsub('$speed', new_speed):gsub('$duration', duration)
self:newMessage('You unlocked ' .. label, 5)
return true
end

function spoils:giveAmmo(args)

local id = self.id
local ammo_types = args.types

local type = rand(1, #ammo_types + 1)
local multiplier = ammo_types[type][1]
local label = ammo_types[type][2]

local dyn = get_dynamic_player(id)
local weapon = read_dword(dyn + 0x118)
if (weapon == 0xFFFFFFFF) then
local this_weapon = read_dword(dyn + 0x118)
if (this_weapon == 0xFFFFFFFF) then
self:newMessage('Picked up custom ammo but no weapon to modify!', 5)
return
return true
end

local object = get_object_memory(weapon)
local object = get_object_memory(this_weapon)
if (object ~= 0) then

weapon = self:getWeapon(object)

local weapon = self:getWeapon(object)
weapon:setAmmoType(type)
weapon:setAmmoDamage(multiplier)

local meta_id = read_dword(object) -- weapon tag id
local clip_size = self.clip_sizes[meta_id]

write_word(weapon.object + 0x2B8, clip_size) -- primary
write_float(weapon.object + 0x240, clip_size) -- battery
sync_ammo(weapon.weapon)
end
write_word(object + 0x2B8, clip_size) -- primary
write_float(object + 0x240, clip_size) -- battery
sync_ammo(this_weapon)

self:newMessage('You unlocked ' .. label, 5)
label = label:gsub('$ammo', clip_size)

self:newMessage('You unlocked ' .. label)
return true
end
return false
end

function spoils:giveCamo(args)
self:newMessage('You unlocked ' .. args.label, 5)
return true
end

function spoils:giveOvershield(args)
self:newMessage('You unlocked ' .. args.label, 5)
return true
end

function spoils:giveHealthBoost(args)
self:newMessage('You unlocked ' .. args.label, 5)
return true
end

return spoils
13 changes: 6 additions & 7 deletions INDEV/Battle Royale/map settings/bloodgulch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ return {
-- The start delay will not begin until the required players have joined.
-- Default (30)
--
start_delay = 5,
start_delay = 1,


--- Lives:
Expand Down Expand Up @@ -193,7 +193,6 @@ return {
-- The frequency of jamming is: (durability / 100) ^ 2 * 100
--
decay_rate = {

['weapons\\plasma pistol\\plasma pistol'] = 1.0,
['weapons\\plasma rifle\\plasma rifle'] = 1.2,
['weapons\\assault rifle\\assault rifle'] = 1.4,
Expand Down Expand Up @@ -282,12 +281,12 @@ return {
-- * 3 = explosive bullets
-- * 4 = golden bullets (one-shot kill)
-- Format: { [type] = {multiplier, label}, ...}
[10000] = {
[100000] = {
types = {
[1] = { 0, '$countX normal bullets' },
[2] = { 1.5, '$countX armour piercing bullets' },
[3] = { 5, '$countX explosive bullets' },
[4] = { 100, '$count golden bullets' }
[1] = { 0, '$ammoX normal bullets' },
[2] = { 1.5, '$ammoX armour piercing bullets' },
[3] = { 5, '$ammoX explosive bullets' },
[4] = { 100, '$ammoX golden bullets' }
},
clip_sizes = {
['weapons\\plasma pistol\\plasma pistol'] = 100,
Expand Down
12 changes: 6 additions & 6 deletions INDEV/Battle Royale/weapon degradation/degradation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ local function checkDurability(weapon, rate, reload)
local durability = weapon.durability
local frequency = (durability / 100) ^ 2 * 100

cprint('Jam when: ' .. time .. ' / ' .. frequency)
--cprint('Jam when: ' .. time .. ' / ' .. frequency)

if (time >= frequency) then
weapon.ammo = ammunition
Expand Down Expand Up @@ -92,17 +92,17 @@ function weapons:degrade()
return
end

local weapon = read_dword(dyn + 0x118)
local object = get_object_memory(weapon)
local this_weapon = read_dword(dyn + 0x118)
local object = get_object_memory(this_weapon)

if (weapon == 0xFFFFFFFF) then
if (this_weapon == 0xFFFFFFFF) then
return
elseif (object == 0) then
self.weapons[object] = nil
return
end

weapon = self:getWeapon(object)
local weapon = self:getWeapon(object)

local in_vehicle = self:inVehicle(dyn)
local overheated = overheating(object)
Expand All @@ -126,7 +126,7 @@ function weapons:degrade()
if (weapon.durability <= 0) then
weapon.durability = 0
self:newMessage('Your weapon has been destroyed', 8)
destroy_object(weapon.weapon)
destroy_object(this_weapon)
elseif (checkDurability(weapon, rate, is_reloading)) then
self:newMessage('Weapon jammed! Press MELEE to unjam.', 5)
else
Expand Down
48 changes: 41 additions & 7 deletions INDEV/Battle Royale/weapons/weapons.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
local weapons = {}

local function reloading(dynamic_player)
return (read_byte(dynamic_player + 0x2A4) == 5)
end

function weapons:newWeapon()

local id = self.id
Expand All @@ -10,10 +14,10 @@ function weapons:newWeapon()
return
end

local weapon = read_dword(dyn + 0x118)
local object = get_object_memory(weapon)
local this_weapon = read_dword(dyn + 0x118)
local object = get_object_memory(this_weapon)

if (weapon == 0xFFFFFFFF) then
if (this_weapon == 0xFFFFFFFF) then
return
elseif (object == 0) then
self.weapons[object] = nil
Expand All @@ -24,7 +28,7 @@ function weapons:newWeapon()
if (not self.weapons[object]) then

self.weapons[object] = {
weapon = read_dword(object), -- weapon tag
weapon = this_weapon, -- weapon tag
damage_multiplier = 0, -- default damage multiplier
ammo_type = 1, -- default ammo type
object = object,
Expand Down Expand Up @@ -71,7 +75,6 @@ function weapons:customAmmo()
return
end

-- don't use self:getWeaponObject() here.
local weapon = read_dword(dyn + 0x118)
local object = get_object_memory(weapon)

Expand All @@ -84,17 +87,48 @@ function weapons:customAmmo()

weapon = self:getWeapon(object)

if (weapon:getAmmoType() == 1) then -- normal ammo, ignore
if (weapon:getAmmoType() == 1) then
-- normal ammo, ignore
return
end

local primary = read_dword(object + 0x2B8) -- primary
if (primary == 0) then
if (primary == 0 or reloading(dyn)) then
weapon:setAmmoType(1) -- reset ammo type
weapon:setAmmoDamage(0) -- reset damage multiplier
self:newMessage('Ammo returned to normal', 8)
return
end
end

function weapons:createExplosiveBullet(dyn)

local id = self.id
local projectile = self.rocket_projectile
local px, py, pz = self:getXYZ(dyn)

local xAim = math.sin(read_float(dyn + 0x230))
local yAim = math.sin(read_float(dyn + 0x234))
local zAim = math.sin(read_float(dyn + 0x238))

local distance = 0.5

local x = px + (distance * xAim)
local y = py + (distance * yAim)
local z = pz + (distance * zAim)

if (projectile) then

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

if (rocket and object ~= 0) then
local velocity = 10
write_float(object + 0x68, velocity * xAim)
write_float(object + 0x6C, velocity * yAim)
write_float(object + 0x70, velocity * zAim)
end
end
end

return weapons

0 comments on commit 3962cfe

Please sign in to comment.