#include <amxmodx>
#include <reapi>
#pragma ctrlchar '\'
#pragma semicolon 1
#if AMXX_VERSION_NUM < 183
#include <colorchat>
#define MAX_PLAYERS 32
#define PLATFORM_MAX_PATH 256
stock const NULL_STRING[1];
#endif
new const PLUGIN_NAME[] = "Knife DeathMatch: VIP Menu";
new const PLUGIN_VERSION[] = "1.0.3";
new const PLUGIN_AUTHOR[] = "Salvatore";
new const MESSAGE_PREFIX[] = "VIPMENU";
enum any: Items
{
ItemGravity,
ItemSpeed,
ItemExplosiveGrenade,
ItemMultijump,
ItemInvisiblity,
ItemMoney,
ItemHealthPoints
}
new bool: gbPlayerAttachedItems[MAX_PLAYERS + 1][Items], giPlayerUsedItems[MAX_PLAYERS + 1][Items];
enum MethodType
{
MethodSteam,
MethodName,
MethodIP
};
enum Config
{
//main section
BitsAccess,
MethodType: SaveMethod,
//items_limit section
ItemsLimit[Items],
ItemsAmount[Items]
}
new gConfig[Config];
new giMenuCallback;
new Trie: gpMapVector;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
RegisterHookChain(RG_CBasePlayer_Spawn, "HC_CBasePlayer_Spawn_Post", 1);
RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "HC_CBasePlayer_ResetMaxSpeed");
RegisterHookChain(RG_CBasePlayer_Jump, "HC_CBasePlayer_Jump_Post", 1);
giMenuCallback = menu_makecallback("VM_Callback");
register_dictionary("vipmenu.txt");
}
public client_putinserver(player)
{
arrayset(giPlayerUsedItems[player], 0, Items);
arrayset(gbPlayerAttachedItems[player], false, Items);
if (~get_user_flags(player) & gConfig[BitsAccess])
return PLUGIN_CONTINUE;
new szMethodInfo[32];
switch (gConfig[SaveMethod])
{
case MethodSteam: get_user_authid(player, szMethodInfo, charsmax(szMethodInfo));
case MethodName: get_user_name(player, szMethodInfo, charsmax(szMethodInfo));
case MethodIP: get_user_ip(player, szMethodInfo, charsmax(szMethodInfo), true);
}
TrieGetArray(gpMapVector, szMethodInfo, giPlayerUsedItems[player], Items) && TrieDeleteKey(gpMapVector, szMethodInfo);
return PLUGIN_CONTINUE;
}
public client_disconnected(player)
{
if (~get_user_flags(player) & gConfig[BitsAccess])
return PLUGIN_CONTINUE;
new szMethodInfo[32];
switch (gConfig[SaveMethod])
{
case MethodSteam: get_user_authid(player, szMethodInfo, charsmax(szMethodInfo));
case MethodName: get_user_name(player, szMethodInfo, charsmax(szMethodInfo));
case MethodIP: get_user_ip(player, szMethodInfo, charsmax(szMethodInfo), true);
}
TrieSetArray(gpMapVector, szMethodInfo, giPlayerUsedItems[player], Items);
return PLUGIN_CONTINUE;
}
public HC_CBasePlayer_Spawn_Post(const this)
{
if (is_user_alive(this))
{
new /*bool:*/ bOldMultiJumpState = gbPlayerAttachedItems[this][ItemMultijump];
arrayset(gbPlayerAttachedItems[this], 0, Items);
rg_reset_maxspeed(this);
rg_set_rendering(this);
if (bOldMultiJumpState && !gConfig[ItemsLimit][ItemMultijump])
gbPlayerAttachedItems[this][ItemMultijump] = true;
}
}
public HC_CBasePlayer_ResetMaxSpeed(const this)
{
if (gbPlayerAttachedItems[this][ItemSpeed])
{
SetHookChainReturn(ATYPE_INTEGER, 0);
return HC_SUPERCEDE;
}
return HC_CONTINUE;
}
public HC_CBasePlayer_Jump_Post(const this)
{
if (!gbPlayerAttachedItems[this][ItemMultijump])
return;
static iJumps;
if (get_entvar(this, var_flags) & FL_ONGROUND)
{
iJumps = 0;
return;
}
if (~get_entvar(this, var_flags) & FL_ONGROUND && ~get_entvar(this, var_oldbuttons) & IN_JUMP && ++iJumps < gConfig[ItemsAmount][ItemMultijump])
{
new Float: flVelocity[3];
get_entvar(this, var_velocity, flVelocity);
flVelocity[2] = random_float(250.0, 300.0);
set_entvar(this, var_velocity, flVelocity);
return;
}
}
public ClientCommand_VM(const this)
{
new title[128];
formatex(title, charsmax(title), "\\w%L", this, get_user_flags(this) & gConfig[BitsAccess] ? "MENU_TITLE_ACCESS" : "MENU_TITLE_NOACCESS");
new iMenu = menu_create(title, "VM_Handler");
formatex(title, charsmax(title), "\\w%L", this, "MENU_ITEM_GRAVITY");
menu_additem(iMenu, title, "1", .callback = giMenuCallback);
formatex(title, charsmax(title), "\\w%L", this, "MENU_ITEM_SPEED");
menu_additem(iMenu, title, "2", .callback = giMenuCallback);
formatex(title, charsmax(title), "\\w%L", this, "MENU_ITEM_EXPLOSIVE");
menu_additem(iMenu, title, "3", .callback = giMenuCallback);
formatex(title, charsmax(title),"\\w%L", this, "MENU_ITEM_MULTIJUMP", gConfig[ItemsAmount][ItemMultijump]);
menu_additem(iMenu, title, "4", .callback = giMenuCallback);
formatex(title, charsmax(title), "\\w%L", this, "MENU_ITEM_INVISIBLITY");
menu_additem(iMenu, title, "5", .callback = giMenuCallback);
formatex(title, charsmax(title), "\\w%L", this, "MENU_ITEM_MONEY", gConfig[ItemsAmount][ItemMoney]);
menu_additem(iMenu, title, "6", .callback = giMenuCallback);
formatex(title, charsmax(title), "\\w%L", this, "MENU_ITEM_HP", gConfig[ItemsAmount][ItemHealthPoints]);
menu_additem(iMenu, title, "7", .callback = giMenuCallback);
formatex(title, charsmax(title), "\\w%L", this, "MENU_NEXTNAME");
menu_setprop(iMenu, MPROP_NEXTNAME, title);
formatex(title, charsmax(title), "\\w%L", this, "MENU_BACKNAME");
menu_setprop(iMenu, MPROP_BACKNAME, title);
formatex(title, charsmax(title), "\\w%L", this, "MENU_EXITNAME");
menu_setprop(iMenu, MPROP_EXITNAME, title);
menu_display(this, iMenu, 0);
return PLUGIN_HANDLED;
}
public VM_Handler(const this, const menu, const item)
{
if (item == MENU_EXIT)
return menu_destroy(menu);
giPlayerUsedItems[this][item]++;
switch (item)
{
case ItemGravity:
{
set_entvar(this, var_gravity, gConfig[ItemsAmount][ItemGravity]);
gbPlayerAttachedItems[this][item] = true;
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, "USE_ITEM_GRAVITY", gConfig[ItemsLimit][item] - giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
}
case ItemSpeed:
{
set_entvar(this, var_maxspeed, gConfig[ItemsAmount][ItemSpeed]);
gbPlayerAttachedItems[this][item] = true;
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, "USE_ITEM_SPEED", gConfig[ItemsLimit][item] - giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
}
case ItemExplosiveGrenade:
{
rg_has_item_by_name(this, "weapon_hegrenade"), rg_has_item_by_name(this, "weapon_flashbang"), rg_has_item_by_name(this, "weapon_smokegrenade") ? rg_set_user_bpammo(this, WEAPON_HEGRENADE, rg_get_user_bpammo(this, WEAPON_HEGRENADE) + 1) : rg_give_item(this, "weapon_hegrenade"), rg_give_item(this, "weapon_flashbang"), rg_give_item(this, "weapon_flashbang"), rg_give_item(this, "weapon_smokegrenade");
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, "USE_ITEM_EXPLOSIVE", gConfig[ItemsLimit][item] - giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
}
case ItemMultijump:
{
gbPlayerAttachedItems[this][item] = gConfig[ItemsLimit][ItemMultijump] ? true : !gbPlayerAttachedItems[this][item];
if (gConfig[ItemsLimit][ItemMultijump])
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, "USE_ITEM_MULTIJUMP", gConfig[ItemsAmount][item], gConfig[ItemsLimit][item] - giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
else
{
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, gbPlayerAttachedItems[this][item] ? "USE_ITEM_MULTIJUMP_ENABLED" : "USE_ITEM_MULTIJUMP_DISABLED");
ClientCommand_VM(this);
}
}
case ItemInvisiblity:
{
rg_set_rendering(this, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, gConfig[ItemsAmount][ItemInvisiblity]);
gbPlayerAttachedItems[this][item] = true;
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, "USE_ITEM_INVISIBLITY", gConfig[ItemsLimit][item] - giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
}
case ItemMoney:
{
rg_add_account(this, gConfig[ItemsAmount][ItemMoney], AS_SET);
gbPlayerAttachedItems[this][item] = true;
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, "USE_ITEM_MONEY", gConfig[ItemsAmount][ItemMoney], gConfig[ItemsLimit][item] - giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
}
case ItemHealthPoints:
{
set_entvar(this, var_health, float(gConfig[ItemsAmount][ItemHealthPoints]));
gbPlayerAttachedItems[this][item] = true;
client_print_color(this, print_team_default, "\4[%s]\1 %L", MESSAGE_PREFIX, this, "USE_ITEM_HP", gConfig[ItemsAmount][ItemHealthPoints], gConfig[ItemsLimit][item] - giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
}
}
return menu_destroy(menu);
}
public VM_Callback(const this, const menu, const item)
{
new szItemName[64], iDummyInt, title[128];
menu_item_getinfo(menu, item, iDummyInt, szItemName, charsmax(szItemName), szItemName, charsmax(szItemName), iDummyInt);
if (~get_user_flags(this) & gConfig[BitsAccess])
{
remove_all_colors(szItemName, charsmax(szItemName));
formatex(title, charsmax(title), "\\d%s %L", szItemName, this, "MENU_ITEM_NOACCESS");
menu_item_setname(menu, item, title);
return ITEM_DISABLED;
}
if (!gConfig[ItemsLimit][item] && item == ItemMultijump)
{
formatex(title, charsmax(title), "%s %L", szItemName, this, gbPlayerAttachedItems[this][ItemMultijump] ? "MENU_ITEM_STATE_DISABLE" : "MENU_ITEM_STATE_ENABLE");
menu_item_setname(menu, item, title);
return ITEM_IGNORE;
}
if (gConfig[ItemsLimit][item] && giPlayerUsedItems[this][item])
{
new iItemState = giPlayerUsedItems[this][item] >= gConfig[ItemsLimit][item] ? ITEM_DISABLED : ITEM_IGNORE;
iItemState && remove_all_colors(szItemName, charsmax(szItemName));
formatex(title, charsmax(title), "%s %L", szItemName, this, iItemState ? "MENU_ITEMS_LEFT_DISABLED" : "MENU_ITEMS_LEFT", giPlayerUsedItems[this][item], gConfig[ItemsLimit][item]);
menu_item_setname(menu, item, title);
return iItemState;
}
return ITEM_IGNORE;
}
public plugin_cfg()
{
new szFile[PLATFORM_MAX_PATH];
get_localinfo("amxx_configsdir", szFile, charsmax(szFile));
add(szFile, charsmax(szFile), "/vm_settings.ini");
new f = fopen(szFile, "rt");
if (!f) {
new err[256];
formatex(err, charsmax(err), "Config %s not found", szFile);
set_fail_state(err);
return;
}
new line[256], key[128], value[128], semicolonPos;
while (!feof(f)) {
fgets(f, line, charsmax(line));
if ((semicolonPos = contain(line, ";")) != -1) {
line[semicolonPos] = EOS;
}
trim(line);
if (!line[0] || line[0] == ';') {
continue;
}
strtok(line, key, charsmax(key), value, charsmax(value), '=', 0);
trim(key);
trim(value);
remove_quotes(key);
remove_quotes(value);
ParserRead_KeyValue(key, value);
}
fclose(f);
gpMapVector = TrieCreate();
}
const TOKEN_NOTFOUND = -1;
public ParserRead_KeyValue(const key[], const value[])
{
if (equal(key, "access"))
gConfig[BitsAccess] = read_flags(value);
else if (equal(key, "save_method"))
gConfig[SaveMethod] = _:str_to_num(value);
else if (equal(key, "cmd_open"))
{
new szBuffer[256], szCmd[32];
copy(szBuffer, charsmax(szBuffer), value);
do {
strtok(szBuffer, szCmd, charsmax(szCmd), szBuffer, charsmax(szBuffer), ',', 1);
register_clcmd(szCmd, "ClientCommand_VM");
} while (szBuffer[0]);
}
else if (contain(key, "maxcount") != TOKEN_NOTFOUND)
{
switch (key[0])
{
case 'g': gConfig[ItemsLimit][ItemGravity] = str_to_num(value);
case 's': gConfig[ItemsLimit][ItemSpeed] = str_to_num(value);
case 'e': gConfig[ItemsLimit][ItemExplosiveGrenade] = str_to_num(value);
case 'j': gConfig[ItemsLimit][ItemMultijump] = str_to_num(value);
case 'i': gConfig[ItemsLimit][ItemInvisiblity] = str_to_num(value);
case 'm': gConfig[ItemsLimit][ItemMoney] = str_to_num(value);
case 'h': gConfig[ItemsLimit][ItemHealthPoints] = str_to_num(value);
}
}
else if (contain(key, "amount") != TOKEN_NOTFOUND)
{
switch (key[0])
{
case 'g': gConfig[ItemsAmount][ItemGravity] = any: str_to_float(value);
case 's': gConfig[ItemsAmount][ItemSpeed] = any: str_to_float(value);
case 'j': gConfig[ItemsAmount][ItemMultijump] = str_to_num(value);
case 'i': gConfig[ItemsAmount][ItemInvisiblity] = str_to_num(value);
case 'm': gConfig[ItemsAmount][ItemMoney] = str_to_num(value);
case 'h': gConfig[ItemsAmount][ItemHealthPoints] = str_to_num(value);
}
}
return true;
}
stock remove_all_colors(buffer[], const len)
{
replace_all(buffer, len, "\\r", NULL_STRING);
replace_all(buffer, len, "\\y", NULL_STRING);
replace_all(buffer, len, "\\d", NULL_STRING);
replace_all(buffer, len, "\\w", NULL_STRING);
}
stock rg_set_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
{
new Float:renderColor[3];
renderColor[0] = float(r);
renderColor[1] = float(g);
renderColor[2] = float(b);
set_entvar(entity, var_renderfx, fx);
set_entvar(entity, var_rendercolor, renderColor);
set_entvar(entity, var_rendermode, render);
set_entvar(entity, var_renderamt, float(amount));
}