#Best way to Handle Weapons

1 messages · Page 1 of 1 (latest)

maiden wind
#

For the past few weeks, I've been stuck on creating a scalable & modular weapon system for my game. Each weapon can be VASTLY different and can range from melee, guns, magic, etc. Due to the differences that each weapon can do, I would need to create something that reflects this.

Currently, I am planning on using composition to compose weapon functionality, and while this works, I am unsure on two things.

  1. How should the weapon receive events? Should there be a method that hooks a callback to an event?

  2. Should there be a base-class or just shared functions that an outside controller or handler can call upon for consistency?

This topic has been confusing but if there are references I might've missed or anyone has better insight, please lmk! Also, here is my basic implementation at the moment.

--// Class Setup \\--

local WeaponClass = {}
local WeaponClassMT = {}
WeaponClassMT.__index = WeaponClassMT

--// Types \\--

type WeaponImpl = {
    Signal: Signal.Signal
}

export type Weapon = typeof(setmetatable({} :: WeaponImpl, WeaponClassMT))

--// Constructor \\--

function WeaponClass.new(): Weapon
    local self = setmetatable({}, WeaponClassMT) :: Weapon
    self.Signal = Signal.new()
    
    return self
end

--// Public Methods \\--

--Action are any events like input events or misc things.
function WeaponClassMT:OnAction(Action: string, callback: (...any?) -> ())
    local self = self :: Weapon
    
    
end

function WeaponClassMT:FireAction(Action: string, ...)
    local self = self :: Weapon
    self.Signal:Fire(Action, ...)
end

--Can put any update logic within here
function WeaponClassMT:Update(DeltaTime: number)
    local self = self :: Weapon
end

function WeaponClassMT:Init()
    local self = self :: Weapon
end

function WeaponClassMT:Destroy()
    local self = self :: Weapon
    
    setmetatable(self, nil)
end

--// Private Methods \\--

return WeaponClass
dim flax
#

im not talking out of my ass btw

#

ive been developing a weapon framework for some time now

maiden wind
#

What is your approach to this?

dim flax
#

I have a module for each gun, all containing the same data structure so i can easily config.
I then break up parts of the weapon into smaller modules; like ammo module, viewmodelLogic etc (if needbe only, if it works dont over complicate)

#

hopefully this helped

maiden wind
#

Ima edit my og question since I rushed it

#

Give you a better understanding on what I am asking

#

Sorry 😭

dim flax
#

aight leme reread

maiden wind
#

This is just my devforum question I posted like 30 minutes ago

dim flax
#

its literally just

#

"what base components i know damn well anything can fit in"

#

you know everything will "fire" in some way

#

maybe something will or will not have physics based projectiles

#

so

#

yeah

#

plus the kinda dissapointing reality

#

is that you most likely wont know what you will need/want untill you're already kinda b**ls deep into it

#

or some shit idk 🥺

wooden kettle
maiden wind
maiden wind
dim flax
dim flax
#

these things come in prototypes, testing, then more refining

maiden wind