Skip to content

Overview

Infinitum edited this page Dec 6, 2021 · 5 revisions

AET Middleware

Purpose

Want to have breakable doors, a banner system that modifies your damage, or a safe zone where no damage can be done? AET Middleware can help you accomplish this without you having to edit a single line of AET code, you only need to interface with it!

How

You simply need to require the Add Middleware function from the location of the middleware and pass in your function to be called. That's it!

@example 1 - breakable parts

local AddHitMiddleware = require(game:GetService("ServerScriptService").server.components.Weapon).AddHitMiddleware

AddHitMiddleware(function(stop, weapon, hit, debounce) 
    if hit.GetAttribute("Breakable") then
        print(weapon.Player.Name .. " broke a breakable part!")
        hit.Destroy()
    end
end)

@example 2 - safe zone

local SafeZone = Instance.new("BasePart")
SafeZone.Parent = Workspace
SafeZone.Position = Vector3.new(0,0,0)

local AddDamageMiddleware = require(game:GetService("ServerScriptService").server.components.Weapon).AddDamageMiddleware

AddDamageMiddleware(function(stop, weapon, Player) 
    if (Player.Character.HumanoidRootPart.Position-SafeZone.Position).Magnitude < 30 then -- the player is within 30 studs of the safezone part
        stop() -- stopping here will ensure that the player does not get damaged
    end
end)

Remarks

stop - A callback parameter to every middleware. If called it will stop the current running middleware, all middlewares that haven't ran, aswell as stopping the area where the middlewares originate from. For instance, if you call stop() within a DamageMiddleware, it will stop the player from getting damaged. The way this is implemented is definitely not good and will be changed in the future, but it does its job fine for now.

Also many of the game's components are built ontop of these middlewares. The BlockedMiddleware for instance, actually uses the HitMiddleware, making the sword decoupled from the shield. The game's particle effects, sound effects, and stun system also come from adding middleware functionality throughout the code.

Clone this wiki locally