#include <amxmodx>
#include <colorchat>
#include <hamsandwich>
#include <cstrike>
#include <euro_system>
#include <nvault>
#include <fun>
new Lifes[33];
new pCvarLifeBuy, pCvarLifeSell;
new pCvarHudsON;
new Vault;
public plugin_init()
{
new const PLUGIN[] = "DeathRun Advanced Life System";
new const AUTHOR[] = "GhosT";
static const VER[] = "1.1";
register_plugin(PLUGIN, VER, AUTHOR);
register_clcmd("say /lifemenu", "ClCmdLifeMenu");
register_clcmd("say /lifes", "ClCmdLifes");
register_event("DeathMsg", "DeathMsg", "ad");
pCvarLifeBuy = register_cvar("pCvarLifeBuy", "20");
pCvarLifeSell = register_cvar("pCvarLifeSell", "10");
pCvarHudsON = register_cvar("pCvarHudsON", "1");
Vault = nvault_open("DeathRun-Lifes");
}
public ClCmdLifeMenu(id)
{
new Title[64], Item1[64], Item2[64], Item3[64];
formatex(Title, sizeof(Title), "%s Ai %d %s", Lifes[id] > 0 ? "\y" : "\d", Lifes[id], Lifes[id] != 1 ? "vieti" : "viata");
formatex(Item1, sizeof(Item1), "%s Foloseste o viata^n", Lifes[id] > 0 ? "\y" : "\d");
formatex(Item2, sizeof(Item2), "%s Cumpara o viata - %d Euro", get_user_euro(id) >= get_pcvar_num(pCvarLifeBuy) ? "\y" : "\d", get_pcvar_num(pCvarLifeBuy));
formatex(Item3, sizeof(Item3), "%s Vinde o viata - %d Euro", Lifes[id] > 0 ? "\y" : "\d" ,get_pcvar_num(pCvarLifeSell));
new menu = menu_create(Title, "LifeMenuHandler");
menu_additem(menu, Item1, "1", 0);
menu_additem(menu, Item2, "2", 0);
menu_additem(menu, Item3, "3", 0);
menu_setprop(menu, MPROP_EXITNAME, "\yIesire");
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public LifeMenuHandler(id, menu, item)
{
if(item == MENU_EXIT)
{
return 1;
}
new euro = get_user_euro(id);
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback);
new key = str_to_num(data);
switch(key)
{
case 1:
{
if(is_user_alive(id))
{
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x01 Trebuie sa fii mort pentru a folosi o viata !");
ClCmdLifeMenu(id);
return PLUGIN_HANDLED;
}
else
{
if(Lifes[id] <= 0)
{
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x01 Trebuie sa ai^x03 minim o viata^x01 pentru a reinvia !");
ClCmdLifeMenu(id);
return PLUGIN_HANDLED;
}
else
{
Lifes[id] -= 1;
spawn(id);
ClCmdLifeMenu(id);
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x01 Ai folosit o viata, acum ai^x03 %d %s", Lifes[id], Lifes[id] == 1 ? "viata" : "vieti");
}
}
}
case 2:
{
if(euro < get_pcvar_num(pCvarLifeBuy))
{
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x01 Ai nevoie de^x03 %d euro^x01 pentru a cumpara o viata !", get_pcvar_num(pCvarLifeBuy));
ClCmdLifeMenu(id);
return PLUGIN_HANDLED;
}
else if(euro >= get_pcvar_num(pCvarLifeBuy))
{
Lifes[id] += 1;
set_user_euro(id, euro - get_pcvar_num(pCvarLifeBuy));
ClCmdLifeMenu(id);
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x03 Ai cumparat o viata^x01 si ai dat^x03 %d euro^x01 ! Acum ai^x03 %d %s", get_pcvar_num(pCvarLifeBuy), Lifes[id], Lifes[id] == 1 ? "viata" : "vieti");
}
}
case 3:
{
if(Lifes[id] <= 0)
{
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x01 Trebuie sa ai^x03 minim o viata^x01 pentru a vinde !");
ClCmdLifeMenu(id);
return PLUGIN_HANDLED;
}
else
{
Lifes[id] -= 1;
set_user_euro(id, euro + get_pcvar_num(pCvarLifeSell));
ClCmdLifeMenu(id);
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x03 Ai vandut o viata^x01 si ai primit^x03 %d euro^x01 ! Acum ai^x03 %d %s", get_pcvar_num(pCvarLifeSell), Lifes[id], Lifes[id] == 1 ? "viata" : "vieti");
}
}
}
menu_destroy(menu);
return 1;
}
public ClCmdLifes(id)
{
new NamePlayer[32];
get_user_name(id, NamePlayer, sizeof(NamePlayer) - 1);
ColorChat(id, RED, "^x04 [DeathRun - Lifes]^x01 Salut^x03 %s^x01.. In acest moment tu ai^x03 %d %s^x01 !", NamePlayer, Lifes[id], Lifes[id] == 1 ? "viata" : "vieti")
return PLUGIN_HANDLED;
}
public DeathMsg()
{
new iHeadShot = read_data(3);
new iVictim = read_data(2);
new iAttacker = read_data(1);
new NamePlayer[32];
get_user_name(iVictim, NamePlayer, sizeof(NamePlayer) - 1);
set_hudmessage(0, 255, 255, -1.0, -1.0);
if(iVictim == iAttacker)
return PLUGIN_HANDLED;
if(iHeadShot && iVictim != iAttacker)
{
Lifes[iAttacker] += 2;
if(get_pcvar_num(pCvarHudsON) >= 1)
show_hudmessage(iAttacker, "[Head Shot] Ai primit doua vieti pentru ca l-ai omorat pe %s !", NamePlayer);
}
if(!iHeadShot && iVictim != iAttacker)
{
Lifes[iAttacker] += 1;
if(get_pcvar_num(pCvarHudsON) >= 1)
show_hudmessage(iAttacker, "[Kill] Ai primit o viata pentru ca l-ai omorat pe %s !", NamePlayer);
}
ClCmdLifeMenu(iVictim);
return PLUGIN_CONTINUE;
}
public client_putinserver(id)
LoadLifes(id);
public client_disconnect(id)
SaveLifes(id);
public SaveLifes(id)
{
new NamePlayer[32];
get_user_name(id, NamePlayer, sizeof(NamePlayer) - 1);
new VaultKey[64],VaultData[256];
format(VaultKey, 63, "%s-DeathRun-Lifes", NamePlayer);
format(VaultData, 255, "%i#", Lifes[id]);
nvault_set(Vault, VaultKey, VaultData);
}
public LoadLifes(id)
{
new NamePlayer[32];
get_user_name(id, NamePlayer, sizeof(NamePlayer) - 1);
new VaultKey[64], VaultData[256];
format(VaultKey, sizeof(VaultKey) - 1, "%s-DeathRun-Lifes", NamePlayer);
format(VaultData, charsmax(VaultData), "%i#", Lifes[id]);
nvault_get(Vault, VaultKey, VaultData, charsmax(VaultData));
replace_all(VaultData, 255, "#", " ");
new PlayerLifes[32];
parse(VaultData, PlayerLifes, sizeof(PlayerLifes) - 1);
Lifes[id] = str_to_num(PlayerLifes);
}