The CS2D Dynamic Menu Library (TCDML for short) is what you'd expect it to be. With the table structure and parsing being based on Engin33r & VADemon's unimenu, it provides many functionalities for full control over your menu(s). It's been tested and works great with Inventory Menus or any menu that is dynamic and requires rapid updates to its contents.
TCDML is still stable and working as any other menu script but I plan to add more functionality.
If you want to have a quick look at how TCDML works, check out main.lua.
Like any other LUA script for CS2D, include dmenu.lua to /sys/lua/server.lua or drop it in sys/lua/autorun/startup.lua is for the Y.A.T.E.S. plugin so it's not required.
Y.A.T.E.S. Admin Script Plugin Installation
Y.A.T.E.S. has a plugin feature which DMenu now supports.
All you need to do is drop dmenu folder (yes, the whole folder) in Y.A.T.E.S. plugin directory. By default that should here sys/lua/yates/plugins/. Once you've done so, the dmenu folder in the plugin directory there only requires the startup.lua file so you can delete the rest.
Configuration
The only configuration in here is logging. Open dmenu.lua and check out lines 9-11 (it won't melt your steel beams).
dmenu.log will switch the whole log process on/off. Logs are done by using print() and the log text can be found in your server console or your cs2d log files.
dmenu.debug will/will not log debug messages
dmenu.error will/will not log error messages
if dmenu.log is false then neither will it log debug or error messages!
Rolling it out
You need to hook 3 functions or simply include these functions in their respective hooks.
dmenu.Construct(id) needs to be added in the Join hook.
**Recommended**
addhook("join", "_join")
function _join(id)
dmenu.Construct(id)
end
**or**
addhook("join", "dmenu.Construct")
dmenu.Destruct(id) needs to be added in the Leave hook.
**Recommended**
addhook("leave", "_leav")
function _leave(id)
dmenu.Destruct(id)
end
**or**
addhook("leave", "dmenu.Destruct")
dmenu.Hook can directly be added as a hook function.
addook("menu", "dmenu.Hook")
You're done setting it up! Now lets head to the functions TCDML provides!
Documentation
# dmenu:display
Function
dmenu:display(id, menuName {,page})
Parameters
id (integer, player ID), menuName (string, internal name of the menu), page (integer, you know what this is)
Returns
brings up the menu in-game or false
Info
This function is usually added in the serveraction hook and as button functions to bring up other menus (such as the next page)
Example
dmenu:display(id, "Inventory")
# dmenu:add
Function
dmenu:add(id, menuName)
Parameters
id (integer, player ID), menuName (string, internal name of the menu)
Returns
true
Info
Before utilizing a menu, you need to construct it. menuName becomes the internal ID of the menu and you can further on access the menu with other functions with this ID
id (integer, player ID), menuName (string, internal name of the menu), itemArr a valid TCDML menu array
Returns
true or false
Info
This method link a valid TCDML menu array to a menu. If you use a local menu array in a function, it will be destroyed once the function ends so the link will become a nil value. So use this for pre-set or global menu arrays.
id (integer, player ID), menuName (string, internal name of the menu)
Returns
true or false
Info
This method will empty the items/buttons from a valid TCDML menu array
Example
--updating the list of players
dmenu:empty(id, "Players List")
for _,pid in ipairs(player(0, "table")) do
dmenu:addButton(id, "Players List", player(pid, "name"), player(pid, "usgn"), nil, false, id)
end
# dmenu:exists
Function
dmenu:exists(id, menuName)
Parameters
id (integer, player ID), menuName (string, internal name of the menu)
Returns
true or false
Info
Checks whether if a menu with the internal menu id menuName exists
Example
if dmenu:exists(id, "Inventory") do
print('Inventory exists!')
else
print('or does it?')
end
id (integer, player ID), menuName (string, internal name of the menu), offset (integer, the item/button offset in the menu array, state (boolean, enable/disable the button)
Returns
true or false
Info
Enable/Disable the button by offset
Example
dmenu:setButtonName(id, "Inventory", 4, false) --disable this button
id (integer, player ID), menuName (string, internal name of the menu), offset (integer, the item/button offset in the menu array), new description (string)
id (integer, player ID), menuName (string, internal name of the menu), buttonNameMatch (string, regex)
Returns
integer
Info
Matches string or regex from the list of buttons in a menu and returns the offset of the button
Note!
Multiple matches return offsets in an array!
Example
local matches = dmenu:getButtonPropertyByButtonNameMatch(id, menuName, "Button")
# dmenu:playerMenuObjectExists
Function
dmenu:playerMenuObjectExists(id)
Parameters
id (integer, player ID)
Returns
boolean
Info
Checks if the main menu array of a player is set
Note!
Not the same as dmenu:exists!
Example
print('player menu initialization is '..tostring(dmenu:playerMenuObjectExists(id)))
# dmenu:isEmpty
Function
ddmenu:isEmpty(id, menuName)
Parameters
id (integer, player ID), menuName (string)
Returns
boolean
Info
Checks whether a menu is empty or not
Example
if dmenu:isEmpty(id, "Inventory") then
msg('Inventory is empty!')
else
dmenu:display(id, "Inventory")
end
Changelog
1.3.0.0 {
- Made README.md more easier to navigate
- Added an example directory filled with some common usage examples and scripts
- Fixed documentation errors
- Added Y.A.T.E.S. plugin support
- Added more configuration options
- Error and Debug Log Prints are colored in the console
- dmenu:switchButton is renamed to dmenu:setButtonState
- Added moar functions
- dmenu:setButtonName
- dmenu:setButtonDescription
- dmenu:setButtonFunction
- dmenu:getButtonPropertyByButtonNameMatch(id, menuName, buttonNameMatch)(This supports regex matching!)
- dmenu:getPlayerMenuCount(id)
- dmenu:playerMenuObjectExists(id)
- dmenu:isEmpty(id, menuName)}1.2.0.0 {
- Stable release
}0.1.0.0 {
- Initial Git alpha release
}