RPG Xdocumentation About RPG X

Stamina and mana

Pools, refilling, combat, training, and buffs and debuffs.

Next to health, players have stamina (for strength attacks) and mana (for magic attacks), shown as bars above the health display. Guns spend them per round (see Guns); addons do too, with GAMEMODE:ResourceSpend( ply, "stamina", 20 ) (server; returns false without using anything if there isn't enough).

A pool's size is:

( base + per_level x (level - 1) + skills ) x ( 1 + training_percent / 100 x training points )

so training grows all of it, levels and skills included (and whatever else goes in later).

  • Skills add to it: the Bonus stamina / Bonus mana skills, and any skill with SKILL.Resources (see Levels and skills).
  • Training points come from use: every train_cost spent earns one, which raises the pool by training_percent (2%) for train_duration seconds of online time, then goes. Each point has its own clock; earning another doesn't reset the others, and the clocks stop while you're offline. So the pool isn't a hard cap: it's how much you can use before you run out, and it grows for as long as you keep using it. The HUD shows them as a training buff with a stack per point (see Buffs and debuffs).
  • Pools refill regen per second, a whole point at a time and evenly (checked every server frame: stamina's points come exactly 0.4 s apart), starting regen_delay seconds after last spending, and are full on joining and respawning. Buffs and debuffs change the rate by overriding GM:ResourceRegenRate( ply, id ) (server); it's asked every frame, so a change applies at once.
  • Nothing refills in combat. Attacking (a shot or a swing, hit or miss), dealing or taking damage (any, falls included) puts a player in combat until rpgx_combat_timeout seconds (10) pass without any of it. Reloading pauses that countdown; it runs on once the reload is done. A hit that did nothing, on something invincible, doesn't count, and neither do the physgun, the gravity gun, the tool gun or the camera. Server: GAMEMODE:SetInCombat( ply, bool ); both sides: GAMEMODE:PlayerInCombat( ply ) (NW2 bool RPGXInCombat); hook RPGXCombat( ply, inCombat ).

Settings, per resource (rpgx_stamina_..., rpgx_mana_...):

Setting Stamina Mana
_base 100 100 Pool at level 1
_per_level 5 5 Added per level above 1
_training_percent 2 2 Percent the whole pool grows per training point
_regen 2.5 0.75 Refilled per second (+1 every 0.4 s / every 1.33 s), only out of combat
_regen_delay 1.5 3 Seconds after spending before refilling starts
_train_cost 100 100 Spent per training point earned (0 = no training)
_train_duration 3600 3600 Online seconds a training point lasts

To try it: rpgx_resource stamina 50 in your console spends 50 (a negative number refills) and prints the pool and training (owners only).

Addons add their own resource, with its own bar and convars, on both realms:

hook.Add( "RPGXResources", "MyAddon", function( register )
	register( "focus", { name = "Focus", color = Color( 200, 120, 255 ), defaults = { base = 50, regen = 2 } } )
end )

Hooks: RPGXResourceSpent( ply, id, amount ), RPGXTrainingPoint( ply, id, points ).

Buffs and debuffs #

A row of rounded boxes above the stamina bar, one per buff (green edge) or debuff (red edge) the player has, with its icon. One that runs out fills from the top down in its edge colour as its time passes (half full halfway through). Stacks show as a number in the bottom right corner (from 2 on). With the mouse free (any window, the C or Q menu), hovering a box shows its name, what it does and how long it has left. Built in:

  • In combat (debuff, icon16/fire.png), for the length of rpgx_combat_timeout.
  • Stamina training / Mana training (buff, icon16/add.png / icon16/lightning_add.png, an addon resource's trainingIcon): a stack per training point; the countdown is the point that runs out next. The tooltip's numbers come from the convars.
  • Every buff from a buff file (see Buffs from code), after these in the order they were applied.

Addons add their own on both realms (any icon16/... name from https://wiki.facepunch.com/gmod/Silkicons, or their own material):

hook.Add( "RPGXStatuses", "MyAddon", function( register )
	register( "blessed", {
		name = "Blessed", icon = "icon16/heart.png", debuff = false,
		desc = "Takes half damage.",   -- the hover tooltip; or function( ply, status ) returning it
		-- nil/false = doesn't have it; true = has it, no timer; or when it ends (CurTime) and how long
		-- it lasts; a third value is its stacks
		get = function( ply )
			local ends = ply:GetNW2Float( "MyBlessing", 0 )
			if ( ends > CurTime() ) then return ends, 30 end
		end,
	} )
end )