I have been thinking about how I would theoretically create a non strenuous passive system. What I mean by passives is something like a player having the “Passive1” value in their passives which is activated every time a player deals 10 damage and the passive will give them a 2x damage boost.
Or something like when this passive called “Double hit” is active, every time they launch a attack with their sword a second sword attack will be launched too from lets say a ghost sword that is behind you.
Now there are numerous ways to make it work I assume but what is a really efficient way to make one?
Passives may need to store data sometimes for them to be able to work such as storing how much damage was done to be able to do something
1. Event
The passive system first needs to do something when a action is done that could be used by a passive. For example a bindable event could be launched to indicate this action has happened.
2. Observe
Something needs to recieve the fact that this action has happened
3. Carry out tasks
The thing that recieved the fact that this action happened then compares if this action is a requirement for a passive or the passive itself.
This is one method that I can think of but please do help me with thinking of a efficient way to make a modular passive system that is efficient so I dont destroy roblox servers.
Thats not the point, a passive could activate after a certain amount of damage or a passive could be activated after a player climbs a wall, any passive we add that can happen on any action we want basically and the name doesnt matter here
Forgot to mention sorry* passives is game terminology, google first result: “ An ability is an action that is commanded by the player when pressing a certain key. A passive ability is an ability that is NOT “casted” by the player. Instead, it is an ongoing effect. For example, Player1 is playing Character1 a video game. Character1 has an ability that throws lava blocks, with his button “1”, so Player1 presses “1” to kill his target. Character1 also has a passive ability that is not controlled by Player1. It is a fire aura around him that shoots flames every 3 seconds.
The passive ability is automatically processed by the game and is not controlled, but is unique to a character in the game.”
You will need to adapt and expand upon this based on the specific requirements of your game and the complexity of passive abilities but here is a bare bones simple system.
-- Passive Ability
local PassiveAbility = {}
function PassiveAbility.new()
local self = {}
-- Define characteristics of the passive ability
self.activationCondition = function(player) return true end
self.effect = function(player) end
return self
end
-- Character Class
local Character = {}
function Character.new()
local self = {}
self.passiveAbilities = {}
return self
end
function Character:AddPassiveAbility(passiveAbility)
table.insert(self.passiveAbilities, passiveAbility)
end
-- Game Loop
local function ProcessPassiveAbilities(characters)
for _, character in pairs(characters) do
for _, passiveAbility in pairs(character.passiveAbilities) do
if passiveAbility.activationCondition(character) then
passiveAbility.effect(character)
end
end
end
end
-- Usage
local character1 = Character.new()
local fireAura = PassiveAbility.new()
-- Set activation condition and effect for the fire aura
fireAura.activationCondition = function(player) return true end
fireAura.effect = function(player) print("Fire aura activates!") end
character1:AddPassiveAbility(fireAura)
-- Game loop execution
ProcessPassiveAbilities({character1})
Passive Ability Definition:
The PassiveAbility module defines a basic structure for a passive ability. Each passive ability has an activation condition (a function that returns true when the ability should activate) and an effect (a function that represents what the ability does when activated).
Character Class Integration:
The Character module represents a game character. Each character has a list of passive abilities (self.passiveAbilities), which is initially an empty array.
Automated Processing:
The ProcessPassiveAbilities function takes an array of characters and iterates through each character’s passive abilities. It checks if the activation condition of each passive ability is met, and if so, it triggers the associated effect.
Efficient Data Storage:
The example doesn’t explicitly cover data storage, but in a real game, you would need to manage data efficiently, such as storing relevant information about characters and their passive abilities.
Modularity:
The design allows for modularity by creating separate modules for passive abilities and characters. This makes it easy to add or remove passive abilities without affecting the core logic.
Usage:
The example creates a character1 instance and a fireAura passive ability.
The activation condition for the fire aura is set to always return true (meaning it will always activate).
Game Loop Execution:
The game loop (not explicitly shown) could be a part of your game’s main loop. It periodically calls the ProcessPassiveAbilities function, passing an array of characters to check for passive ability activations.