[SCRIPT] h0tmod (alpha) - Script Plugin Framework

  • I'm slowly rewriting my h0tstuff script into something more manageable / extendable. Figured I would share my progress. I'm not running this on my server yet.


    Right now it is basic plugin framework and a couple example modules; Welcome Message and Motd.
    Suggestions appreciated.


    https://github.com/Clarkmania/rising-world-h0tmod


    Supports run-time hooking of events, commands, and timers. Will be adding an admin module next for enabling and disabling modules on the fly.

  • Lots of fixes and updates today. Main show stopper from me running this on my main server is the lack of privilege support. Will be working on that in the next day or two.


    Below is an example Message of the day module.

    • Automatically displays the latest message on login
    • Message display every hour to connected players
    • Adds /motd command with three actions (broadcast, list, set)
    • Adds motd help information to the /help command (framework built-in)


    [lua]
    -- Copyright (c) 2014, Jeffrey Clark. This file is licensed under the
    -- Affero General Public License version 3 or later. See the COPYRIGHT file.


    modMotd = {
    new = function()
    self = ModBase.new()
    self.name = "Message of the day"
    self.author = "h0tw1r3"
    self.version = 0.1


    -- Module initilization
    db:queryupdate("CREATE TABLE IF NOT EXISTS `motd` (`ID` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `time` INTEGER, `message` VARCHAR);");


    -- Internal methods
    self.broadcastMotd = function(self)
    server:brodcastTextMessage(self:prettyMotd())
    end


    self.prettyMotd = function(self, motd)
    if not motd then motd = self:getMotd() end
    return string.format("[#FFA500]** %s -- %s", motd.message, os.date("%x %X", motd.time))
    end


    self.getMotd = function(self)
    -- TODO: cache result
    local motd = { time = 0, message = "No message of the day" }
    result = db:query("SELECT * FROM motd ORDER BY time DESC LIMIT 1;")
    if result:next() then
    motd.time = result:getInt("time")
    motd.message = result:getString("message")
    end
    result:close()


    return motd
    end


    -- Client commands and help list
    self.commands['motd'] = {
    callback = function(event, command, action, message)
    if not action then
    event.player:sendTextMessage(self:prettyMotd())
    elseif action == "broadcast" then
    self:broadcastMotd()
    elseif action == "list" then
    -- TODO
    ModManager:sendPlayerCommandHelp(event.player, command, "list not implemented yet")
    elseif action == "set" and message then
    db:queryupdate("INSERT INTO motd (time, message) VALUES (strftime('%s', 'now'), '" .. message .. "')")
    event.player:sendTextMessage("motd set")
    else
    ModManager:sendPlayerCommandHelp(event.player, command, "Invalid command usage, see /help " .. command)
    end
    return true
    end,
    help = {
    "set <message>",
    "broadcast => send motd to all players",
    "list => show last 5 messages",
    " => show motd",
    }
    }


    -- Global timers
    self.timers['Broadcast'] = {
    -- Broadcast motd every 60 minutes, forever
    frequency = 3600,
    count = -1,
    callback = function() self:broadcastMotd() end
    }


    -- Event hooks
    self.events['PlayerSpawn'] = {
    callback = function(event)
    event.player:sendTextMessage(self:prettyMotd())
    end,
    }


    return self
    end
    }
    [/lua]

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!