/*
_______________________________________________________
|
.:> TheArmagedon's Plugin - Life System |
_______________________________________________________|
|
.:> Cvar: |
.:> amx_life [1/0] - On/Off Life System. |
.:> amx_life_cost [Amount] - Life Price. |
.:> amx_life_start [Amount] - How many lifes at start. |
.:> V1.1 |
.:> amx_life_max [Amount] - Max life to player |
.:> V1.2 |
.:> amx_life_auto_respawn [1/0] - On/off Auto. Respawn |
_______________________________________________________|
*/
// Includes.
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
// Color Chat
#define MAXSLOTS 32
enum Color
{
YELLOW = 1, // Yellow
GREEN, // Green Color
TEAM_COLOR, // Red, grey, blue
GREY, // grey
RED, // Red
BLUE, // Blue
}
new TeamInfo;
new SayText;
new MaxSlots;
new TeamName[][] =
{
"",
"TERRORIST",
"CT",
"SPECTATOR"
}
new bool:IsConnected[MAXSLOTS + 1];
// Plugin Version
#define VERSION "1.2"
// Principal Command.
new g_Life[33];
new bool:autoSpawn[33];
// Pcvar's
new lifepreco;
new lifeonoff;
new lifestart;
new lifemax;
new lifespawn;
// Lets start the tutorial
public plugin_init() {
// Register
register_plugin("Life System", VERSION, "TheArmagedon");
register_cvar("life_system", VERSION, FCVAR_SPONLY|FCVAR_SERVER)
set_cvar_string("life_system", VERSION)
// Say command
register_clcmd("say /respawn", "ComCMD"); // Uses the life.
register_clcmd("say /ujra", "ComCMD"); // Uses the life.
register_clcmd("say /uselife", "ComCMD"); // Uses the life.
register_clcmd("say /buylife", "BuyCMD"); // Buy a life.
register_clcmd("say /elet", "BuyCMD"); // Buy a life.
// Cvar's
lifeonoff = register_cvar("amx_life", "1");
lifepreco = register_cvar("amx_life_cost", "15000");
lifestart = register_cvar("amx_life_start", "0"); // How many lifes at start?
lifemax = register_cvar("amx_life_max", "8"); // Max life for a player
lifespawn = register_cvar("amx_life_auto_respawn", "0"); // If 1 Respawn Automatically | If 0 use the /respawn command
// ColorChat
TeamInfo = get_user_msgid("TeamInfo");
SayText = get_user_msgid("SayText");
MaxSlots = get_maxplayers();
// Death
register_event( "DeathMsg", "EventDeath", "a");
// Player Spawn
RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1);
}
// Start with how many lives?
public client_putinserver(id)
{
g_Life[id] = get_pcvar_num(lifestart);
}
// Show Hud.
public fw_PlayerSpawn_Post(id)
{
hudreset(id);
}
// DeathEvent.
public EventDeath()
{
new iVictim = read_data( 2 );
FreeLife(iVictim); // Show the Command "FreeLife"
AutoResp(iVictim); // Command Auto Respawn
}
// Command "say /buylife"
public BuyCMD(id)
{
// If Cvar = 1.
if(get_pcvar_num(lifeonoff) == 1) {
new money = cs_get_user_money(id);
new custo = get_pcvar_num(lifepreco); // Life Price.
if(money > custo || money == custo) {
if(g_Life[id] < get_pcvar_num(lifemax)) {
cs_set_user_money(id, money - custo);
g_Life[id]++
ColorChat(id, TEAM_COLOR, "Eletet vettel");
hudreset(id);
if(!is_user_alive(id) && autoSpawn[id] == true) {
set_task(2.0, "RespawnCommand", id);
g_Life[id]--
}
} else
ColorChat(id, TEAM_COLOR, "Nem vehetsz tobb eletet, max: %d", get_pcvar_num(lifemax))
} else
ColorChat(id, TEAM_COLOR, "Nincs eleg penzed.");
} else
ColorChat(id, TEAM_COLOR, "Parancs kikapcsolva.");
}
// Auto respawn command
public AutoResp(id)
{
// If user is dead.
if(!is_user_alive(id)) {
// If cvar is 1
if(get_pcvar_num(lifeonoff) == 1) {
// If auto. spawn cvar 1
if(get_pcvar_num(lifespawn) == 1) {
autoSpawn[id] = true;
if(autoSpawn[id] == true) {
// If dont have any life, dont respawn
if(!g_Life[id]) {
hudreset(id);
return PLUGIN_HANDLED
}
set_task(2.0, "RespawnCommand", id);
g_Life[id]--
hudreset(id);
}
} else
autoSpawn[id] = false;
}
}
return PLUGIN_CONTINUE;
}
// If you death you have chance to get a free life.
public FreeLife(id)
{
// If Cvar = 1.
if(get_pcvar_num(lifeonoff)) {
if( random_num( 1, 5 /*5 = chance 1 in 5 to get a free Life.*/) == 5 ) {
if(g_Life[id] < get_pcvar_num(lifemax)) {
g_Life[id]++
ColorChat(id, TEAM_COLOR, "Eletet kaptal.");
hudreset(id);
if(!is_user_alive(id) && autoSpawn[id] == true) {
set_task(2.0, "RespawnCommand", id);
}
}
} else {
client_print(id, print_console, "Nem kaphatsz eletet.");
hudreset(id);
}
}
}
// Command "say /respawn"
public ComCMD(id)
{
// If Cvar = 1.
if(get_pcvar_num(lifeonoff) == 1) {
// If dont have any life, dont respawn
if(!g_Life[id]) {
hudreset(id);
return PLUGIN_HANDLED
}
// If player dead and have life, Respawn.
if(!is_user_alive(id)) {
if(autoSpawn[id] == false) {
g_Life[id]--
RespawnCommand(id); // Respawn Command.
hudreset(id);
} else
ColorChat(id, TEAM_COLOR, "Parancs kikapcsolva. Automata ujraelesztes bekapcsolva.");
} else
ColorChat(id, TEAM_COLOR, "Nem hasznalhatod ezt a parancsot ha elsz.");
} else
ColorChat(id, TEAM_COLOR, "Parancs kikapcsolva.")
return PLUGIN_CONTINUE;
}
// Show Hud, How many lives you got.
public hudshow(id)
{
if(get_pcvar_num(lifeonoff) == 1) {
set_hudmessage(255, 0, 0, 0.01, 0.2, 0, 6.0, 30.0)
show_hudmessage(id, "--[ Elet Rendszer ]--^nNeked van %d/%d %s^n^nElet vasarlas: /elet^nElet ara: %d$", g_Life[id], get_pcvar_num(lifemax),g_Life[id] == 1 ? "Eleted" : "Eleted", get_pcvar_num(lifepreco))
}
}
// Reset HUD MSG.
public hudreset(id)
{
hudshow(id)
}
public RespawnCommand(id)
{
if(!is_user_alive(id)) {
ExecuteHamB(Ham_CS_RoundRespawn, id);
ColorChat(id, TEAM_COLOR, "Ujra lettel elesztve!");
}
}
// Color Chat
public ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
{
static message[256];
switch(type)
{
case YELLOW: // Yellow
{
message[0] = 0x01;
}
case GREEN: // Green
{
message[0] = 0x04;
}
default: // White, Red, Blue
{
message[0] = 0x03;
}
}
vformat(message[1], 251, msg, 4);
// Make sure message is not longer than 192 character. Will crash the server.
message[192] = '^0';
new team, ColorChange, index, MSG_Type;
if(!id)
{
index = FindPlayer();
MSG_Type = MSG_ALL;
} else {
MSG_Type = MSG_ONE;
index = id;
}
team = get_user_team(index);
ColorChange = ColorSelection(index, MSG_Type, type);
ShowColorMessage(index, MSG_Type, message);
if(ColorChange)
{
Team_Info(index, MSG_Type, TeamName[team]);
}
}
ShowColorMessage(id, type, message[])
{
message_begin(type, SayText, _, id);
write_byte(id)
write_string(message);
message_end();
}
Team_Info(id, type, team[])
{
message_begin(type, TeamInfo, _, id);
write_byte(id);
write_string(team);
message_end();
return 1;
}
ColorSelection(index, type, Color:Type)
{
switch(Type)
{
case RED:
{
return Team_Info(index, type, TeamName[1]);
}
case BLUE:
{
return Team_Info(index, type, TeamName[2]);
}
case GREY:
{
return Team_Info(index, type, TeamName[0]);
}
}
return 0;
}
FindPlayer()
{
new i = -1;
while(i <= MaxSlots)
{
if(IsConnected[++i])
{
return i;
}
}
return -1;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1034\\ f0\\ fs16 \n\\ par }
*/