I got a working modular interface for scripting :v

Started by EK.IceFlake, Sep 19, 2016, 05:31 PM

Previous topic - Next topic

EK.IceFlake

Modules are scripts which are loaded into memory, which basically behave like plugins
They got their own internal events, for example many modules can share onPlayerJoin for some stuff without even having to modify the actual engine (except for the module list which is an array)

Here are some modules I made:
cmds - pretty self explanatory
you use this function:
cmds.register(command, function) (or you can use cmds.registeradmin)
it will automatically show up in /cmds once you registered it

here is how it works: when you do for example:

function Slap(parameters)//parameters is an array which contains what the user wrote after the command
{
    FindPlayer(parameters[0]).Health -= 20;
}
cmds.register("slap", Slap);

this will now automatically show up in /cmds and whenever the player types /slap it will call the function Slap



Here is an example source of a module

class cmds
{
    dependencies = ["message"];

    cmdls = {};
    cmdst = [];
    cmdsta = [];

    function Init() {}

    function register(command, func, admin=false) { cmdls.rawset(command, func); admin == false ? cmdst.push(command) : cmdsta.push(command); }

    function onplayercommand(player, command, parameters)
    {
        if (cmdls.rawin(command))
        {
            if (parameters == null) return cmls.rawget(command)();
            else return cmdls.rawget(command)(split(parameters, " "));
        }
        else if (command == "commands" || command == "cmds")
        {
            foreach (cmd in cmdst)
            {
                message.writeplayer(player, "i", cmd);
            }
        }
    }
}

Note: the dependencies checker is not done yet


I am not releasing this right now because it is not complete, however if you want it right now just reply and I will give it to you



:edit: the snippet I gave requires the message plugin, here it is
class message
{
    function Init() {}
    function write(type, msg)
    {
        switch (type)
        {
            case "i": ::MessageAll("[#00C2C2]Information: [#FFFFFF]" + msg); break;
            case "e": ::MessageAll("[#00C2C2]Error: [#FFFFFF]" + msg); break;
        }
    }
    function writeplayer(player, type, msg)
    {
        switch (type)
        {
            case "i": ::MessagePlayer("[#00C2C2]Information: [#FFFFFF]" + msg, player); break;
            case "e": ::MessagePlayer("[#00C2C2]Error: [#FFFFFF]" + msg, player); break;
        }
    }
}

Murdock


EK.IceFlake

Quote from: Murdock on Sep 20, 2016, 07:02 AMEver heared of naming conventions?
Yeah, I was wondering which one to use
I hate camel case so that is out
I decided to use the underscores one (mysql_connect etc.) but I didnt feel like using that
I decided to use hungarian notation (nPlayerId) but decided it will prevent me from using the advantage of dynamic types
I finally decided to just use lowercase names

Murdock

Quote from: EK.CrystalBlue on Sep 20, 2016, 11:26 AM
Quote from: Murdock on Sep 20, 2016, 07:02 AMEver heared of naming conventions?
Yeah, I was wondering which one to use
I hate camel case so that is out
I decided to use the underscores one (mysql_connect etc.) but I didnt feel like using that
I decided to use hungarian notation (nPlayerId) but decided it will prevent me from using the advantage of dynamic types
I finally decided to just use lowercase names

Hungarian notation is discouraged pretty much everywhere now. Why mix your own conventions with squirrel's anyway, makes it look messy.

EK.IceFlake

Quote from: Murdock on Sep 21, 2016, 09:37 AM
Quote from: EK.CrystalBlue on Sep 20, 2016, 11:26 AM
Quote from: Murdock on Sep 20, 2016, 07:02 AMEver heared of naming conventions?
Yeah, I was wondering which one to use
I hate camel case so that is out
I decided to use the underscores one (mysql_connect etc.) but I didnt feel like using that
I decided to use hungarian notation (nPlayerId) but decided it will prevent me from using the advantage of dynamic types
I finally decided to just use lowercase names

Hungarian notation is discouraged pretty much everywhere now. Why mix your own conventions with squirrel's anyway, makes it look messy.
Because you aren't required to follow the conventions if you're writing your own code, which means you can come up with conventions you prefer.

:edit: There is still time to change it to underscore convention, if you think its a good idea tell me before I continue work on the module.