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 f005b66 commit 0721e08
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 24 deletions.
13 changes: 10 additions & 3 deletions INDEV/Battle Royale/events/on_damage.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local event = {}

-- Prevent spectators from damaging (or being damaged) by other players:
function event:onDamage(victim, killer)
function event:onDamage(victim, killer, meta_id, damage)

local v = tonumber(victim)
local k = tonumber(killer)

if (k == 0) then
if (k == 0 or k == v) then
return true
end

Expand All @@ -17,7 +17,14 @@ function event:onDamage(victim, killer)
return false
end

return true
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
end
end

register_callback(cb['EVENT_DAMAGE_APPLICATION'], 'OnDamage')
Expand Down
18 changes: 18 additions & 0 deletions INDEV/Battle Royale/events/on_start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ function event:loadMapSettings()
return success, error
end

function event:getClipSizesTable()
for _,v in pairs(self.looting.spoils) do
if (v.clip_sizes) then
return v.clip_sizes
end
end
end

function event:onStart()
if (get_var(0, '$gt') ~= 'n/a') then

Expand All @@ -29,6 +37,8 @@ function event:onStart()
-- Disable Full Spectrum Vision:
execute_command('disable_object "' .. 'powerups\\full-spectrum vision"')

self.weapons = {}

self.loot = nil
self.loot_crates = nil

Expand Down Expand Up @@ -68,6 +78,14 @@ function event:onStart()
end
end

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

--self:spawnBarrier()
end
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 @@ -35,10 +35,16 @@ function event:onTick()
self:monitorLoot(self.loot) -- loot crate monitor

for _, v in pairs(self.players) do

--
-- warning: The order of these functions is important.
--

v:crateIntersect()
v:setSpeed() --todo: move this to a function called every 1 second.
v:setSpeed()
v:spectate()
v:newWeapon()
v:customAmmo()
v:degrade()
v:displaySecondaryHUD()
end
Expand Down
32 changes: 31 additions & 1 deletion INDEV/Battle Royale/loot/spoils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,37 @@ function spoils:giveSpeedBoost(args)
end

function spoils:giveAmmo(args)
self:newMessage('You unlocked ' .. args.label, 5)

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
self:newMessage('Picked up custom ammo but no weapon to modify!', 5)
return
end

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

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

self:newMessage('You unlocked ' .. label, 5)
end

function spoils:giveCamo(args)
Expand Down
41 changes: 27 additions & 14 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 @@ -144,23 +144,16 @@ return {

-- Format: ['tag name'] = weight reduction value
weapons = {

['weapons\\flag\\flag'] = 0.028,
['weapons\\ball\\ball'] = 0.028,

['weapons\\pistol\\pistol'] = 0.036,
['weapons\\plasma pistol\\plasma pistol'] = 0.036,

['weapons\\needler\\mp_needler'] = 0.042,
['weapons\\plasma rifle\\plasma rifle'] = 0.042,

['weapons\\shotgun\\shotgun'] = 0.047,
['weapons\\assault rifle\\assault rifle'] = 0.061,

['weapons\\flamethrower\\flamethrower'] = 0.073,

['weapons\\sniper rifle\\sniper rifle'] = 0.075,

['weapons\\plasma_cannon\\plasma_cannon'] = 0.098,
['weapons\\rocket launcher\\rocket launcher'] = 0.104
}
Expand Down Expand Up @@ -203,15 +196,11 @@ return {

['weapons\\plasma pistol\\plasma pistol'] = 1.0,
['weapons\\plasma rifle\\plasma rifle'] = 1.2,

['weapons\\assault rifle\\assault rifle'] = 1.4,

['weapons\\pistol\\pistol'] = 4.10,
['weapons\\needler\\mp_needler'] = 4.20,

['weapons\\flamethrower\\flamethrower'] = 7.05,
['weapons\\shotgun\\shotgun'] = 8.0,

['weapons\\sniper rifle\\sniper rifle'] = 23.0,
['weapons\\plasma_cannon\\plasma_cannon'] = 25.0,
['weapons\\rocket launcher\\rocket launcher'] = 40.0,
Expand Down Expand Up @@ -286,8 +275,32 @@ return {
},

--- AMMO:
[40] = {
label = 'Ammo',
-- When you pick up custom ammo, you will receive 1 clip of that ammo type.
-- Ammo types:
-- * 1 = normal bullets
-- * 2 = armour piercing bullets
-- * 3 = explosive bullets
-- * 4 = golden bullets (one-shot kill)
-- Format: { [type] = {multiplier, label}, ...}
[10000] = {
types = {
[1] = { 0, '$countX normal bullets' },
[2] = { 1.5, '$countX armour piercing bullets' },
[3] = { 5, '$countX explosive bullets' },
[4] = { 100, '$count golden bullets' }
},
clip_sizes = {
['weapons\\plasma pistol\\plasma pistol'] = 100,
['weapons\\plasma rifle\\plasma rifle'] = 100,
['weapons\\assault rifle\\assault rifle'] = 60,
['weapons\\pistol\\pistol'] = 12,
['weapons\\needler\\mp_needler'] = 20,
['weapons\\flamethrower\\flamethrower'] = 100,
['weapons\\shotgun\\shotgun'] = 12,
['weapons\\sniper rifle\\sniper rifle'] = 4,
['weapons\\plasma_cannon\\plasma_cannon'] = 100,
['weapons\\rocket launcher\\rocket launcher'] = 2
},
_function_ = 'giveAmmo'
},

Expand Down
5 changes: 5 additions & 0 deletions INDEV/Battle Royale/misc/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ function misc:getTag(class, name)
return (tag ~= 0 and read_dword(tag + 0xC)) or nil
end

function misc:getWeaponObject(dynamic_player)
local weapon = read_dword(dynamic_player + 0x118)
return (weapon ~= 0xFFFFFFFF and get_object_memory(weapon)) or nil
end

function misc:disableDeathMessages()
safe_write(true)
write_dword(self.death_message_address, 0x03EB01B1)
Expand Down
4 changes: 3 additions & 1 deletion INDEV/Battle Royale/weapon degradation/degradation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ function weapons:degrade()
local id = self.id
local dyn = get_dynamic_player(id)

if (not self.weapon_degradation.enabled) then
if (not self.pre_game_timer or not self.pre_game_timer.started) then
return
elseif (not self.weapon_degradation.enabled) then
return
elseif (not player_alive(id) or dyn == 0) then
return
Expand Down
43 changes: 39 additions & 4 deletions INDEV/Battle Royale/weapons/weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ local weapons = {}

function weapons:newWeapon()

self.weapons = self.weapons or {}

local id = self.id
local dyn = get_dynamic_player(id)
if (not player_alive(id) or dyn == 0) then
if (not self.pre_game_timer or not self.pre_game_timer.started) then
return
elseif (self.spectator or not player_alive(id) or dyn == 0) then
return
end

Expand All @@ -24,8 +24,9 @@ function weapons:newWeapon()
if (not self.weapons[object]) then

self.weapons[object] = {
weapon = read_dword(object), -- weapon tag
damage_multiplier = 0, -- default damage multiplier
ammo_type = 0, -- default ammo type
ammo_type = 1, -- default ammo type
object = object,
timer = self:new(),
durability = self.weapon_degradation.max_durability, -- 0% = broken, 100% = new
Expand Down Expand Up @@ -62,4 +63,38 @@ function weapons:getAmmoDamage()
return self.damage_multiplier
end

function weapons:customAmmo()

local id = self.id
local dyn = get_dynamic_player(id)
if (not player_alive(id) or dyn == 0) then
return
end

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

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

weapon = self:getWeapon(object)

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

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

return weapons

0 comments on commit 0721e08

Please sign in to comment.