Welcome Guest, Not a member yet? Login with Steam   Create Account  

Ability API | A simple ability addon for Garrys Mod.


Welcome to Ability API, one of the first ability addons in Garrys Mod that allows people to create, edit, design, choose and use abilities on their server / personal use.
In this addon you can create abilities that players can use after binding a key using the bind menu (!binding in game), after this players can type !ability or !abilities and choose their abilities from a list of abilities created through LUA.
The main reason I made this addon was for Gamemodes and Servers who enjoyed my most recently published addon that involved abilities, [Overwatch] Reaper | Custom Abilities, Weapons, Model, Voicelines.
The addon is can be subscribed here; Addon


Creating Abilities:
You can create abilities using a server sided function AddAbility() with the arguments of a table, the template can be found or how to use this can be found in the addon/lua/autorun/default_abilities.lua.
Example of creating an ability: (In a server sided file)

local ply = ply or {}
AddAbility( {  
   name = "Blink", // Must be a unique name and different from the others.
   color = Color( 25,100,100 ),
   cooldown = 10, // How long must a player wait before re-activating after using an ability?
   material = "", // This will make the ability slot ball on the UI change material, some materials look pretty buggy, type "" to only use the specified color.
   func = function(ply)
       ply:SetFOV( 150, 1 )
       ply:Freeze( true )

           ply:Freeze( false )
           ply:SetPos( ply:GetEyeTrace().HitPos )
           ply:SetFOV( 0, 1 )

           UnstuckPlayer( ply )
} )

Now if you run this inside one of your files, and you do not localize ply to equal ply or a table, you will get errors spitting at you saying "what is ply" as ply does not exist until the function ply:Ability() gets called (this runs the function after a player presses a key, and this creates its own cooldown timer, this can be executede server sided).

Running / Setting a players ability
By default a player can select they're abilities through the client sided GUI that will open when a player types !ability, of course deleting the cl_abilities.lua will remove this function and remove the UI, but players can set abilities through console commands, this can be removed in the abilities.lua (this is how the client sends info back and forth without using net lua).
You can set abilities through player data using NW strings. Here is an example:

ply:SetNWString( "Ability1", "Blink" ) // Second value MUST be the ability name.
// This goes upto 4 abilities and can be modified to you're liking.

// Example of creating a so called "First Person Abilitized Character" in you're gamemode.
// Just an example weapon.
// The abilities below are just examples of you creating abilities, then assigning them in a gamemode.
function GM:PlayerSpawn(ply)
 ply:SetNWString( "Ability1", "Dash" )
 ply:SetNWString( "Ability2", "Flame Strike" )
 ply:SetNWString( "Ability3", "Wheel Barrow Time" )
 ply:SetNWString( "Ability4", "Dragon Blade" )
 ply:Give( "m9k_colt1911" )
end )

Grabbing Abilities / Cooldown timers
If you want a list of the players abilities use ply:GetAbilities() this only works on server side, and to retrieve a list of the abilities on the client use the global table of Abilities (this is the global table name).
Grabbing a the time left of a timer on the client is ply:GetNWInt( "CooldownAbility1" ), it can be 1-2-3-4 (unless you add more ability slots)

The rest is up to you, just see how it works, recode it, do what ever you want as long as you make sure I have full credit for you're use of this addon, and its LUA so using it server sided wont require the players to download it via workshop!
Thanks, and I hope you enjoy my simple ability api addon.

Original post on Facepunch: https://forum.facepunch.com/f/gmodaddon/...rys-Mod/1/
Community Helper:
Fun ideas that have potential to work in Garry's Mod are always good ideas that I will take apon myself to make possible, so if you need something done don't fear to ask.

Helped communities: 89
Time covered: 3 years
Ability: Lua Teaching, Experience Required Lua Development, Optimism and Leadership.

------ Current Project ----------
MultiverseRP (images only)



Looks sick man, nice job!

Users browsing this thread:
1 Guest(s)