Skip to content

Shield System

Vuthakral edited this page Nov 25, 2022 · 9 revisions

The shield system in the Draconic Base is still under early development and will have more features added in the future as they are thought of / requested.

Example Code paste

local shieldtable = {
	["Regenerating"] = true, -- Should the shield regenerate at all?
	["RegenDelay"] = 5, -- Delay (in seconds) before the shield will regenerate after taking damage.
	["RegenAmount"] = 33, -- Amount (per second) which the shield will regenerate
	["Health"] = 100, -- Total HP of the shield
	["Effects"] = {
		["BloodEnum"] = BLOOD_COLOR_RED, -- The colour of blood particles that the entity should make when the shields are down
		["Impact"] = "", -- Optionally add an effect to any of these
		["Deplete"] = "",
		["Recharge"] = "",
	},
	["Sounds"] = {
		["Impact"] = "", -- Optionally add a sound to any of these
		["Deplete"] = "",
		["Recharge"] = "",
	},
	["Material"] = "models/vuthakral/shield_example",
	["OverMaterial"] = "models/vuthakral/shield_over_example", -- Overshield material
	["AlwaysVisible"] = false,
	["ScaleMax"] = 1.15, -- The scale the shield will reach when taking damage
	["ScaleMin"] = 1.05, -- The scale the shield will be when idle.
}

DRC:SetShieldInfo(ENTITYGOESHERE, true, shieldtable)

DRC:SetShieldInfo(<ent> entity, <true/false> enabled/disabled, <table> shield information)

Example vmt of a shield material

(This tints with the player's energy colour, to tint it to a specific colour just remove the drc_EnergyColour proxy and set the vector $emissiveBlendTint)

"VertexLitGeneric"
{
	$basetexture	"models\debug\debugwhite"

 	$model		1
	$nocull		1
	$translucent	1
	$nodecal		1

	$color2	"[ 1 1 1 ]"

	$emissiveBlendEnabled	1
	$emissiveBlendTexture	"models\vuthakral\shield_arcs"
	$emissiveBlendBaseTexture	"models\debug\debugwhite"
	$emissiveBlendFlowTexture	"models\vuthakral\shield_flow"
	$emissiveBlendTint		"[ 1 1 1 ]"
	$emissiveBlendStrength 	1
	$emissiveBlendScrollVector	"[ .4 .4 ]"

	Proxies
	{

		drc_ShieldFade{}
		drc_EnergyColour
		{
			resultVar	$emissiveBlendTint	
		}
	}
}

Ok, but how do I make my HUD / etc compatible with it?

DRC:GetShield(ENTITYGOESHERE) will return these first two useful values: Current shield, and max shield. So you could use it like this:

local shp, mshp = DRC:GetShield(ENTITYGOESHERE)

and from then on the value shp will be the shield's current health, and mshp will be the shield's max health.

But then how do I even detect if an entity/player is shielded?

ent:GetNWBool("DRC_Shielded")

But what if my content is aimed at being compatible without your shields too?

if Draconic then

That's cool and all, but I'm not developing a HUD / Display.

DRC:AddShield(ENTITYGOESHERE, amount)
DRC:SubtractShield(ENTITYGOESHERE, amount)

How do I give people overshields / toggle shield invulnerability?

To get something's overshield information, use the following in your code:

local ovshp, numb, fract = DRC:GetOverShield(ent)

From this point on:

  • ovshp is the overshield's health (NOT the base shields)
  • numb is how many times over the overshield health number makes up their shield. E.g. If their overshield health is 300 & their base shield's max health is 100, this value will be 3
  • fract is the fraction from 0 to 1 representing the percentage of overshield left in the current numb. E.g. if the overshield is 260, this value will be 0.6

To add overshield health:

This function will just add a number amount of overshield health to a given entity.

DRC:AddOverShield(ent, amount)

This function will add a relative amount of overshield health, based on the entity's max shield amount. For instance, setting the multiplier value to 3 when the ent's max shield hp is 100 will result in 300 overshield health being added. The final argument, cap is a number value for the maximum amount of overshield this call should be allowed to give. E.g. if the ent has 100 shield max base, the function calls for 5, it should add 500; but if you have cap set to 250, then it will only add 250.

DRC:AddOverShield_Mul(ent, multiplier, cap)

How to toggle invulernability:

The three arguments of the below function are pretty self explanatory. The entity you want to have the shield become invulnerable on, how long (in seconds), and the material to set their shield to. It will automatically reset when the duration ends.

The base comes with one example invulnerability material to use in case you just need one for testing or etc: models/vuthakral/shield_invuln_example

DRC:SetShieldInvulnerable(ent, time, mat)
Clone this wiki locally