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 b8da487 commit 88c0410
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 33 deletions.
3 changes: 3 additions & 0 deletions INDEV/Battle Royale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ local BattleRoyale = {
['./Battle Royale/spectator/'] = {
'spectate'
},
['./Battle Royale/stun/'] = {
'stun'
},
['./Battle Royale/util/'] = {
'timer'
},
Expand Down
2 changes: 1 addition & 1 deletion INDEV/Battle Royale/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion INDEV/Battle Royale/events/on_damage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions INDEV/Battle Royale/events/on_death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ 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
end

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
Expand Down
2 changes: 2 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,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')
Expand Down
40 changes: 15 additions & 25 deletions INDEV/Battle Royale/events/on_start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion INDEV/Battle Royale/events/on_tick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions INDEV/Battle Royale/loot/spoils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 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 = 1,
start_delay = 5,


--- Lives:
Expand Down Expand Up @@ -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'
},

Expand Down
11 changes: 11 additions & 0 deletions INDEV/Battle Royale/misc/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ')
Expand Down
11 changes: 11 additions & 0 deletions INDEV/Battle Royale/stun/stun.lua
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions INDEV/Battle Royale/weapons/weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion SAPP SCRIPTS/ATTRACTIVE MODS/Stun Grenades.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 88c0410

Please sign in to comment.