From 3962cfec987d9ca28665cdaef02cc9f6d22c82c4 Mon Sep 17 00:00:00 2001 From: Chalwk77 Date: Sat, 8 Jul 2023 13:52:23 +1200 Subject: [PATCH] ... --- INDEV/Battle Royale/about.md | 11 +++-- .../Battle Royale/events/on_object_spawn.lua | 13 +++++ INDEV/Battle Royale/events/on_start.lua | 2 + INDEV/Battle Royale/hud/hud.lua | 1 + INDEV/Battle Royale/loot/crates.lua | 5 +- INDEV/Battle Royale/loot/spoils.lua | 32 ++++++++----- .../Battle Royale/map settings/bloodgulch.lua | 13 +++-- .../weapon degradation/degradation.lua | 12 ++--- INDEV/Battle Royale/weapons/weapons.lua | 48 ++++++++++++++++--- 9 files changed, 100 insertions(+), 37 deletions(-) diff --git a/INDEV/Battle Royale/about.md b/INDEV/Battle Royale/about.md index 54ee230f..7c266c53 100644 --- a/INDEV/Battle Royale/about.md +++ b/INDEV/Battle Royale/about.md @@ -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%) @@ -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`, @@ -47,4 +48,4 @@ Planned features: - `deathisland`, `gephyrophobia` # Progress: -![alt text](https://progress-bar.dev/70/?title=Progress) \ No newline at end of file +![alt text](https://progress-bar.dev/75/?title=Progress) \ No newline at end of file diff --git a/INDEV/Battle Royale/events/on_object_spawn.lua b/INDEV/Battle Royale/events/on_object_spawn.lua index 7a0e6436..1a7d001a 100644 --- a/INDEV/Battle Royale/events/on_object_spawn.lua +++ b/INDEV/Battle Royale/events/on_object_spawn.lua @@ -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 diff --git a/INDEV/Battle Royale/events/on_start.lua b/INDEV/Battle Royale/events/on_start.lua index 310bc7ef..8cea737f 100644 --- a/INDEV/Battle Royale/events/on_start.lua +++ b/INDEV/Battle Royale/events/on_start.lua @@ -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 diff --git a/INDEV/Battle Royale/hud/hud.lua b/INDEV/Battle Royale/hud/hud.lua index 49e7dd1d..b603912b 100644 --- a/INDEV/Battle Royale/hud/hud.lua +++ b/INDEV/Battle Royale/hud/hud.lua @@ -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, diff --git a/INDEV/Battle Royale/loot/crates.lua b/INDEV/Battle Royale/loot/crates.lua index 47a861c3..2d18fb20 100644 --- a/INDEV/Battle Royale/loot/crates.lua +++ b/INDEV/Battle Royale/loot/crates.lua @@ -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: diff --git a/INDEV/Battle Royale/loot/spoils.lua b/INDEV/Battle Royale/loot/spoils.lua index 28ad6d93..c5d95bd2 100644 --- a/INDEV/Battle Royale/loot/spoils.lua +++ b/INDEV/Battle Royale/loot/spoils.lua @@ -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) @@ -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 \ No newline at end of file diff --git a/INDEV/Battle Royale/map settings/bloodgulch.lua b/INDEV/Battle Royale/map settings/bloodgulch.lua index 8e1af711..30474058 100644 --- a/INDEV/Battle Royale/map settings/bloodgulch.lua +++ b/INDEV/Battle Royale/map settings/bloodgulch.lua @@ -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: @@ -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, @@ -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, diff --git a/INDEV/Battle Royale/weapon degradation/degradation.lua b/INDEV/Battle Royale/weapon degradation/degradation.lua index 199acf31..7825cff2 100644 --- a/INDEV/Battle Royale/weapon degradation/degradation.lua +++ b/INDEV/Battle Royale/weapon degradation/degradation.lua @@ -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 @@ -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) @@ -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 diff --git a/INDEV/Battle Royale/weapons/weapons.lua b/INDEV/Battle Royale/weapons/weapons.lua index 4d00c964..84243018 100644 --- a/INDEV/Battle Royale/weapons/weapons.lua +++ b/INDEV/Battle Royale/weapons/weapons.lua @@ -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 @@ -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 @@ -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, @@ -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) @@ -84,12 +87,13 @@ 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) @@ -97,4 +101,34 @@ function weapons:customAmmo() 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 \ No newline at end of file