Code: Select all
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
new const PLUGIN[] = "Points";
new const VERSION[] = "1.3";
new const AUTHOR[] = "Alex #";
new Points[33];
new SaveDataFile[128];
const Float:HUD_SPECT_X = 0.1;
const Float:HUD_SPECT_Y = 0.2;
enum ShopItems
{
ITEM_MACHETE,
ITEM_BAK_KNIFE,
ITEM_POCKET_KNIFE,
ITEM_BUTCHER_KNIFE,
ITEM_DEFAULT_KNIFE,
ITEM_EXIT
};
new const SHOP_ITEM_PRICE[5] =
{
5,
10,
8,
15,
12
};
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_event("DeathMsg", "eDeath", "a");
new DataDir[64];
get_configsdir(DataDir, charsmax(DataDir));
format(SaveDataFile, 127, "%s/Points.dat", DataDir);
set_task(0.1, "TASK_MSG", _, _, _, "b");
register_clcmd("say /shop", "menuShopDisplay");
register_menucmd(register_menuid("\r[<><><><>] - \w[DR SHOP]\n\n"), 1023, "menuShopAction");
}
public plugin_natives()
{
register_native("csdm_get_user_points", "get_user_points", 1);
register_native("csdm_set_user_points", "set_user_points", 1);
}
public get_user_points(id)
{
return Points[id];
}
public set_user_points(id, PointsNum)
{
Points[id] = PointsNum;
}
public eDeath(id)
{
new Killer = read_data(1);
new Victim = read_data(2);
new HeadShoot = read_data(3);
if (Killer == Victim)
return PLUGIN_HANDLED;
Points[Killer] += 2;
if (HeadShoot)
{
Points[Killer] += 2;
}
return PLUGIN_CONTINUE;
}
public client_connect(id)
{
LoadPoints(id);
}
public LoadPoints(id)
{
new Name[32];
get_user_name(id, Name, 31);
new Line[128], IsPlayer = false, Arg1[32], Arg2[32];
new File = fopen(SaveDataFile, "rt");
while (!feof(File))
{
fgets(File, Line, 127);
trim(Line);
parse(Line, Arg1, 31, Arg2, 31);
if (equali(Arg1, Name))
{
Points[id] = str_to_num(Arg2);
IsPlayer = true;
break;
}
}
fclose(File);
if (!IsPlayer)
Points[id] = 0;
}
public SavePoints(id)
{
new Name[32];
get_user_name(id, Name, 31);
new Save[1024];
format(Save, sizeof(Save) - 1, "^"%s^" %d", Name, Points[id]);
new Line[128], Linie, IsPlayer = false, Arg1[32]
new File = fopen(SaveDataFile, "rt");
while (!feof(File))
{
fgets(File, Line, 127);
parse(Line, Arg1, 31);
if (equali(Arg1, Name))
{
write_file(SaveDataFile, Save, Linie);
IsPlayer = true;
break;
}
Linie++
}
fclose(File);
if (!IsPlayer)
write_file(SaveDataFile, Save, -1);
}
public TASK_MSG()
{
static id;
for (id = 1; id <= get_maxplayers(); id++)
{
if (is_user_alive(id) && is_user_connected(id))
{
switch (cs_get_user_team(id))
{
case CS_TEAM_T:
{
set_hudmessage(id, 127, 255, HUD_SPECT_X, HUD_SPECT_Y, 1, 6.0, 1.1, 0.0, 0.0, -1);
show_hudmessage(id, "[DR CREDITS]: %d", Points[id]);
}
case CS_TEAM_CT:
{
set_hudmessage(id, 127, 255, HUD_SPECT_X, HUD_SPECT_Y, 1, 6.0, 1.1, 0.0, 0.0, -1);
show_hudmessage(id, "[DR CREDITS]: %d", Points[id]);
}
case CS_TEAM_SPECTATOR:
{
return PLUGIN_CONTINUE;
}
}
}
}
return PLUGIN_CONTINUE;
}
public menuShopDisplay(id)
{
new menu[256];
new len = formatex(menu, sizeof(menu) - 1, "\r[FPS] - \w[DR SHOP]^n^n");
len += formatex(menu[len], sizeof(menu) - len - 1, "\r1. \wMachete: \y%.1d credits^n", SHOP_ITEM_PRICE);
len += formatex(menu[len], sizeof(menu) - len - 1, "\r2. \wBak Knife: \y%.1d credits^n", SHOP_ITEM_PRICE);
len += formatex(menu[len], sizeof(menu) - len - 1, "\r3. \wPocket Knife: \y%.1d credits^n", SHOP_ITEM_PRICE);
len += formatex(menu[len], sizeof(menu) - len - 1, "\r4. \wButcher Knife: \y%.1d credits^n", SHOP_ITEM_PRICE);
len += formatex(menu[len], sizeof(menu) - len - 1, "\r5. \wDefault Knife: \y%.1d credits^n", SHOP_ITEM_PRICE);
len += formatex(menu[len], sizeof(menu) - len - 1, "^n\r0. \wIesire");
show_menu(id, (1 << 0 | 1 << 1 | 1 << 9), menu, -1);
return PLUGIN_HANDLED;
}
public menuShopAction(id, option)
{
switch (option)
{
case ITEM_MACHETE:
if (Points[id] >= SHOP_ITEM_PRICE[id])
{
Points[id] -= SHOP_ITEM_PRICE[id];
client_print(id, print_chat, "Ai cumparat Machete!");
}
else
{
client_print(id, print_chat, "Nu ai suficiente puncte pentru a cumpara Machete!");
}
case ITEM_BAK_KNIFE:
if (Points[id] >= SHOP_ITEM_PRICE[id])
{
Points[id] -= SHOP_ITEM_PRICE[id];
client_print(id, print_chat, "Ai cumparat Bak Knife!");
}
else
{
client_print(id, print_chat, "Nu ai suficiente puncte pentru a cumpara Bak Knife!");
}
case ITEM_POCKET_KNIFE:
if (Points[id] >= SHOP_ITEM_PRICE[id])
{
Points[id] -= SHOP_ITEM_PRICE[id];
client_print(id, print_chat, "Ai cumparat Pocket Knife!");
}
else
{
client_print(id, print_chat, "Nu ai suficiente puncte pentru a cumpara Pocket Knife!");
}
case ITEM_BUTCHER_KNIFE:
if (Points[id] >= SHOP_ITEM_PRICE[id])
{
Points[id] -= SHOP_ITEM_PRICE[id];
client_print(id, print_chat, "Ai cumparat Butcher Knife!");
}
else
{
client_print(id, print_chat, "Nu ai suficiente puncte pentru a cumpara Butcher Knife!");
}
case ITEM_DEFAULT_KNIFE:
if (Points[id] >= SHOP_ITEM_PRICE[id])
{
Points[id] -= SHOP_ITEM_PRICE[id];
client_print(id, print_chat, "Ai cumparat Default Knife!");
}
else
{
client_print(id, print_chat, "Nu ai suficiente puncte pentru a cumpara Default Knife!");
}
case ITEM_EXIT:
client_print(id, print_chat, "Ai iesit din shop");
}
return PLUGIN_HANDLED;
}