/*
*
*
*   *    *    *****   *****        *       *****    *    *    *****   *    *   *       *
*   *    *   *             *      * *      *    *   *   **   *        *   **   * *   * *
*   ******   ******   ******     *   *     ******   *  * *   *        *  * *   *  * *  *
*   *    *   *             *    *******    *    *   * *  *   *        * *  *   *   *   *
*   *    *    *****   *****    *       *   *****    *    *    *****   *    *   *       *
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* AMX MOD X script.                                                 *
* Plugin made by He3aBuCuM(a.k.a. independent).                     *
* Important! You can modify the code, but DO NOT modify the author! *
* Please, come in www.Mehanata.org!                                 *
* Contacts with me:                                                 *
* E-mail: nezavisimm@gmail.com                                      *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* * * * * * * * * * * * * * *
* Special thanks to:        *
* hateYou@amxmodxbg.org     *
* ConnorMcLeod@amxmodx.org  *
* xPaw@amxmodx.org          *
* darkspeed@amxmodxbg.org   *
* * * * * * * * * * * * * * *
*
*
*/

#include <amxmodx>
#include <amxmisc>

new cvar_message, cvar_color, cvar_location, cvar_effects, cvar_show, hudsync

public plugin_init() {
    register_plugin("Permanent message", "1.0", "He3aBuCuM")
    cvar_message = register_cvar("amx_permanent_message", "Your/nadvertisement%new%here")
    cvar_color = register_cvar("amx_permanent_message_color", "255 255 255")
    cvar_location = register_cvar("amx_permanent_message_location", "3")
    cvar_effects = register_cvar("amx_permanent_message_effects", "0")
    cvar_show = register_cvar("amx_permanent_message_show", "0")
    hudsync = CreateHudSyncObj()
    set_task(1.0, "show_hud", 0, "", 0, "b")
}

public show_hud() {
    new message[200], location, eff, show, players[32], inum
    static red, green, blue
    get_pcvar_string(cvar_message, message, charsmax(message))
    get_hud_color(red, green, blue)
    location = get_pcvar_num(cvar_location)
    eff = clamp(get_pcvar_num(cvar_effects), 0, 2)
    show = get_pcvar_num(cvar_show)
    get_players(players, inum)

    replace_all(message, charsmax(message), "%new%", "^n")
    replace_all(message, charsmax(message), "/n", "^n")

    switch(location) {
        case 1: set_hudmessage(red, green, blue, 0.01, 0.15, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 2: set_hudmessage(red, green, blue, -1.0, 0.15, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 3: set_hudmessage(red, green, blue, 0.99, 0.15, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 4: set_hudmessage(red, green, blue, 0.01, -1.0, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 5: set_hudmessage(red, green, blue, -1.0, -1.0, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 6: set_hudmessage(red, green, blue, 0.99, -1.0, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 7: set_hudmessage(red, green, blue, 0.01, 0.75, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 8: set_hudmessage(red, green, blue, -1.0, 0.75, eff, 1.0, 1.0, 0.1, 0.2, -1)
        case 9: set_hudmessage(red, green, blue, 0.99, 0.70, eff, 1.0, 1.0, 0.1, 0.2, -1)
    }

    for(new i=0; i<inum; ++i) {
        switch(show) {
		    case 0: ShowSyncHudMsg(0, hudsync, message)
            case 1: {
                if(!is_user_alive(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            case 2: {
                if(is_user_alive(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            case 3: {
                if(is_user_admin(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            case 4: {
                if(!is_user_admin(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            case 5: {
                if(is_user_admin(players[i]) && is_user_alive(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            case 6: {
                if(is_user_admin(players[i]) && !is_user_alive(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            case 7: {
                if(!is_user_admin(players[i]) && is_user_alive(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            case 8: {
                if(!is_user_admin(players[i]) && !is_user_alive(players[i]))
                    ShowSyncHudMsg(players[i], hudsync, message)
            }
            default: ShowSyncHudMsg(0, hudsync, message)
        }
    }
    return PLUGIN_CONTINUE
}

get_hud_color(&r, &g, &b) {
    new color[20]
    static red[5], green[5], blue[5]
    get_pcvar_string(cvar_color, color, charsmax(color))
    parse(color, red, charsmax(red), green, charsmax(green), blue, charsmax(blue))

    r = str_to_num(red)
    g = str_to_num(green)
    b = str_to_num(blue)
}