From 88c0410dd281ddd966f183a9fe2a4286167407c5 Mon Sep 17 00:00:00 2001 From: Chalwk77 Date: Sat, 8 Jul 2023 17:26:24 +1200 Subject: [PATCH] ... --- INDEV/Battle Royale.lua | 3 ++ INDEV/Battle Royale/about.md | 2 +- INDEV/Battle Royale/events/on_damage.lua | 19 ++++++++- INDEV/Battle Royale/events/on_death.lua | 4 +- INDEV/Battle Royale/events/on_spawn.lua | 2 + INDEV/Battle Royale/events/on_start.lua | 40 +++++++------------ INDEV/Battle Royale/events/on_tick.lua | 8 +++- INDEV/Battle Royale/loot/spoils.lua | 16 ++++++++ .../Battle Royale/map settings/bloodgulch.lua | 15 ++++++- INDEV/Battle Royale/misc/misc.lua | 11 +++++ INDEV/Battle Royale/stun/stun.lua | 11 +++++ INDEV/Battle Royale/weapons/weapons.lua | 9 +++++ .../ATTRACTIVE MODS/Stun Grenades.lua | 2 +- 13 files changed, 109 insertions(+), 33 deletions(-) create mode 100644 INDEV/Battle Royale/stun/stun.lua diff --git a/INDEV/Battle Royale.lua b/INDEV/Battle Royale.lua index 02f3e5c6..97dbb78e 100644 --- a/INDEV/Battle Royale.lua +++ b/INDEV/Battle Royale.lua @@ -63,6 +63,9 @@ local BattleRoyale = { ['./Battle Royale/spectator/'] = { 'spectate' }, + ['./Battle Royale/stun/'] = { + 'stun' + }, ['./Battle Royale/util/'] = { 'timer' }, diff --git a/INDEV/Battle Royale/about.md b/INDEV/Battle Royale/about.md index 1f049215..bbc3bf4b 100644 --- a/INDEV/Battle Royale/about.md +++ b/INDEV/Battle Royale/about.md @@ -16,7 +16,7 @@ Planned features: - [x] Loot will be randomized and spawn in random locations - Loot includes ammo: - [ ] Nuke - - [ ] Stun grenades + - [x] Stun grenades - [ ] Air Strike ability - [x] Weapon parts (for weapon repair system) - [x] Ammo (different types) diff --git a/INDEV/Battle Royale/events/on_damage.lua b/INDEV/Battle Royale/events/on_damage.lua index 8a4f35c1..90ad33c4 100644 --- a/INDEV/Battle Royale/events/on_damage.lua +++ b/INDEV/Battle Royale/events/on_damage.lua @@ -17,14 +17,31 @@ function event:onDamage(victim, killer, meta_id, damage) return false end + -- + -- Stun grenades: + if (self.stuns[meta_id] and killer and killer.can_stun and not victim.stun) then + victim:newMessage('You have been stunned!') + local grenade = self.stuns[meta_id] + victim.stun = { + interval = os.time() + grenade[1], + speed = grenade[2] + } + return true, damage + end + + -- + -- Custom ammo: local dyn = get_dynamic_player(killer.id) local weapon = read_dword(dyn + 0x118) local object = get_object_memory(weapon) weapon = self:getWeapon(object) if (weapon) then - return true, damage * weapon.damage_multiplier + local mult = weapon.damage_multiplier + return true, (mult > 0 and damage * mult) or damage end + + return true, damage end register_callback(cb['EVENT_DAMAGE_APPLICATION'], 'OnDamage') diff --git a/INDEV/Battle Royale/events/on_death.lua b/INDEV/Battle Royale/events/on_death.lua index 8215bcaf..2fdc0d41 100644 --- a/INDEV/Battle Royale/events/on_death.lua +++ b/INDEV/Battle Royale/events/on_death.lua @@ -9,6 +9,8 @@ function event:onDeath(victim) victim = tonumber(victim) local player = self.players[victim] player.weapon_parts = false -- weapons parts loot + player.stun = nil -- stun grenades + player.can_stun = nil -- stun grenades if (not player.can_spectate) then return @@ -16,10 +18,8 @@ function event:onDeath(victim) player.lives = player.lives - 1 if (player.lives <= 0) then - player.spectator = true player:setSpectatorBits() - for _, v in pairs(self.players) do v:newMessage(player.name .. ' has been eliminated', 5) end diff --git a/INDEV/Battle Royale/events/on_spawn.lua b/INDEV/Battle Royale/events/on_spawn.lua index 66c17e7d..27e52bab 100644 --- a/INDEV/Battle Royale/events/on_spawn.lua +++ b/INDEV/Battle Royale/events/on_spawn.lua @@ -12,6 +12,8 @@ function event:onSpawn(id) execute_command('hp ' .. id .. ' ' .. self.health) execute_command('wdel ' .. id) execute_command('s ' .. id .. ' ' .. self.default_running_speed) + + player.stun = nil end register_callback(cb['EVENT_SPAWN'], 'OnSpawn') diff --git a/INDEV/Battle Royale/events/on_start.lua b/INDEV/Battle Royale/events/on_start.lua index 61e1f9b3..6fcc729a 100644 --- a/INDEV/Battle Royale/events/on_start.lua +++ b/INDEV/Battle Royale/events/on_start.lua @@ -22,6 +22,14 @@ function event:getClipSizesTable() end end +function event:getStunTags() + for _, v in pairs(self.looting.spoils) do + if (v.grenade_tags) then + return v.grenade_tags + end + end +end + function event:onStart() if (get_var(0, '$gt') ~= 'n/a') then @@ -39,9 +47,6 @@ function event:onStart() self.weapons = {} - self.rocket_projectile = self:getTag('proj', 'weapons\\rocket launcher\\rocket') - self.frag_projectile = self:getTag('proj', 'weapons\\frag grenade\\frag grenade') - self.loot = nil self.loot_crates = nil @@ -65,29 +70,14 @@ function event:onStart() end end - self.weapon_weights = {} - for name, speed in pairs(self.weight.weapons) do - local tag = self:getTag('weap', name) - if (tag) then - self.weapon_weights[tag] = speed - end - end - - self.decay_rates = {} - for name, rate in pairs(self.weapon_degradation.decay_rate) do - local tag = self:getTag('weap', name) - if (tag) then - self.decay_rates[tag] = rate - end - end + self.weapon_weights = self:tagsToID(self.weight.weapons, 'weap') + self.decay_rates = self:tagsToID(self.weapon_degradation.decay_rate, 'weap') + self.clip_sizes = self:tagsToID(self:getClipSizesTable(), 'weap') + self.stuns = self:tagsToID(self:getStunTags(), 'jpt!') - self.clip_sizes = {} - for name, size in pairs(self:getClipSizesTable()) do - local tag = self:getTag('weap', name) - if (tag) then - self.clip_sizes[tag] = size - end - end + -- For explosive bullets and grenade launcher: + self.rocket_projectile = self:getTag('proj', 'weapons\\rocket launcher\\rocket') + self.frag_projectile = self:getTag('proj', 'weapons\\frag grenade\\frag grenade') --self:spawnBarrier() end diff --git a/INDEV/Battle Royale/events/on_tick.lua b/INDEV/Battle Royale/events/on_tick.lua index 79fed1ca..63ac43e6 100644 --- a/INDEV/Battle Royale/events/on_tick.lua +++ b/INDEV/Battle Royale/events/on_tick.lua @@ -41,7 +41,13 @@ function event:onTick() -- v:crateIntersect() - v:setSpeed() + + if (v.stun) then + v:stunPlayer() + else + v:setSpeed() + end + v:spectate() v:newWeapon() v:customAmmo() diff --git a/INDEV/Battle Royale/loot/spoils.lua b/INDEV/Battle Royale/loot/spoils.lua index 36a2db97..28cf5f63 100644 --- a/INDEV/Battle Royale/loot/spoils.lua +++ b/INDEV/Battle Royale/loot/spoils.lua @@ -12,7 +12,23 @@ function spoils:enableAirstrike(args) end function spoils:giveStunGrenades(args) + + self.can_stun = true + + local id = self.id + local dyn = get_dynamic_player(id) + + local frags = args.count[1] + local plasmas = args.count[2] + + write_byte(dyn + 0x31E, frags) + write_byte(dyn + 0x31F, plasmas) + + local label = args.label + label = label:gsub('$frags', frags):gsub('$plasmas', plasmas) self:newMessage('You unlocked ' .. args.label, 5) + + return true end function spoils:giveGrenadeLauncher(args) diff --git a/INDEV/Battle Royale/map settings/bloodgulch.lua b/INDEV/Battle Royale/map settings/bloodgulch.lua index 766299e8..c70f0f33 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 = 1, + start_delay = 5, --- Lives: @@ -236,8 +236,19 @@ return { }, --- STUN GRENADES: - [10] = { + -- Grenade stunning is simulated by reducing the player's speed. + [100000] = { label = 'Stun Grenade(s)', + + -- How many of each grenade (frags, plasmas) to give: + count = { 2, 4 }, + + -- Format: { 'tag name', stun time, speed } + grenade_tags = { + ['weapons\\frag grenade\\explosion'] = { 5, 0.5 }, + ['weapons\\plasma grenade\\explosion'] = { 5, 0.5 }, + ['weapons\\plasma grenade\\attached'] = { 10, 0.5 } + }, _function_ = 'giveStunGrenades' }, diff --git a/INDEV/Battle Royale/misc/misc.lua b/INDEV/Battle Royale/misc/misc.lua index ec41f73b..351dc7a2 100644 --- a/INDEV/Battle Royale/misc/misc.lua +++ b/INDEV/Battle Royale/misc/misc.lua @@ -17,6 +17,17 @@ function misc:secondsToTime(s) return hours, mins, secs end +function misc:tagsToID(target, class) + local t = {} + for tag, value in pairs(target) do + local id = self:getTag(class, tag) + if (id) then + t[id] = value + end + end + return t +end + function misc:cls() for _ = 1, 25 do rprint(self.id, ' ') diff --git a/INDEV/Battle Royale/stun/stun.lua b/INDEV/Battle Royale/stun/stun.lua new file mode 100644 index 00000000..cf002f58 --- /dev/null +++ b/INDEV/Battle Royale/stun/stun.lua @@ -0,0 +1,11 @@ +local victim = {} + +function victim:stunPlayer() + if (os.time() > self.stun.interval) then + self.stun = nil + return + end + execute_command('s ' .. self.id .. ' ' .. self.stun.speed) +end + +return victim \ No newline at end of file diff --git a/INDEV/Battle Royale/weapons/weapons.lua b/INDEV/Battle Royale/weapons/weapons.lua index 209f9f00..e9448e22 100644 --- a/INDEV/Battle Royale/weapons/weapons.lua +++ b/INDEV/Battle Royale/weapons/weapons.lua @@ -90,6 +90,15 @@ function weapons:customAmmo() return end + local frags = read_byte(dyn + 0x31E) + local plasmas = read_byte(dyn + 0x31F) + + if (self.can_stun and frags == 0 and plasmas == 0) then + self.can_stun = false + self:newMessage('You ran out of stun grenades', 5) + end + + -- weapon object: weapon = self:getWeapon(object) -- normal ammo, ignore: diff --git a/SAPP SCRIPTS/ATTRACTIVE MODS/Stun Grenades.lua b/SAPP SCRIPTS/ATTRACTIVE MODS/Stun Grenades.lua index 8c85b7d9..67406abe 100644 --- a/SAPP SCRIPTS/ATTRACTIVE MODS/Stun Grenades.lua +++ b/SAPP SCRIPTS/ATTRACTIVE MODS/Stun Grenades.lua @@ -103,7 +103,7 @@ function OnDamage(Victim, Killer, MetaID) local pvp = (killer > 0 and victim ~= killer) if (pvp and stuns[MetaID]) then - + local stun_time = stuns[MetaID][1] local stun_percent = stuns[MetaID][2]