Bug Reporting Plugin

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1327
Gender:
United States of America

Bug Reporting Plugin

Post by Archive-Poster »

Being under 50 lines i didn't see this fit as a "release" plugin. But i thought some might find it useful on public test servers. If not....its a good example of how to pull apart say and say_team messages and text and then print them to a log.

DESCRIPTION: This plugin gives users of a server the ability to report any sort of bugs they see to a developer with a simple command "/bugreport [bug]"

The bug then gets logged to a defined log file with the reporter's name so you can look at it later. It also helps when you're testing, you don't have to write all that stuff down, and you can keep it permanently.

Happy developing!

Here is the code all commented out as the tutorial. If you have any questions or i'm unclear, please don't be afraid to comment.

Code: Select all

/* 
    This gives users of a server the ability
    to report a bug via chat commands.
    Also includes an advertisement (toggleable)
    
    */

#include <amxmodx>

#define PLUGIN "Bug Report"
#define VERSION "1.0"
#define AUTHOR "Liverwiz"

    // This is a string that determines the file in which to log bugs
new const LogFile[] = "BugLog.log"
    // This can be commented out to disable advertising
    // the value determines how often (in seconds) the message is displayed
#define ADVERTISE 30.0

public plugin_init() 
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
        /* these register commands with the core to catch
         when users "say" with 'y' or "team say" with 'u'  */
    register_clcmd("say", "handleSay")
    register_clcmd("say_team", "handleSay")
    
        /* This is a preprocessor if-statement it allows
        lines to be executed while the condition is true
        In this case i checked to make sure ADVERTISE is defined
        otherwise ADVERTISE won't be found and will then have an
        error on compilation. Every #if statement must be closed
        with an #endif (much like the brackets)    
        
        The set_task sets a task to run the function "advertise"
        every ADVERTISE seconds. 0 is the id (irrelevant in this
        example, but important in many other situations. You can 
        skip paramaters in a stock function (like set_task) 
        if they have a default value. Then define
        what parameters you wish with a period (.) then the 
        parameter name = value i.e. (.flags="a") You may also
        skip parameters with underscores ( _ ) This is also quite
        common and is easier for some people to see. I prefer this
        method because you can see exactly what variables you're 
        working with. It is important to know if you go this rout
        EVERY paramater after will require this sort of definition */
#if defined ADVERTISE 
    set_task(ADVERTISE, "advertise", 0, .flags="a")
#endif
}

public handleSay(id)
{
        // This defines all variables we will be using later
        // sz is a Hungarian Notation prefix for "string"
        // szInput is set at 192. that is the maxlen of a chat string
    new szInput[192], szCommand[32], szBug[192], szName[32]
    
        /* This takes all arguemtns passed to the function and outputs
         them as a string    */
    read_args(szInput, charsmax(szInput) )
        // Remove quotes so there is no confusions in handling
    remove_quotes(szInput)
    
        /* This seperates the input into two strings a right and left
        left is szCommand and right is szBug. The string is seperated
        at the first space unless contained in quotes    */
    strbreak(szInput, szCommand, charsmax(szCommand), szBug, charsmax(szBug) )
    
        // This checks to make sure they are using the right command
    if(!equali(szCommand, "/reportbug") && !equali(szCommand, "/bugreport") )
        return PLUGIN_CONTINUE 
        
        // Gets user name and stores it into szName
        /* I see a lot of peole using a hardcoded number instead
        of charsmax(szName). This is bad practice. And you will
        also find this to be an inconvenience later if you change
        the length of the string. Remember to use charsmax(string) */
    get_user_name(id, szName, charsmax(szName) )
    
        // Logs  it to the indentified Log File
    log_to_file(LogFile, "%s: %s", szName, szBug)
    
        // Shows our appreciation for bug reports. 
    client_print(id, print_chat, "[AMXX] Thanks for the report! I appreciate your support!")
    
    return PLUGIN_HANDLED
}
    // This prints an advertisement from the task. 0 as the id means "all clients" 
public advertise(id)
    client_print(0, print_chat, "[AMXX] Notice a bug with a plugin? Type '/bugreport' with a short description and we'll get it taken care of!") 
Attachments
bug_report.sma.zip
(857 Bytes) Downloaded 7 times

Who is online

Users browsing this forum: No registered users and 1 guest