/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <hamsandwich>

#define PLUGIN "PaintBall VIP"
#define VERSION "1.0"

#define ADMIN_CHECK ADMIN_LEVEL_H

static const COLOR[] = "^x04" //green
static const CONTACT[] = ""

new maxplayers
new gmsgSayText

public plugin_init() 
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
        
        register_clcmd("say /vip","ShowMotd")
        register_clcmd("say /infovip","ShowMotd")
        register_clcmd("say /info","ShowMotd")
        register_clcmd("say /vipinfo","ShowMotd")
        register_clcmd("say_team /vip","ShowMotd")
        register_clcmd("say_team /infovip","ShowMotd")
        register_clcmd("say_team /info","ShowMotd")
        register_clcmd("say_team /vipinfo","ShowMotd")

        RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1);
        
        maxplayers = get_maxplayers()
        gmsgSayText = get_user_msgid("SayText")
        register_clcmd("say", "handle_say")
        register_clcmd("say_team", "handle_say")
        register_cvar("amx_contactinfo", CONTACT, FCVAR_SERVER)
}

public fwHamPlayerSpawnPost(id)
{       
        if(is_user_alive(id) && get_user_flags(id) & ADMIN_LEVEL_H)
        {
                if(task_exists(id + 666))
                        remove_task(id + 666);
                        
                set_task(2.0, "doGiveGrenades", id + 666);
        }
}

public doGiveGrenades(task_id)
{
        new id = task_id -= 666;
        
        if(id > get_maxplayers() || id < 1)
                return PLUGIN_HANDLED;
                
        set_user_health(id, 200);
        give_item(id, "weapon_smokegrenade");
        give_item(id, "weapon_hegrenade");
        give_item(id, "item_thighpack");
        give_item(id, "weapon_p90");
        give_item(id, "weapon_primammo");
        give_item(id, "weapon_primammo");
        
        return PLUGIN_CONTINUE;
}
                
public ShowMotd(id) 
        show_motd(id, "vip.txt")

public handle_say(id) 
{
        new said[192]
        read_args(said,192)
        if( ( containi(said, "who") != -1 && containi(said, "vips") != -1 ) || contain(said, "/vips") != -1 )
                set_task(0.1,"print_adminlist",id)
        return PLUGIN_CONTINUE
}

public print_adminlist(user) 
{
        new adminnames[33][32]
        new message[256]
        new contactinfo[256], contact[112]
        new id, count, x, len
        
        for(id = 1 ; id <= maxplayers ; id++)
                if(is_user_connected(id))
                        if(get_user_flags(id) & ADMIN_CHECK)
                                get_user_name(id, adminnames[count++], 31)

        len = format(message, 255, "%s VIP'y online: ",COLOR)
        if(count > 0) {
                for(x = 0 ; x < count ; x++) {
                        len += format(message[len], 255-len, "%s%s ", adminnames[x], x < (count-1) ? ", ":"")
                        if(len > 96 ) {
                                print_message(user, message)
                                len = format(message, 255, "%s ",COLOR)
                        }
                }
                print_message(user, message)
        }
        else {
                len += format(message[len], 255-len, "Brak VIP'ow online.")
                print_message(user, message)
        }
        
        get_cvar_string("amx_contactinfo", contact, 63)
        if(contact[0])  {
                format(contactinfo, 111, "%s Kontakt z H@ znajdziesz na forum www.cskaskada.xaa.pl %s", COLOR, contact)
                print_message(user, contactinfo)
        }
}

print_message(id, msg[]) 
{
        message_begin(MSG_ONE, gmsgSayText, {0,0,0}, id)
        write_byte(id)
        write_string(msg)
        message_end()
}