Toolbox v4.2.1
Last update:
July 4, 2014This is a beta version of the mod.
It doesn't add any new sprites, sound, monsters etc., also it doesn't change gameplay.
This mod was made to simplify process of merging different mods together and it is provided to gamemoders.
"Toolbox" have several functions (only 11 atm, divided into 3 groups) for other mods. Here they are:
FunctionsMods communication groupRegisterMod ( name, version )
RegisterMod ( name, version, folder )
IsModRegistered ( name ) --returns true or false
GetRegisteredMod ( name ) --returns result of require(name) or nil
GetModVersion ( name ) --returns version or nil
IsModEnabled ( name ) -- return true / false / (nil if the mod was not found)
RegisterMod ( name, version ) - declares the fact what your mod is installed on this server + provides version of your mod. It is expected, what name of folder name matches mod's name. It is recommended to call this function at the end of your "init.lua" file (after main initialization of your mod).
RegisterMod ( name, version, folder ) - same thing, but for mods with different "name" and folder name inside of knights_data/server/. Otherwise, recommended use: T.RegisterNamedMod("mod_name", mod_version, ...) - "..." will be automatically replaced with foldername of your mod.
IsModRegistered - checks whether the mod is installed on this server.
GetRegisteredMod - returns same value as require() function if the mod was registered, nil otherwise
GetModVersion - returns version of the mod if it was registered, nil otherwise
IsModEnabled - will return true if the mod is enabled/not supports enabling system; nil if the mod wasn't found; false if the mod is disabled.
Implement
toolbox_enable (S) and
toolbox_disable (S) functions in your mod to add it into "Enable/Disable mod" list.
HooksRegisterHook( hook, id, function ) -- returns true (success) or false (fail)
DeleteHook( hook, id )
Correct types for hook variable are:
"WEAPON_DOWNSWING", "WEAPON_PARRY", "KNIGHT_DAMAGE", "CREATURE_SQUELCH", "SHOOT", "MISSILE_MISS"
Using this you can install hook at any time (even ingame) and remove it without problems.
Example:
local T = require("toolbox")
function ouch()
print("Ouch!")
T.DeleteHook("KNIGHT_DAMAGE", "mymod_ouch")
end
T.RegisterHook("KNIGHT_DAMAGE", "mymod_ouch", ouch)
This code will write "Ouch!" when the knight was hit in a first time.
Pretty easy, imho.
Action ListenersAction Listeners is an unofficial analog of hooks system.
AL_AddListener ( action_id, function_id, function )
AL_DeleteListener ( action_id, function_id )
AL_SendAction ( id, argument )
AL_AddListener - declares what you want to listen "action_id" action using "function" with "function_id" identificator (a string to identify your listener).
AL_DeleteListener - removes previously installed listener using its identificator.
AL_SendAction - sends the argument to all listeners of this action. Returns last non-nil value given by listeners.
Default Actions (events):"GAME_START" - called when the match starts (same effect as editing kts.MENU.start_game_func by yourself)
"GAME_PREPARE" - called before dungeon generation (kts.MENU.prepare_game_func)
"RESPAWN" - called when knight is preparing to spawn. Gives a player as parameter of the function. You can return a position to spawn this knight in.
"MOD_REGISTERED" - called every time some mod was registered. Gives a name of the mod as an argument.
Also, using this you can make your own "hooks" and events.
Example:
--FIRST MOD
local T = require("toolbox")
function spawned_1 (location)
print("Oh no, spiders are coming!")
T.AL_DeleteListener ( "spiders_spider_spawned", "f1" )
end
function spawned_2 (location)
print("A spider spawned at "..location.x.." "..location.y)
end
T.AL_AddListener ( "spiders_spider_spawned", "f1", spawned_1 )
T.AL_AddListener ( "spiders_spider_spawned", "f2", spawned_2 )
--ANOTHER MOD
local T = require("toolbox")
--...some functions are here
function spawn_a_spider()
T.AL_SendAction ( "spiders_spider_spawned", {x=15, y=20} )
--...
end
This code will print "Oh no, spiders are coming!" at first appear of this event and print given coordinates (as example, you can use any type of parameter) every time.
A configuration fileYou can edit "config.lua" file to change some behavior of the mod.
DEFAULT_MOD_STATE = "on" -- if you will set this to "off" value - all switchable mods will be disabled by default.
Recent changes (also take a look at changelog.txt)
Version 4.2
26.06.2014
Duel to the Death black screen problem fixed
Installation1) Download "toolbox.zip" from attachments
2) Unzip it into "<path to your knights>\knights_data\server"
3) Put '
require ("toolbox")' line into "knights_data\server\main.lua"
Warning! Put it right after '
require ("classic")', as here:
require ("classic")
require ("toolbox")
require ("spiders_v2")
require ("multiwand")
require ("heroes")
Because it should be loaded before any other mods.
____________________________________________
Any questions, comments and suggestions are welcome.
Feel free to study and use any part of the source code.