CAF: Custom Addon Framework

[release]Custom Addon Framework[/release]

Official website: http://www.snakesvx.net/

What is it?

Like some of you already know it is used by LS3, RD3, SB3, … to add support to enable/disable the addons when needed. This is only part of what CAF is used for or will be used for in the future. So does CAF add support for using different Languages (wip), alles addons to set their ‘required’ addons, so they won’t be started without them, can have an autoStart feature…

In short: CAF is meant to be there to help the dev to integrate certain actions easily without having to write all the code themselves for it and thus also makes it easier for the User (Server Admins for example) to find out about these features since they can be found in the CAF Main Menu.

What addons are using it so far?

[ol]
[li] Full CA’s (Custom Addons)
[/li][ul]
[li] Life Support 3
[/li][li] Resource Distribution 3
[/li][li] Spacebuild 3.1
[/li][li] SpaceAge (Private Addon)
[/li][list]Servers:
[li] server 1 Pacifist: 80.86.82.80:27015
[/li][li] server 2 War: 80.86.82.80:27025
[/li][li] server 3 Faction only 80.86.82.80:27035
[/li][/ul]
[/ol]
[li] Partial CA’s
[/li][ul]
[li] Life Support 1 and 2 : Added to Life Support 3 to show if they are installed or not (is hidden when not installed)
[/li][li] Resource Distribution 1 and 2 : Added to Resource Distribution 3 to show if they are installed or not (is hidden when not installed)
[/li][li] Life Support Entities : Informational + Stools
[/li][li] SBEP : Information + Stools
[/li][/ul]
[li] Future addons that might use it
[/li][ul]
[li] GCombat (Optional support, CAF won’t be required)
[/li][/ul]
[/list]

List of Features
[ul]
[li] Upgraded STOOL system which TAD2020 originaly made for RD2
[/li][list]
[li] makes it easier to Spawn Sents with, but can still be used everything else!
[/li][li] some example (For complete examples check the Life Support Entities CAF/Stools folder)
[/li][li] Models/Entities can be added to the Stools, without having to Modify the Stools themselves…
[/li]



/*
	TOOL.AdminOnly 			= true //Make the Stool admin only
	TOOL.EnableFunc  = function(ply) return true or false end (Optional)
	
	
	type = {
		type			= "entity type", --same as key (optional). typically same as class
		class			= "entity class", --entity class used by ents.Create() (optional if type is class)
		Name			= "Print Name used for device catagory in tool",
		legacy		= true, --if _WHOLE_ group contains _ONLY_ ents that are from orginal ls2 (optional) this is for old dupe saves that use model as a sub type
		hide			= true, --if this group should be hidden on the control panel (optional)
		
		MakeFunc		= function(tool, ply, Ang, Pos, type, sub_type, model, frozen, Extra_Data, devinfo) return ent end (optional)
		MakeFuncReturn	= true, --skips rest of make rd2 ent function and returns ent (optional)
		EnableFunc  = function(ply) return true or false end (Optional)
		func			= function(ent,type,sub_type,devinfo,Extra_Data,ent_extras) addres(ent) return mass, maxhealth end (optional)
		AdminOnly		= true/false //Make the Device group Admin only
		devices = {
			sub_type = {
				Name		= "Print Name for this sub_type in tool",
				type		= "entity class", can be different than group type (optional)
				class		= "entity class", --entity class used by ents.Create() (optional if type is class or if same as group.class or group.type)
				model		= "path/to/model",
				skin		= # for skin, (optional)
				res			= {coolant = 4000},
				EnableFunc  = function(ply) return true or false end (Optional)
				maxhealth	= 300,
				mass		= 20,
				legacy	= true, --if ent is from ls2 (optional)
				hide		= true, --if this sub_type should be hidden on the control panel (optional)
				ent_extras	= {}, --table of exra info to copy to ent (optional)
				AdminOnly		= true/false //Make the Device Admin only
			},
			sub_type = {
				Name		= "Print Name for this sub_type in tool",
				model		= "path/to/model",
				material	= "path/to/material", (optional)
				func		= function(ent,type,sub_type,devinfo,Extra_Data,ent_extras) addres(ent) return mass, maxhealth end (optional)
			},
		},
	},
*/


[/ul]
[li] Enable/disable (Status) Support: Using some simple functions you can add support for CAF to be able to enable/disable your addons. This is also saved to the sqlite db so it’s stored accross sessions. Clients will also be able to see clientside if your addon is active or not.
[/li][li] Help/Info Support (WIP): In the CAF menu is a TAB that’s able to show people Help/info HTML pages. You can set 2 links per info/help page: 1 local (data directory), 2 Internet. CAF will show the Internet link if their is internet, otherwise it will show the page in Data if there is one available.
[/li][li] Simple Multilanguage support
[/li]



CAF.GetLangVar("I want this translated").

This could return
1) this sentence if found in the set language
2) this sentence if found in the default language
3) the sentence ifself as given to the LangVar Function

LanguageVars can be added using lua files to the CAF/LanguageVars folder, CAF will handle the rest like Sending it to the Client, Loading the vars both Server and clientside, ...


[li] Various other support features like ‘showing’ if your addon is up to date, support to add your own Clientside and/or serverside menu/buttons straight into the CAF menu for your Addon.
[/li][li] …
[/li][/list]

The future?

There are plans to add even more features (requested) or thinks I come up with myself.
The system works and it makes it easier (especially for servers) to for example Enable/disable addons without having to remove/install them all the time.

Can I help?

Sure, if you have some ideas for CAF or have things you might think could be usefull for other Devs (like Helpe code for various things commonly used) or are just good at Derma/VGUI and want to make the CAF menu look a whole lot better.
There is only 1 requirement: That you want to help to make Addons/CAF better in the future, and not just to get your name added to the credits later on.

I’m not good at lua or any of that other stuff but I know some lua-modules that could be usefull

Well let me know. I’ll check it out and if it’s really usefull I’ll ask the author if I can add it to CAF.

Notes

[ul]
[li] CAF is still a WIP, this means there might still be bugs or things changing
[/li][li] CAF isn’t just another ‘Required’ addon, it helps to reduce commonly used code and/or add it’s own functions to help make addons have more features. (Would LS and RD, … have the ability to be enabled/disabled otherwise?
[/li][li] CAF isn’t able to unload Stools/Entities/Models/Textures/… at the moment. (Probably never will be).
[/li][/ul]

Screenshots

To be added

[release]**SVN links:**http://www.snakesvx.net/index.php/module_Wiki/title_Help_Info_SVN[/release]

It sounds good and all, but I have a few questions…

[ul]
[li]How exactly can I integrate it into my addons? Would I have to write my addons in a specific plugin format to be displayed in your menu and be open to the framework, or is there a much smoother and unnoticeable integration?[/li][li]How well-optimised is it? An addon like this needs to be very light and do minimum impact to the game.[/li][/ul]

Certain standard have been made yes, to allow addons to be used with CAF. In most cases these are just functions you have to (or can optionally) implement.
So are functions __Construct, __Destruct, GetStatus required, while others like GetCustomStatus, __AutoStart, GetRequiredAddons, … are optional.

There are also predefined folder structures available, but you don’t have to use them if you don’t want to. The AddonRegister functions remains available even after CAF loaded all the addon found in the default folders. The only difference is that you’ll have to take care of sending the required files to the client while CAF auto sends all files in the Client and Shared folders to the client.

When it comes to optimized, so far I haven’t heard any complaints about their servers running slowly or anything like that. So are there certains timers implemented into CAF, which only run if there is something that needs them.

I tried to keep everything as lite as possible so it doesn’t affect the system in any way. Some things that might require optimizing though like the Menu generated clientside. Could also be improved in how it looks for example.

For the rest it’s usualy up to the Addons to make it so they are optimized themselves.
With the enable/disable funtions for example you can clear any hooks you aren’t using anymore for example.

SB Example:



--Serverside
/**
	The AutoStart functions
	Optional
	Get's called before/replacing __Construct on CAF Startup
	Return true = AutoStart (Addon got enabled)
	Return nil or false = addon didn't get enabled
*/
function SB.__AutoStart()
	Register_Sun()
	Register_Environments()
	if SB_InSpace == 1 then
		SB.__Construct();
	end
end

/**
	The Constructor for this Custom Addon Class
	Required
	Return True if succesfully able to start up this addon
	Return false, the reason of why it wasn't able to start
*/
function SB.__Construct()
	if status then return false , CAF.GetLangVar("This Addon is already Active!") end
	if SB_InSpace == 1 then
		hook.Add("PlayerNoClip", "SB_PlayerNoClip_Check", PlayerNoClip)
		hook.Add("PlayerInitialSpawn", "SB_PlayerInitialSpawn_Check", PlayerInitialSpawn)
		hook.Add("PlayerSay", "SB_PlayerSay_Check", PlayerSay)
		CAF.AddHook("think3", SB.PerformEnvironmentCheck)
		for k, v in pairs(player.GetAll()) do
			PlayerInitialSpawn(v);
		end
		status = true;
		return true
	end
	return false, CAF.GetLangVar("Not on a Spacebuild Map!")
end

/**
	The Destructor for this Custom Addon Class
	Required
	Return true if disabled correctly
	Return false + the reason if disabling failed
*/
function SB.__Destruct()
	if not status then return false , CAF.GetLangVar("This Addon is already disabled!") end
	hook.Remove("PlayerNoClip", "SB_PlayerNoClip_Check")
	hook.Remove("PlayerInitialSpawn", "SB_PlayerInitialSpawn_Check")
	hook.Remove("PlayerSay", "SB_PlayerSay_Check")
	CAF.RemoveHook("think3", SB.PerformEnvironmentCheck)
	status = false;
	return true;
end

/**
	Get the required Addons for this Addon Class
	Optional
	Put the string names of the Addons in here in table format
	The CAF startup system will use this to decide if the Addon can be Started up or not. If a required addon isn't installed then Construct will not be called
	Example: return {"Resource Distribution", "Life Support"}
	
	Works together with the startup Level number at the bottom of this file
*/
function SB.GetRequiredAddons()
	return {}
end

/**
	Get the Boolean Status from this Addon Class
	Required, used to know if this addon is active or not
*/
function SB.GetStatus()
	return status
end

/**
	Get the Version of this Custom Addon Class
	Optional (but should be put it in most cases!)
*/
function SB.GetVersion()
	return 3.1, CAF.GetLangVar("Beta")
end

/**
	Get any custom options this Custom Addon Class might have
	Not implemented yet
*/
function SB.GetExtraOptions()
	return {}
end

/**
	Get the Custom String Status from this Addon Class
	Optional, returns a custom String status, could be used if your addon has more then 1 status based on the options activated?
*/
function SB.GetCustomStatus()
	return
end

/**
	You can send all the files from here that you want to add to send to the client
	Optional
*/
function SB.AddResourcesToSend()
	
end

CAF.RegisterAddon("Spacebuild",  SB, "1") 

--Clientside
----Caf will call the Clientside __Construct, __Destruct function when the Addon got Enabled/Disabled successfully serverside.
/**
	The Constructor for this Custom Addon Class
*/
function SB.__Construct()
	hook.Add( "RenderScreenspaceEffects", "VFX_Render", Render );
	hook.Add( "RenderScreenspaceEffects", "SunEffects", DrawSunEffects );
	CAF.AddHook("think2", Space_Affect_Cl)
	status = true;
	return true
end

/**
	The Destructor for this Custom Addon Class
*/
function SB.__Destruct()
	hook.Remove( "RenderScreenspaceEffects", "VFX_Render");
	hook.Remove( "RenderScreenspaceEffects", "SunEffects");
	CAF.RemoveHook("think2", Space_Affect_Cl)
	status = false;
	return true
end

/**
	Get the Boolean Status from this Addon Class
*/
function SB.GetStatus()
	return status
end

/**
	Get the Version of this Custom Addon Class
*/
function SB.GetVersion()
	return 3.1, CAF.GetLangVar("Beta")
end

/**
	Get any custom options this Custom Addon Class might have
*/
function SB.GetExtraOptions()
	return {}
end

/**
	Gets a menu from this Custom Addon Class
*/
function SB.GetMenu(menutype, menuname)//Name is nil for main menu, String for others
	local data = {}
	return data
end

/**
	Get the Custom String Status from this Addon Class
*/
function SB.GetCustomStatus()
	return
end

/**
	Returns a table containing the Description of this addon
*/
function SB.GetDescription()
	return {
				"Spacebuild Addon",
				"",
				"Prviously a Gamemode",
				""
			}
end

CAF.RegisterAddon("Spacebuild",  SB, "1") 


This is just the CAF side of the SB addon, most code in the files are the other functions that are custom to SB itself.

So this is basically a addon maker?

No, it allows addons to be enabled/disabled at runtime.

Added SpaceAge to the list of Addons using CAF.

SpaceAge is an Extension to SB which adds goals, mining and more.
It’s currently only available on the following servers:
[ul]Servers:
[li] server 1 Pacifist: 80.86.82.80:27015
[/li][li] server 2 War: 80.86.82.80:27025
[/li][li] server 3 Faction only 80.86.82.80:27035
[/li][/ul]

EVE Online like?

So, I noticed the Black Hole Cache is in CAF format, but it is no where to be seen on any of my spawn (or tool) lists.

Any ideas why that is?

Besides that, I like the CAF idea, it is nice being able to turn off addons if I can’t even use them on a map

Well I would have to see the code (svn?) for it to see what the problem is. My best guess it that it hasn’t been updated yet. There was a folder change while back which changed the folder structure to be a bit nicer. Before you had stuff like caf_addons and caf_core, now it’s CAF/Addons and CAF/Core for example.

The CAF stuff

is C:\Program Files\Steam\steamapps*username*\garrysmod\garrysmod\addons\Black Hole Cache\lua\caf_addons\

client\BlackholeEnts.lua

server\BlackholeEnts.lua

The SVN address is;

http://jenovasmods.googlecode.com/svn/trunk/Blackhole Cache

There are currently no new updates (and I doubt there will be, the last time it updated was in September)

Yea, that’s the old folder structure. I’ll see to update it and put it on another svn…

Added Thread links to FP Spacebuild 3.1 and SpaceAge threads.

do I need this to see LS3?

yes.

RD, LS3 and SB3 won’t even load without it…

I’ve been looking through the LUA files in order to try and make the Blackhole Cache work with the new CAF update. Sadly, it’s not as simple as changing the addon into the new file structure used by CAF. When you change the file structure; in-game CAF reports that the Blackhole Cache is “Enabled (Not Yet Implemented)”. So there’s more somewhere that needs to be altered to bring this addon into line with the new CAF update.

I’m no expert at LUA coding so my attempts at fixing it are not going very well as you would imagine. Have you had much luck with it, snake?

Edit: I’m thinking that it might be that it has no associated STool with it…(?)

Any progress On getting the Blackhole Cache to work?
I’ve been messing around with it, but no luck :frowning:

Try this svn for it.



https://customaddons.googlecode.com/svn/trunk/Black Hole Cache


Let me know if it works or not. I didn’t test it…

No worky… Console Spam:

Unknown command: receptacles_extra_num
ERROR: Trying to derive entity black_hole_cache from non existant entity base_rd_entity!
ERROR: Trying to derive entity black_hole_cache from non existant entity base_rd_entity!
CAF/Core/server/tool_ents.lua:96: attempt to call method ‘SetPlayer’ (a nil value)
ERROR: Trying to derive entity black_hole_cache from non existant entity base_rd_entity!
[ents.Create( “prop_physics” )] This frame you have created 162105248 entities! (Lua Error!?)

Changing the “extra number” makes it worse.
Thanks for trying anyways

Well I can’t even access the SVN. “anonsvn” for both username and password does not authenticate - as usual. So either there’s different details or the SVN is offline atm. =/

Commited fix

[editline]04:40PM[/editline]

Remove the s from https.

so it’s just http://