Skip to content

Instantly share code, notes, and snippets.

@metasta
Created March 31, 2010 05:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metasta/349971 to your computer and use it in GitHub Desktop.
Save metasta/349971 to your computer and use it in GitHub Desktop.
AMXX scripting
/*
* amx_practice_plus
* - infinite money
* - infinite ammo
* - infinite health
* - damage display
* - checkpoint ( I referred kz plugin )
*
* todo
* - buyzone edit ( I'll refer the nice plugin "buyzone_range" )
*/
#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <fun>
new g_on;
new g_buy;
new g_ammo;
new g_health;
new g_showdamage;
new g_checkpoint;
#define MAX_CP 25
// Check Point
new cpCount[33];
new cp_count[33] = {-1, ...};
new Float:cp_location[33][MAX_CP][3];
// Teleport Count
new gc_count[33];
public plugin_init()
{
register_plugin("amx_practice", "0.1", "meta");
register_event("Money", "event_Money", "b");
register_event("CurWeapon", "event_CurWeapon", "be", "1=1");
register_event("Damage", "event_Damage", "b", "2>0");
register_event("ResetHUD", "event_ResetHUD", "be");
g_on = register_cvar("amx_practice", "1");
g_buy = register_cvar("amx_practice_buy", "1");
g_ammo = register_cvar("amx_practice_ammo", "1");
g_health = register_cvar("amx_practice_health", "1");
g_showdamage = register_cvar("amx_practice_showdamage", "1");
g_checkpoint = register_cvar("amx_practice_checkpoint", "1");
register_clcmd("say /cp", "cmdCP");
register_clcmd("say /check", "cmdCP");
register_clcmd("say /checkpoint", "cmdCP");
register_clcmd("say_team /cp", "cmdCP");
register_clcmd("say_team /check", "cmdCP");
register_clcmd("say_team /checkpoint", "cmdCP");
register_clcmd("say /tp", "cmdTele");
register_clcmd("say /gc", "cmdTele");
register_clcmd("say /tele", "cmdTele");
register_clcmd("say /gocheck", "cmdTele");
register_clcmd("say_team /tp", "cmdTele")
register_clcmd("say_team /gc", "cmdTele");
register_clcmd("say_team /tele", "cmdTele");
register_clcmd("say_team /gocheck", "cmdTele");
register_clcmd("say /stuck", "cmdStuck");
register_clcmd("say /unstuck", "cmdStuck");
register_clcmd("say_team /stuck", "cmdStuck");
register_clcmd("say_team /unstuck", "cmdStuck");
}
public event_Money(id)
{
if(get_pcvar_num(g_on) && get_pcvar_num(g_buy) && is_user_alive(id)){
cs_set_user_money(id, 16000, 0);
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public event_CurWeapon(id)
{
if(get_pcvar_num(g_on) && get_pcvar_num(g_ammo) && is_user_alive(id)){
new clip, ammo;
new w = get_user_weapon(id, clip, ammo);
if(w == CSW_C4 || w == CSW_KNIFE){
return PLUGIN_CONTINUE;
}
else if(w == CSW_HEGRENADE || w == CSW_FLASHBANG || w == CSW_SMOKEGRENADE){
cs_set_user_bpammo(id, w, 1000);
}
else if(clip == 0){
new weapon[32];
get_weaponname(w, weapon, 31);
give_item(id, weapon);
engclient_cmd(id, weapon);
}
}
return PLUGIN_CONTINUE;
}
public event_Damage(id)
{
if(get_pcvar_num(g_on) && is_user_alive(id)){
if(get_pcvar_num(g_showdamage)){
new attacker = get_user_attacker(id);
new damage = read_data(2);
if(attacker != id && is_user_alive(attacker)){
set_hudmessage(0, 100, 200, -1.0, 0.55, 2, 0.1, 4.0, 0.02, 0.02, 7);
show_hudmessage(attacker, "%d", damage);
}
else {
set_hudmessage(200, 100, 0, -1.0, 0.55, 2, 0.1, 4.0, 0.02, 0.02, 7);
show_hudmessage(id, "%d", damage);
}
}
if(get_pcvar_num(g_health)){
set_user_health(id, 1023);
}
}
return PLUGIN_CONTINUE;
}
public event_ResetHUD(id)
{
if(get_pcvar_num(g_on) && get_pcvar_num(g_health) && is_user_alive(id)){
set_user_health(id, 1023);
}
return PLUGIN_CONTINUE;
}
_fm_set_entity_flags(index, flag, onoff) // Taken from fakemeta_util
{
new flags = pev(index, pev_flags);
if ((flags & flag) > 0)
return onoff == 1 ? 2 : 1 + 0 * set_pev(index, pev_flags, flags - flag);
else
return onoff == 0 ? 2 : 1 + 0 * set_pev(index, pev_flags, flags + flag);
return 0;
}
delay_duck(id)
{
set_task(0.01, "force_duck", id);
_fm_set_entity_flags(id, FL_DUCKING, 1);
}
public force_duck(id)
{
_fm_set_entity_flags(id, FL_DUCKING, 1);
}
public cmdCP(id)
{
if(get_pcvar_num(g_on) && get_pcvar_num(g_checkpoint) && is_user_alive(id)){
static vel[3];
pev(id, pev_velocity, vel);
if(vel[2] >= 0 && pev(id, pev_flags) & FL_ONGROUND){
cp_count[id]++;
cpCount[id]++;
if(cp_count[id] == MAX_CP) cp_count[id] = 0;
pev(id, pev_origin, cp_location[id][cp_count[id]]);
client_print(id, print_center, "Checkpoint #%i.", cpCount[id]);
} else {
client_print(id, print_center, "You can't make checkpoints while falling.");
}
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public cmdTele(id)
{
if(get_pcvar_num(g_on) && get_pcvar_num(g_checkpoint) && is_user_alive(id)){
if(cp_count[id] != -1){
static Float:origin[3], players[32], nums, person, i, Float:cp_origin[3];
get_players(players, nums, "ac");
cp_origin = cp_location[id][cp_count[id]];
for(i = 0; i < nums; i++){
person = players[i];
if(id == person) continue;
pev(person, pev_origin, origin);
if(vector_distance(origin, cp_origin) <= 74.0) break;
}
set_pev(id, pev_velocity, {0, 0, 0});
set_pev(id, pev_origin, cp_origin);
client_print(id, print_center, "Teleported.");
delay_duck(id);
gc_count[id]++;
}
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public cmdStuck(id)
{
if(get_pcvar_num(g_on) && get_pcvar_num(g_checkpoint) && is_user_alive(id)){
if(cp_count[id] == -1) return PLUGIN_HANDLED;
if(cp_count[id] > 0){
cp_count[id]--;
}
set_pev(id, pev_velocity, {0, 0, 0});
client_print(id, print_center, "Previous checkpoint.");
set_pev(id, pev_origin, cp_location[id][cp_count[id]]);
delay_duck(id);
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public client_connect(id)
{
if(get_pcvar_num(g_on) && get_pcvar_num(g_checkpoint)){
cp_count[id] = -1;
gc_count[id] = 0;
cpCount[id] = 0;
}
return PLUGIN_CONTINUE;
}
#include <amxmodx>
#include <cstrike>
#include <csx>
new bool:is_bomb_planted = false
new g_bot_autokill
new g_bot_autokill_delay
public plugin_init()
{
register_plugin("Bot Autokill", "0.2", "meta")
register_logevent("new_round_start", 2, "1=Round_Start")
g_bot_autokill = register_cvar("bot_autokill", "1")
g_bot_autokill_delay = register_cvar("bot_autokill_delay", "0.0")
register_srvcmd("bot_kill_ct", "bot_kill_ct")
register_srvcmd("bot_kill_t", "bot_kill_t")
}
public client_death(killer, victim, wpnindex, hitplace, TK)
{
/* is he the last human? */
if(!get_pcvar_num(g_bot_autokill)) return PLUGIN_CONTINUE
if(is_bomb_planted) return PLUGIN_CONTINUE
if(is_user_bot(victim)) return PLUGIN_CONTINUE
for(new i = 1; i <= 32; i++){
if(!is_user_bot(i) && is_user_alive(i)){
return PLUGIN_CONTINUE
}
}
set_bot_autokill(cs_get_user_team(victim))
return PLUGIN_CONTINUE
}
public set_bot_autokill(CsTeams:team)
{
new Float:delay = get_pcvar_float(g_bot_autokill_delay)
if(delay >= 0.1){
if(team == CS_TEAM_CT) set_task(delay, "bot_kill_ct", 0)
else if(team == CS_TEAM_T) set_task(delay, "bot_kill_t", 0)
}
else {
if(team == CS_TEAM_CT) bot_kill_ct()
else if(team == CS_TEAM_T) bot_kill_t()
}
return PLUGIN_CONTINUE
}
public bot_kill_ct()
{
for(new i = 1; i <= 32; i++){
if(is_user_bot(i)){
if(cs_get_user_team(i) == CS_TEAM_CT) user_kill(i, 1)
}
}
return PLUGIN_CONTINUE
}
public bot_kill_t()
{
for(new i = 1; i <= 32; i++){
if(is_user_bot(i)){
if(cs_get_user_team(i) == CS_TEAM_T) user_kill(i, 1)
}
}
return PLUGIN_CONTINUE
}
public bomb_planted(planter)
{
if(task_exists(0)) remove_task(0)
is_bomb_planted = true
return PLUGIN_CONTINUE
}
public new_round_start()
{
is_bomb_planted = false
return PLUGIN_CONTINUE
}
#include <amxmodx>
#include <cstrike>
new const version[] = "0.1"
new money[33]
new msgid
public plugin_init ()
{
register_plugin ("Ceilingless Money", version, "meta")
register_event ("Money", "event_money", "b")
register_event ("TextMsg", "event_restart", "a", "2&#Game_C", "2&#Game_w")
msgid = get_user_msgid ("Money")
return PLUGIN_CONTINUE
}
public client_connect (i)
{
money[i] = 0
}
public event_money (i)
{
if (! is_user_connected (i)) return PLUGIN_HANDLED
new amount = read_data (1)
new flag = read_data (2)
new prev = money[i]
new curr = (prev < 8000) ? amount : money[i] + amount - 8000
cs_set_user_money (i, (curr < 8000) ? curr : 8000, 0)
show_user_money (i, prev, curr, flag)
money[i] = curr
return PLUGIN_CONTINUE
}
public event_restart ()
{
new amount = get_cvar_num("mp_startmoney")
for (new i = 0; i < 33; i++) {
money[i] = 0
if (is_user_connected (i)) cs_set_user_money (i, amount, 0)
}
}
public show_user_money (i, prev, curr, flag)
{
message_begin (MSG_ONE, msgid, {0,0,0}, i)
write_long ((prev == curr) ? 0 : prev)
write_byte (0)
message_end ()
message_begin (MSG_ONE, msgid, {0,0,0}, i)
write_long (curr)
write_byte (flag)
message_end ()
}
/* *
* HLTV Control
*
* Remote control HLTV from your game server
* (this is a tiny rcon-client)
*
* Cvar:
* hltv_address <address>
* hltv_port <port>
* hltv_password <password>
* Command:
* hltv <HLTV command>
*
* Thanks to:
* hackziner (author of "Ingame remote rcon control")
* IsoTeemu (author of "HLTV inviter")
*/
#include <amxmodx>
#include <sockets>
public plugin_init()
{
register_plugin("HLTV Control", "0.0", "meta")
register_cvar("hltv_address", "127.0.0.1")
register_cvar("hltv_port", "27020")
register_cvar("hltv_password", "", FCVAR_PROTECTED)
register_srvcmd("hltv", "command_hltv")
}
public command_hltv()
{
if(read_argc() < 2){
server_print("Syntax: hltv <command>")
return PLUGIN_HANDLED
}
new address[32]; get_cvar_string("hltv_address", address, 31)
new port = get_cvar_num("hltv_port")
new password[32]; get_cvar_string("hltv_password", password, 31)
new command[128]; read_args(command, 127); remove_quotes(command)
new sock, r
new send[256], cmd[256], rconid[32], nothing[64]
sock = socket_open(address, port, SOCKET_UDP, r)
if(r != 0){
server_print("socket error(%d).", r)
socket_close(sock)
return PLUGIN_HANDLED
}
formatex(send, 256, "%c%c%c%cchallenge rcon",255,255,255,255)
socket_send2(sock, send, 255)
if(!socket_change(sock, 1000000)){
server_print("No response from %s.", address)
socket_close(sock)
return PLUGIN_HANDLED
}
socket_recv(sock, cmd, 255)
parse(cmd, nothing, 63, nothing, 63, rconid, 31)
formatex(cmd, 256, "%c%c%c%crcon %s ^"%s^" %s",255,255,255,255, rconid, password, command)
socket_send2(sock, cmd, 255)
if(socket_change(sock)){
new buf[2048]
socket_recv(sock, buf, 2047)
server_print("%s", buf[5])
}
socket_close(sock)
return PLUGIN_HANDLED
}
[en]
KICK_REASON = このサーバは K/D < %.1f の方のみ入場できます。
/*
* K:D Limit by PsychoStats DB
*
* When a player connects, this plugin will see the psychostats db (mysql),
* get the player's stats data, and kick him if his K:D is higher than kd_max.
*
* If player's kills are fewer than kd_minkills, nothing happens.
*
* To disable this plugin, set kd_max 0 (or less).
*/
#include <amxmodx>
#include <sqlx>
new g_kd_max, g_kd_minkills
new g_kd_host, g_kd_user, g_kd_pass, g_kd_db
public plugin_init()
{
register_plugin("K:D Limit by PsychoStats DB", "0.3", "meta")
g_kd_max = register_cvar("kd_max", "1.0")
g_kd_minkills = register_cvar("kd_minkills", "100")
g_kd_host = register_cvar("kd_host", "127.0.0.1", FCVAR_PROTECTED)
g_kd_user = register_cvar("kd_user", "guest", FCVAR_PROTECTED)
g_kd_pass = register_cvar("kd_pass", "asdf", FCVAR_PROTECTED)
g_kd_db = register_cvar("kd_db" , "psychostats3_1", FCVAR_PROTECTED)
register_dictionary("kd_limit.txt")
}
public client_authorized(id)
{
if(is_user_hltv(id) || is_user_bot(id)) return PLUGIN_CONTINUE
new Float:kd_max = get_pcvar_float(g_kd_max)
if(kd_max <= 0) return PLUGIN_CONTINUE
new host[64]; get_pcvar_string(g_kd_host, host, 63)
new user[64]; get_pcvar_string(g_kd_user, user, 63)
new pass[64]; get_pcvar_string(g_kd_pass, pass, 63)
new db[64]; get_pcvar_string(g_kd_db, db, 63)
new Handle:tuple = SQL_MakeDbTuple(host, user, pass, db)
new errcode, err[256]
new Handle:sql = SQL_Connect(tuple, errcode, err, 255)
if(!sql) {
SQL_FreeHandle(sql)
SQL_FreeHandle(tuple)
return PLUGIN_CONTINUE
}
new authid[36]; get_user_authid(id, authid, 35)
new Handle:query = SQL_PrepareQuery(sql, "SELECT plrid FROM ps_plr_ids_worldid WHERE worldid='%s'", authid)
if(!(SQL_Execute(query) && SQL_MoreResults(query))) return free_handles(query, sql, tuple)
new plrid = SQL_ReadResult(query, 0)
query = SQL_PrepareQuery(sql, "SELECT kills,killsperdeath FROM ps_c_plr_data WHERE plrid='%d'", plrid)
if(!(SQL_Execute(query) && SQL_MoreResults(query))) return free_handles(query, sql, tuple)
new min = get_pcvar_num(g_kd_minkills)
new kills = SQL_ReadResult(query, 0)
new Float:kd; SQL_ReadResult(query, 1, kd)
console_print(0, "[K:D] %s^tK: %d^tK/D: %.2f", authid, kills, kd)
if(kd > kd_max && kills > min) server_cmd("kick #%d ^" %L^"", get_user_userid(id), id, "KICK_REASON", kd_max)
return free_handles(query, sql, tuple)
}
free_handles(Handle:query, Handle:sql, Handle:tuple)
{
SQL_FreeHandle(query)
SQL_FreeHandle(sql)
SQL_FreeHandle(tuple)
return PLUGIN_CONTINUE
}
/*
* Server Load Balancer
*
* Redirect players if the server already has many players.
*
* Cvar:
* sv_maxplayers <n>
* When the (sv_maxplayers + 1)th client tries to connect to server,
* he/she will be redirected.
* The default value of <n> is "10".
*
* sv_redirectaddress <host:port>
* The redirect destination. ex.) "example.com:27018"
* The default value of <host:port> is "".
*
* Thanks to:
* Vet (author of "Redirect to your new server IP")
* http://forums.alliedmods.net/showthread.php?t=61833
*/
#include <amxmodx>
new const version[] = "0.1"
new sv_maxplayers
new sv_redirectaddress
public plugin_init ()
{
register_plugin ("Server Load Balancer", version, "meta")
sv_maxplayers = register_cvar ("sv_maxplayers", "10")
sv_redirectaddress = register_cvar ("sv_redirectaddress", "")
register_event("InitHUD", "event_inithud", "bd")
}
public event_inithud (i)
{
if (is_user_bot(i) || is_user_hltv(i)) return PLUGIN_CONTINUE
new max = get_pcvar_num (sv_maxplayers), n
new players[32]
get_players(players, n, "ch")
server_print ("[LoadBalancer] player capacity: %d/%d", n, max)
if (n > max){
new str[65]
get_pcvar_string (sv_redirectaddress, str, 64)
client_cmd(i, "echo Redirecting;Connect %s", str)
}
return PLUGIN_CONTINUE
}
#include <amxmodx>
#include <cstrike>
#include <amxmisc>
new const version[] = "0.1"
enum GameStatus {
REST,
KNIFE,
MATCH_F,
MATCH_L
}
new GameStatus:status = REST
new score[2] = {0,0}
new sidevote[2] = {0,0}
new overtime = 0
new maxrounds = 0
public plugin_init ()
{
register_plugin ("Standard Match", version, "meta")
register_cvar ("knifecfgfile", "knife.cfg")
register_cvar ("matchcfgfile", "lo3.cfg")
register_cvar ("overtimecfgfile", "ot.cfg")
register_cvar ("restcfgfile", "practice.cfg")
register_cvar ("mp_halfrounds", "15", FCVAR_SERVER)
register_cvar ("mp_overtime", "1", FCVAR_SERVER)
register_cvar ("mp_halfrounds_overtime", "3", FCVAR_SERVER)
register_cvar ("mp_preparetime", "15", FCVAR_SERVER)
register_cvar ("mp_readytime", "15", FCVAR_SERVER)
register_event ("TextMsg", "event_gamecommencing", "a", "2&#Game_C")
register_event ("CurWeapon", "event_curweapon", "be", "1=1", "2!29")
register_event ("SendAudio", "event_terwin", "a", "2=%!MRAD_terwin")
register_event ("SendAudio", "event_ctwin", "a", "2=%!MRAD_ctwin")
register_event ("HLTV", "update_scoreboard", "a", "2=90")
register_event ("TeamScore", "update_scoreboard", "a")
register_menu ("Select your side", MENU_KEY_1|MENU_KEY_2, "count_sidevote")
}
public count_sidevote (i, key)
{
sidevote[key] += 1
new name[32], team[32]
get_user_name (i, name, 31)
team = (key) ? "Counter-Terrorist Force" : "Terrorist Force"
client_print (0, print_chat, "%s chose %s", name, team)
}
public update_scoreboard ()
{
new scoreid = get_user_msgid ("TeamScore")
message_begin (MSG_ALL, scoreid)
write_string ("TERRORIST")
write_short (score[0])
message_end ()
message_begin (MSG_ALL, scoreid)
write_string ("CT")
write_short (score[1])
message_end ()
}
exec_cfg (cfgfile[128])
{
new config[128]
get_cvar_string (cfgfile, config, 127)
if (file_exists (config)) server_cmd ("exec %s", config)
}
public restartround ()
{
server_cmd ("sv_restartround 1")
}
exec_lo3cfg (cfgfile[128])
{
new config[128]
get_cvar_string (cfgfile, config, 127)
if (file_exists (config)) server_cmd ("exec %s", config)
else {
restartround ()
set_task (1.1, "restartround")
set_task (2.2, "restartround")
}
}
public countdown_knife (n)
{
client_print (0, print_center, "The Knife Round will start in %d SECOND%s", n, (n > 1) ? "S" : "")
}
public countdown_sidevote (n)
{
client_print (0, print_center, "Team select will finish in %d SECOND%s", n, (n > 1) ? "S" : "")
}
public countdown_firsthalf (n)
{
client_print (0, print_center, "The First Half will start in %d SECOND%s", n, (n > 1) ? "S" : "")
}
public countdown_latterhalf (n)
{
client_print (0, print_center, "The Latter Half will start in %d SECOND%s", n, (n > 1) ? "S" : "")
}
public countdown_overtime (n)
{
client_print (0, print_center, "The Overtime will start in %d SECOND%s", n, (n > 1) ? "S" : "")
}
show_countdown (n, func[64])
{
for (new i = 1; i < n; i++) set_task (i - 0.0, func, n - i)
}
public change_side ()
{
new players[32], num
get_players (players, num)
for (new index = 0; index < num; index++){
new i = players[index]
new CsTeams:side = cs_get_user_team (i)
switch (side){
case CS_TEAM_T: cs_set_user_team (i, CS_TEAM_CT, CS_CT_SAS)
case CS_TEAM_CT: {
cs_set_user_team (i, CS_TEAM_T, CS_T_LEET)
cs_set_user_defuse (i, 0)
}
default: {}
}
}
new tmp = score[1]
score[1] = score[0]
score[0] = tmp
}
public event_curweapon (i)
{
if (status == KNIFE && read_data (2) != 6) engclient_cmd (i, "weapon_knife")
return PLUGIN_CONTINUE
}
round_win (CsTeams:win)
{
new b = (win == CS_TEAM_T) ? 0 : 1
if (status != REST) score[b] += 1
new r = get_cvar_num ("mp_halfrounds")
new o = get_cvar_num ("mp_halfrounds_overtime")
new h = (overtime) ? o : r
new s = r + overtime * o
switch (status){
case REST: return PLUGIN_CONTINUE
case KNIFE: end_knife (win)
case MATCH_F: if (score[b] + score[1-b] == 2 * s - h) end_firsthalf ()
case MATCH_L: {
if (score[b] == s + 1) end_latterhalf (win)
else if (score[b] + score[1-b] == 2 * s) end_latterhalf (CS_TEAM_UNASSIGNED)
}
default: {}
}
return PLUGIN_CONTINUE
}
public event_terwin ()
{
round_win (CS_TEAM_T)
return PLUGIN_CONTINUE
}
public event_ctwin ()
{
round_win (CS_TEAM_CT)
return PLUGIN_CONTINUE
}
public event_gamecommencing ()
{
status = REST
exec_cfg ("restcfgfile")
new t = get_cvar_num ("mp_preparetime")
set_task (t + 1.0, "start_knife")
show_countdown (t + 1, "countdown_knife")
return PLUGIN_CONTINUE
}
public start_knife ()
{
status = KNIFE
score[0] = score[1] = 0
exec_lo3cfg ("knifecfgfile")
}
public end_knife (CsTeams:win)
{
status = REST
exec_cfg ("restcfgfile")
start_sidevote (win)
}
public start_sidevote (CsTeams:win)
{
new menu[128]
format (menu, 127, "\ySelect your side^n^n\w1. Terrorist Force^n2. Counter-Terrorist Force")
for (new i = 1; i < 33; i++){
if (is_user_connected (i) && cs_get_user_team (i) == win)
show_menu (i, MENU_KEY_1|MENU_KEY_2, menu, 10)
}
set_task (11.0, "end_sidevote")
show_countdown (11, "countdown_sidevote")
}
public end_sidevote ()
{
new win = (score[0] > score[1]) ? 0 : 1
client_print (0, print_chat, "Result: Terrorist(%d) CT(%d)", sidevote[0], sidevote[1])
if (sidevote[win] < sidevote[1 - win] || (sidevote[0] == sidevote[1] && random (2))) {
change_side ()
restartround ()
}
score[0] = score[1] = 0
set_task (3.0, "ready_for_match")
}
public ready_for_match ()
{
new t = get_cvar_num ("mp_readytime")
set_task (t + 1.0, "start_firsthalf")
show_countdown (t + 1, overtime ? "countdown_overtime" : "countdown_firsthalf")
}
public start_firsthalf ()
{
status = MATCH_F
exec_lo3cfg (overtime ? "overtimecfgfile" : "matchcfgfile")
}
public end_firsthalf ()
{
status = REST
exec_cfg ("restcfgfile")
set_task (2.5, "change_side")
set_task (3.0, "intermission")
}
public intermission ()
{
new t = get_cvar_num ("mp_readytime")
set_task (t + 1.0, "start_latterhalf")
show_countdown (t + 1, "countdown_latterhalf")
}
public start_latterhalf ()
{
status = MATCH_L
exec_lo3cfg (overtime ? "overtimecfgfile" : "matchcfgfile")
}
public end_latterhalf (CsTeams:win)
{
status = REST
if (win == CS_TEAM_UNASSIGNED && get_cvar_num ("mp_overtime")){
overtime += 1
exec_cfg ("restcfgfile")
set_task (3.0, "ready_for_match")
} else {
set_task (5.0, "end_match")
}
}
public end_match()
{
maxrounds = get_cvar_num ("mp_maxrounds")
set_cvar_num ("mp_maxrounds", 1)
}
public plugin_end ()
{
set_cvar_num ("mp_maxrounds", maxrounds)
}
/*
* Sleep Config
*
* Auto Config Loader.
* Sleep : when the number of players becomes less than <sleep_minplayers>
* Wakeup: when the number of players becomes <sleep_minplayers> or more
*
* ex. sleep_minplayers 3
* number of the players 2 -> 3 : Wakeup(cvar wakeupcfgfile)
* number of the players 3 -> 2 : Sleep (cvar sleepcfgfile)
*
* To disable this plugin, set sleep_minplayers 0 or less.
*
* This plugin originally created by Ryozi (amx_cacacl),
* this is an arranged version.
*/
#include <amxmodx>
new g_minplayers
new g_sleepcfg
new g_wakeupcfg
new count = 0
public plugin_init()
{
register_plugin("Sleep Config", "0.2", "meta")
g_minplayers = register_cvar("sleep_minplayers", "1")
g_sleepcfg = register_cvar("sleepcfgfile", "")
g_wakeupcfg = register_cvar("wakeupcfgfile", "")
set_task(10.0,"sleep_check")
}
public sleep_check()
{
if(count < get_pcvar_num(g_minplayers)) exec_cfg(g_sleepcfg)
return PLUGIN_CONTINUE
}
public client_connect(id)
{
if(is_user_hltv(id) || is_user_bot(id)) return PLUGIN_CONTINUE
count += 1
if(count == get_pcvar_num(g_minplayers)) exec_cfg(g_wakeupcfg)
return PLUGIN_CONTINUE
}
public client_disconnect(id)
{
if(is_user_hltv(id) || is_user_bot(id)) return PLUGIN_CONTINUE
count -= 1
if(count == get_pcvar_num(g_minplayers) - 1) exec_cfg(g_sleepcfg)
return PLUGIN_CONTINUE
}
exec_cfg(pcvar)
{
new config[128]
get_pcvar_string(pcvar, config, 127)
if(config[0]) server_cmd("exec %s", config)
}
/* AMX Mod X
* StatsX Plugin
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
//--------------------------------
#include <amxmodx>
#include <amxmisc>
#include <csx>
//--------------------------------
// Uncomment to activate log debug messages.
//#define STATSX_DEBUG
// You can also manualy enable or disable these options by setting them to 1
// For example:
// public ShowAttackers = 1
// However amx_statscfg command is recommended
// Standard Contstants.
#define MAX_TEAMS 2
#define MAX_PLAYERS 32 + 1
#define MAX_NAME_LENGTH 31
#define MAX_WEAPON_LENGTH 31
#define MAX_TEXT_LENGTH 255
#define MAX_BUFFER_LENGTH 2047
// User stats parms id
#define STATS_KILLS 0
#define STATS_DEATHS 1
#define STATS_HS 2
#define STATS_TKS 3
#define STATS_SHOTS 4
#define STATS_HITS 5
#define STATS_DAMAGE 6
// Killer information, save killer info at the time when player is killed.
#define KILLED_KILLER_ID 0 // Killer userindex/user-ID
#define KILLED_KILLER_HEALTH 1 // Killer's health
#define KILLED_KILLER_ARMOUR 2 // Killer's armour
#define KILLED_TEAM 3 // Killer's team
#define KILLED_KILLER_STATSFIX 4 // Fix to register the last hit/kill
new g_izKilled[MAX_PLAYERS][5]
new g_izShowStatsFlags[MAX_PLAYERS] = {0, ...}
new g_izStatsSwitch[MAX_PLAYERS] = {0, ...}
new Float:g_fzShowUserStatsTime[MAX_PLAYERS] = {0.0, ...}
new Float:g_fFreezeTime = 0.0
new g_iRoundEndTriggered = 0
new g_iRoundEndProcessed = 0
new Float:g_fStartGame = 0.0
new g_izTeamScore[MAX_TEAMS] = {0, ...}
new g_izTeamEventScore[MAX_TEAMS] = {0, ...}
new g_izTeamRndStats[MAX_TEAMS][8]
new g_izTeamGameStats[MAX_TEAMS][8]
new g_izUserUserID[MAX_PLAYERS] = {0, ...}
new g_izUserAttackerDistance[MAX_PLAYERS] = {0, ...}
new g_izUserVictimDistance[MAX_PLAYERS][MAX_PLAYERS]
new g_izUserRndName[MAX_PLAYERS][MAX_NAME_LENGTH + 1]
new g_izUserRndStats[MAX_PLAYERS][8]
new g_izUserGameStats[MAX_PLAYERS][8]
// Common buffer to improve performance, as Small always zero-initializes all vars
new g_sBuffer[MAX_BUFFER_LENGTH + 1] = ""
new t_sText[MAX_TEXT_LENGTH + 1] = ""
new t_sName[MAX_NAME_LENGTH + 1] = ""
new t_sWpn[MAX_WEAPON_LENGTH + 1] = ""
//--------------------------------
// Initialize
//--------------------------------
public plugin_init()
{
// Register plugin.
register_plugin("StatsX Lite", "0.1", "AMXX Dev Team +meta")
register_dictionary("statsx.txt")
// Register events.
register_event("TextMsg", "eventStartGame", "a", "2=#Game_Commencing", "2=#Game_will_restart_in")
register_event("ResetHUD", "eventResetHud", "be")
register_event("RoundTime", "eventStartRound", "bc")
register_event("SendAudio", "eventEndRound", "a", "2=%!MRAD_terwin", "2=%!MRAD_ctwin", "2=%!MRAD_rounddraw")
register_event("TeamScore", "eventTeamScore", "a")
// Init buffers and some global vars.
g_sBuffer[0] = 0
}
public plugin_cfg()
{
// Update local configuration vars with value in cvars.
get_config_cvars()
}
// Set hudmessage format.
set_hudtype_attacker(Float:fDuration)
{
set_hudmessage(220, 80, 0, 0.55, 0.35, 0, 6.0, fDuration, (fDuration >= 12.0) ? 1.0 : 0.0, 1.0, -1)
}
set_hudtype_victim(Float:fDuration)
{
set_hudmessage(0, 80, 220, 0.55, 0.60, 0, 6.0, fDuration, (fDuration >= 12.0) ? 1.0 : 0.0, 1.0, -1)
}
// Stats formulas
Float:accuracy(izStats[8])
{
if (!izStats[STATS_SHOTS])
return (0.0)
return (100.0 * float(izStats[STATS_HITS]) / float(izStats[STATS_SHOTS]))
}
// Get config parameters.
get_config_cvars()
{
g_fFreezeTime = get_cvar_float("mp_freezetime")
if (g_fFreezeTime < 0.0)
g_fFreezeTime = 0.0
}
// Get and format attackers header and list.
get_attackers(id, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new izStats[8], izBody[8]
new iAttacker
new iFound, iLen
new iMaxPlayer = get_maxplayers()
iFound = 0
sBuffer[0] = 0
// Get and format header. Add killing attacker statistics if user is dead.
// Make sure shots is greater than zero or division by zero will occur.
// To print a '%', 4 of them must done in a row.
izStats[STATS_SHOTS] = 0
iAttacker = g_izKilled[id][KILLED_KILLER_ID]
if (iAttacker)
{
get_user_astats(id, iAttacker, izStats, izBody)
}
iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L:^n", id, "ATTACKERS")
// Get and format attacker list.
for (iAttacker = 1; iAttacker <= iMaxPlayer; iAttacker++)
{
if (get_user_astats(id, iAttacker, izStats, izBody, t_sWpn, MAX_WEAPON_LENGTH))
{
iFound = 1
get_user_name(iAttacker, t_sName, MAX_NAME_LENGTH)
if (izStats[STATS_KILLS])
{
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen,
"%s -- %d %L / %d %L / %s^n", t_sName,
izStats[STATS_HITS], id, "HIT_S",
izStats[STATS_DAMAGE], id, "DMG", t_sWpn)
}
else
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen,
"%s -- %d %L / %d %L^n", t_sName,
izStats[STATS_HITS], id, "HIT_S",
izStats[STATS_DAMAGE], id, "DMG")
}
}
if (!iFound)
sBuffer[0] = 0
return iFound
}
// Get and format victims header and list
get_victims(id, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new izStats[8], izBody[8]
new iVictim
new iFound, iLen
new iMaxPlayer = get_maxplayers()
iFound = 0
sBuffer[0] = 0
// Get and format header.
// Make sure shots is greater than zero or division by zero will occur.
// To print a '%', 4 of them must done in a row.
izStats[STATS_SHOTS] = 0
get_user_vstats(id, 0, izStats, izBody)
if (izStats[STATS_SHOTS])
iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L -- %0.2f%% %L:^n", id, "VICTIMS", accuracy(izStats), id, "ACC")
else
iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L:^n", id, "VICTIMS")
for (iVictim = 1; iVictim <= iMaxPlayer; iVictim++)
{
if (get_user_vstats(id, iVictim, izStats, izBody, t_sWpn, MAX_WEAPON_LENGTH))
{
iFound = 1
get_user_name(iVictim, t_sName, MAX_NAME_LENGTH)
if (izStats[STATS_DEATHS])
{
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen,
"%s -- %d %L / %d %L / %s^n", t_sName,
izStats[STATS_HITS], id, "HIT_S",
izStats[STATS_DAMAGE], id, "DMG", t_sWpn)
}
else
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen,
"%s -- %d %L / %d %L^n", t_sName,
izStats[STATS_HITS], id, "HIT_S",
izStats[STATS_DAMAGE], id, "DMG")
}
}
if (!iFound)
sBuffer[0] = 0
return iFound
}
// Show round end stats.
show_user_hudstats(id, Float:fGameTime)
{
// Bail out if there no HUD stats should be shown
// for this player or user stats timer is zero.
if (!g_izStatsSwitch[id]) return
if (g_fzShowUserStatsTime[id] == 0.0) return
// Set HUD-duration to default or remaining time.
new Float:fDuration
if (fGameTime == 0.0)
fDuration = 12.0
else
{
fDuration = g_fzShowUserStatsTime[id] + 12.0 - fGameTime
if (fDuration > g_fFreezeTime - 2.0)
fDuration = g_fFreezeTime - 2.0
}
// Show stats only if more time left than coded minimum.
if (fDuration >= 0.2)
{
get_victims(id, g_sBuffer)
set_hudtype_victim(fDuration)
show_hudmessage(id, "%s", g_sBuffer)
get_attackers(id, g_sBuffer)
set_hudtype_attacker(fDuration)
show_hudmessage(id, "%s", g_sBuffer)
}
}
//------------------------------------------------------------
// Plugin events
//------------------------------------------------------------
// Reset game stats on game start and restart.
public eventStartGame()
{
read_data(2, t_sText, MAX_TEXT_LENGTH)
if (t_sText[6] == 'w')
{
read_data(3, t_sText, MAX_TEXT_LENGTH)
g_fStartGame = get_gametime() + float(str_to_num(t_sText))
}
else
g_fStartGame = get_gametime()
return PLUGIN_CONTINUE
}
// Round start
public eventStartRound()
{
new iTeam, id, i
new Float:roundtime = get_cvar_float("mp_roundtime");
if (read_data(1) >= floatround(roundtime * 60.0,floatround_floor) ||
(roundtime == 2.3 && read_data(1) == 137))
// these round too weird for it to work through pawn, have to add an exception for it
{
// Reset game stats on game start and restart.
if (g_fStartGame > 0.0 && g_fStartGame <= get_gametime())
{
g_fStartGame = 0.0
// Clear team and game stats.
for (iTeam = 0; iTeam < MAX_TEAMS; iTeam++)
{
g_izTeamEventScore[iTeam] = 0
for (i = 0; i < 8; i++)
g_izTeamGameStats[iTeam][i] = 0
}
// Clear game stats, incl '0' that is sum of all users.
for (id = 0; id < MAX_PLAYERS; id++)
{
for (i = 0; i < 8; i++)
g_izUserGameStats[id][i] = 0
}
}
// Update team score with "TeamScore" event values and
// clear team round stats.
for (iTeam = 0; iTeam < MAX_TEAMS; iTeam++)
{
g_izTeamScore[iTeam] = g_izTeamEventScore[iTeam]
for (i = 0; i < 8; i++)
g_izTeamRndStats[iTeam][i] = 0
}
// Clear user round stats, incl '0' that is sum of all users.
for (id = 0; id < MAX_PLAYERS; id++)
{
g_izUserRndName[id][0] = 0
for (i = 0; i < 8; i++)
g_izUserRndStats[id][i] = 0
g_fzShowUserStatsTime[id] = 0.0
}
// Allow end round stats and reset end round triggered indicator.
g_iRoundEndTriggered = 0
g_iRoundEndProcessed = 0
// Update local configuration vars with value in cvars.
get_config_cvars()
}
return PLUGIN_CONTINUE
}
// Reset killer info on round restart.
public eventResetHud(id)
{
// Show user and score round stats after HUD-reset
show_user_hudstats(id, get_gametime())
// Reset round stats
g_izKilled[id][KILLED_KILLER_ID] = 0
g_izKilled[id][KILLED_KILLER_STATSFIX] = 0
g_izShowStatsFlags[id] = -1 // Initialize flags
g_fzShowUserStatsTime[id] = 0.0
g_izUserAttackerDistance[id] = 0
for (new i = 0; i < MAX_PLAYERS; i++)
g_izUserVictimDistance[id][i] = 0
return PLUGIN_CONTINUE
}
// Save killer info on death.
public client_death(killer, victim, wpnindex, hitplace, TK)
{
// Bail out if no killer.
if (!killer)
return PLUGIN_CONTINUE
if (killer != victim)
{
new iaVOrigin[3], iaKOrigin[3]
new iDistance
get_user_origin(victim, iaVOrigin)
get_user_origin(killer, iaKOrigin)
g_izKilled[victim][KILLED_KILLER_ID] = killer
g_izKilled[victim][KILLED_KILLER_HEALTH] = get_user_health(killer)
g_izKilled[victim][KILLED_KILLER_ARMOUR] = get_user_armor(killer)
g_izKilled[victim][KILLED_KILLER_STATSFIX] = 0
iDistance = get_distance(iaVOrigin, iaKOrigin)
g_izUserAttackerDistance[victim] = iDistance
g_izUserVictimDistance[killer][victim] = iDistance
}
g_izKilled[victim][KILLED_TEAM] = get_user_team(victim)
g_izKilled[victim][KILLED_KILLER_STATSFIX] = 1
// Display kill stats for the player if round
// end stats was not processed.
if (!g_iRoundEndProcessed)
kill_stats(victim)
return PLUGIN_CONTINUE
}
// Display hudmessage stats on death.
// This will also update all round and game stats.
// Must be called at least once per round.
kill_stats(id)
{
// Bail out if user stats timer is non-zero,
// ie function already called.
if (g_fzShowUserStatsTime[id] > 0.0)
{
return
}
new team = get_user_team(id)
if (team < 1 || team > 2)
{
return
}
// Flag kill stats displayed for this player.
g_fzShowUserStatsTime[id] = get_gametime()
// Add user death stats to user round stats
new izStats[8], izBody[8]
new iTeam, i
new iKiller
iKiller = g_izKilled[id][KILLED_KILLER_ID]
// Get user's team (if dead use the saved team)
if (iKiller)
iTeam = g_izKilled[id][KILLED_TEAM] - 1
else
iTeam = get_user_team(id) - 1
get_user_name(id, g_izUserRndName[id], MAX_NAME_LENGTH)
if (get_user_rstats(id, izStats, izBody))
{
// Update user's team round stats
if (iTeam >= 0 && iTeam < MAX_TEAMS)
{
for (i = 0; i < 8; i++)
{
g_izTeamRndStats[iTeam][i] += izStats[i]
g_izTeamGameStats[iTeam][i] += izStats[i]
g_izUserRndStats[0][i] += izStats[i]
g_izUserGameStats[0][i] += izStats[i]
}
}
// Update user's round stats
if (g_izUserUserID[id] == get_user_userid(id))
{
for (i = 0; i < 8; i++)
{
g_izUserRndStats[id][i] += izStats[i]
g_izUserGameStats[id][i] += izStats[i]
}
} else {
g_izUserUserID[id] = get_user_userid(id)
for (i = 0; i < 8; i++)
{
g_izUserRndStats[id][i] = izStats[i]
g_izUserGameStats[id][i] = izStats[i]
}
}
} // endif (get_user_rstats())
// Display player stats info.
show_user_hudstats(id, 0.0)
}
public eventEndRound()
{
// Update local configuration vars with value in cvars.
get_config_cvars()
// If first end round event in the round, calculate team score.
if (!g_iRoundEndTriggered)
{
read_data(2, t_sText, MAX_TEXT_LENGTH)
if (t_sText[7] == 't') // Terrorist wins
g_izTeamScore[0]++
else if (t_sText[7] == 'c') // CT wins
g_izTeamScore[1]++
}
set_task(0.3, "endround_stats", 997)
return PLUGIN_CONTINUE
}
public endround_stats()
{
// Flag round end triggered.
g_iRoundEndTriggered = 1
// Bail out if end round stats has already been processed
// or round end not triggered.
if (g_iRoundEndProcessed || !g_iRoundEndTriggered)
return
new iaPlayers[32], iPlayer, iPlayers, id
get_players(iaPlayers, iPlayers)
// Display attacker & victim list for all living players.
// This will also update all round and game stats for all players
// not killed.
for (iPlayer = 0; iPlayer < iPlayers; iPlayer++)
{
id = iaPlayers[iPlayer]
if (g_fzShowUserStatsTime[id] == 0.0)
{
kill_stats(id)
}
}
// Flag round end processed.
g_iRoundEndProcessed = 1
}
public eventTeamScore()
{
new sTeamID[1 + 1], iTeamScore
read_data(1, sTeamID, 1)
iTeamScore = read_data(2)
g_izTeamEventScore[(sTeamID[0] == 'C') ? 1 : 0] = iTeamScore
return PLUGIN_CONTINUE
}
public client_connect(id)
{
get_user_info(id, "_amxstatsx", t_sText, MAX_TEXT_LENGTH)
g_izStatsSwitch[id] = (t_sText[0]) ? str_to_num(t_sText) : -1
g_izKilled[id][KILLED_KILLER_ID] = 0
g_izKilled[id][KILLED_KILLER_STATSFIX] = 0
g_izShowStatsFlags[id] = 0 // Clear all flags
g_fzShowUserStatsTime[id] = 0.0
return PLUGIN_CONTINUE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment