This is almost exactly how the Zombie API is intended to work.
The only difference is that the function callbacks in hooks are not type safe:
PHP Code:
stock bool:AddHookIfExists(bool:bHookManLoaded, &iBitArray, iBitToCheck, const String:sHookName[], Function:fFunc, const String:sPassedHook[])
If I pass a function with no parameters into fFunc, while the hook actually expect it to have parameters, it will crash.
This is solved with functags, which also means we'll have to create a hook native for every single type of callback. It's quite similar to adding listeners in Java, where each type of event has it's own method for registering listeners for a particular event. I think this is called the
observer pattern.
A native for hooking events may accept a group (enum array) of callbacks specified with functags so that we don't have to create that many natives. But only group callbacks that makes sense, such as OnClientInfect, OnClientHuman or OnRoundStart and OnRoundEnd.
Type safety on event callbacks is absolutely essential. We
must catch these errors as early as possible (which is on compile time). Otherwise the API won't be robust enough. Developers
will make silly typo mistakes, or forget to update the callback function signature when the hook is changed. Although a hook callback type should not be changed after a release, that would break backwards compatibility.
MVC pattern
Otherwise I think we should go for something based on a MVC pattern so that code is loosely coupled and easier to maintain.
An example for the player class system would be something like below. It is simplified a lot because my idea for the class system is also based on event listeners and plugins for each class attribute (or a group of them).
Model:
The player class. One include file (or API) that provides operations on a single player class such as getters and setters.
Repository:
The class database. Stores all classes in memory and provides an API for inserting, and searching.
Controller/Manager:
Player class logic. API for applying a class on a player, doing stuff on infection, round start and so on.
__________________