Skip to main content

EnergyShield

Generates a forcefield protecting its interior from energy-based weapons such as Lasers and PlasmaCannons, and offers full protection from Warhead explosions. An EnergyShield has a few sets of properties that you can fine tune to create a balanced shield.

ShieldRadius - The size of the entire shield. This will exponentially consume more power the higher the radius is. RegenerationSpeed - Scale from 1 to 10 on how fast the shield will regenerate. The shield will not regenerate while unpowered. ShieldStrength - Scale from 1 to 10 on how much the shield can endure.

RegenerationSpeed and ShieldStrength combined must not exceed 11.

It is a craftable and spawnable non-flammable solid.

It cannot be resized.

At its default size (5x5x7) it has a durability of 8.

By default, its colour is #7fb2ff.

It requires 50 Aluminum, 200 Iron, 75 Quartz, and 90 Silicon to be crafted.

Methods


CalculateCost(radius) → cost

The radius parameter is the radius of the theoretical energy shield you want to calculate the power cost for. If nil, will default to the EnergyShield.Radius configuration. The parameter is not bound by the constraints of EnergyShield.Radius and will accept any input. It is a number. It can also be nil.

The cost return is the Power cost per game tick to keep the EnergyShield running. It is a number.


GetShieldHealth() → health

Gets the current health of the shield as a percentage between 0 and 1.

The health return is a number.


SetColor(color)

Sets the color of the object.

The color parameter is the Color3 of the color you want to set the object to. It is a Color3.

local sift = require("sift") -- Grab this fancy library for manipulating tables provided by wos.

-- Get all of the types of objects with a `:SetColor` method and merge them into one big table.
local objects = sift.Array.merge(
GetParts("Light"),
GetParts("LightTube"),
GetParts("SpotLight"),
GetParts("EnergyShield")
)

-- We want this to run infinitely, but we want to run it every frame, rather than every game
-- tick, so we won't use the `Microcontroller.Loop` event.
while true do
-- First we want to get the current time, the function `os.clock` gives us a very precise
-- measurement of the current time (if you want to know, it basically uses the internal
-- clock of the computer running the code).
local currentTime = os.clock()

-- We then use the 'modulo' operator, what this does is it gives you the 'remainder'
-- from the division. So if you do something like `5.25 % 1` you get out the `0.25`,
-- or if you do, say, `31 % 2`, since 31 isn't divisble by 2 you get a remainder of `1`.

-- We do this so we just get the fractional aspect of the time (which would be the
-- milliseconds), giving us a number between 0 and 1.
local hue = currentTime % 1

-- We then construct a `Color3` passing in the value we just calculated, which, since
-- we used the modulo operator is always going to be between 0 and 1, the exact range
-- needed for the 'hue' of the `fromHSV`. We just set the 'saturation' and 'brightness'
-- to 1 to keep the colour nice and bright.

-- A helpful feature of the HSV colour space is that a hue of both `0` and `1` are red!
local color = Color3.fromHSV(hue, 1, 1)

-- Now we have our colour, we just want to apply it to all of our objects, so we'll use
-- a simple for loop. The 'index' or 'key' value is named '_' since we don't need it,
-- and naming it '_' is a good way to say it's an unused variable.
for _, object in objects do
-- Simply call the `SetColor` method (since it's a method, we use a `:` when
-- calling the function, rather than a `.`) passing in the `Color3`!
object:SetColor(color)
end

-- Wait a little bit before updating the colour again!
task.wait()
end

Configurables


RegenerationSpeed

Determines how fast the shield regenerates after being hit. It is a number. It ranges between 1 and 10.


ShieldRadius

The size of the entire shield. The shield exponentially consumes more power the higher this is. It is a number. It ranges between 50 and 1000.


ShieldStrength

Determines the shield's resistance to damage. It is a number. It ranges between 1 and 10.

Events


Configured(configurerId)

Fires when the object is configured.

The configurerId parameter is the UserId of the player who configured the object. It is a number.


Loop(deltaTime)

Fires when the object is updated by the game loop.

The deltaTime parameter is the 'time' since the last tick, it does not represent the actual time since the last tick was occurred, rather just how often a game tick should be fired (it will always be precisely 1). It is a number.