11/12/2018, 05:30 PM
(Última modificación: 11/12/2018, 05:30 PM por metita. Edited 1 time in total.)
Otro plugin mas que tengo botado por ahi... todos los creditos a Sugisaki, autor del plugin.
Cumple su funcion.
Requisitos:
- AMXX 1.8.3 (Fue hecho para esa version, no fue compilado ni con 1.8.2 ni con 1.9.0 ni posteriores builds).
- ReAPI
- MySQLt (https://amxmodx-es.com/Thread-Modulo-MySQL-Threads-1-2)
- Base de datos MySQL
Ademas crear: amxmodx/configs/ranks.ini (el archivo ranks.ini lo crean ustedes)
con la siguiente estructura:
En fin, se testeo en su momento y funciona perfecto, como ya no le doy uso de hace meses, prefiero que alguien mas le de el uso que desee.
Tiene ademas una serie de natives para que puedan darle otro tipo de usos de acuerdo a lo que ustedes estimen convenientes.
Cumple su funcion.
Requisitos:
- AMXX 1.8.3 (Fue hecho para esa version, no fue compilado ni con 1.8.2 ni con 1.9.0 ni posteriores builds).
- ReAPI
- MySQLt (https://amxmodx-es.com/Thread-Modulo-MySQL-Threads-1-2)
- Base de datos MySQL
Ademas crear: amxmodx/configs/ranks.ini (el archivo ranks.ini lo crean ustedes)
con la siguiente estructura:
Código PHP:
; "Nombre del rango" "Experiencia necesaria para alcanzar el rango."
"Sin Rango" 0
"Sin Rango #1" 500
"Sin Rango #2" 1500
"Sin Rango #3" 5000
"Sin Rango #4" 12000
"Sin Rango #5" 17000
Código PHP:
#include <amxmodx>
#include <mysqlt>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <fakemeta>
#include <reapi>
#define PLUGIN_NAME "Rank System"
#define VERSION "1.0"
#define AUTHOR "Sugisaki"
#define Login(%1) (g_estado |= (1<<(%1&31)))
#define LogOff(%1) (g_estado &= ~(1<<(%1&31)))
#define IsUserLogged(%1) (g_estado & (1<<(%1&31)))
new g_estado
new rank[33]
new exp[33]
new const DB_HOST[] = "localhost"
new const DB_USER[] = ""
new const DB_PASS[] = ""
new const DB___DB[] = ""
new Handle:SQL_Handle
new const IN_TAG[] = "[AMXX]"
new SQL_TABLE[] = "CREATE TABLE IF NOT EXISTS `rangos` ( `id` INT NOT NULL AUTO_INCREMENT , `user` VARCHAR(33) NOT NULL , `rank` INT NOT NULL DEFAULT '0' , `exp` INT NOT NULL DEFAULT '0' , PRIMARY KEY (`id`), UNIQUE (`user`)) ENGINE = MyISAM;"
new g_PlayerName[33][33]
new g_last_query_count = 0
new g_last_save_count = 0
new g_maxplayers
new Array:g_ranks
new Array:g_exps
new const INI_FILE[] = "addons/amxmodx/configs/ranks.ini"
new Sync
public plugin_init()
{
register_plugin( PLUGIN_NAME, VERSION, AUTHOR)
register_forward( FM_ClientDisconnect, "OnClientDisconnect")
register_event("DeathMsg", "OnPlayerKilled", "a")
register_clcmd("joinclass", "load_rank")
RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)
Sync = CreateHudSyncObj()
g_maxplayers = get_maxplayers()
db_con()
read_ini()
set_task(1.0, "ShowHudRank", .flags="b")
}
db_con()
{
new errno, error[128]
SQL_Handle = mysql_connect( mysql_makehost( DB_HOST, DB_USER, DB_PASS, DB___DB), errno, error, charsmax(error));
if(SQL_Handle == Empty_Handle)
{
log_amx("%s La base de datos se encuentra apagada.", IN_TAG)
log_amx("%s %s",IN_TAG, error)
return;
}
mysql_performance(75, 75, 3);
mysql_query(SQL_Handle, "_handler_table", "SET NAMES utf8");
mysql_query(SQL_Handle, "_handler_table", "SET CHARACTER SET utf8");
mysql_query( SQL_Handle, "_handler_table", SQL_TABLE)
}
stock read_ini()
{
if(! file_exists( INI_FILE))
{
set_fail_state("%s Archivo de configuracion no existe.", IN_TAG);
}
new fh = fopen( INI_FILE, "r")
if(!fh)
{
set_fail_state("%s No se puede abrir el archivo de configuracion porque no existe.", IN_TAG);
}
new line[128], p1[sizeof(line) / 2], p2[sizeof(line) / 2]
new file_len = file_size( INI_FILE, FSOPT_LINES_COUNT) + 1;
g_ranks = ArrayCreate(68, file_len)
g_exps = ArrayCreate(68, file_len)
while(!feof(fh))
{
fgets(fh, line, charsmax(line))
trim(line)
if(!line[0] || line[0] == ';')
{
continue;
}
parse(line, p1, charsmax(p1), p2, charsmax(p2))
trim(p1)
trim(p2)
if(!p2[0] || !p1[0])
{
continue;
}
ArrayPushString( g_ranks, p1);
ArrayPushCell( g_exps, str_to_num(p2));
}
}
public _handler_table(failstate, error[], errnum, data[], size, Float:queuetime)
{
if(failstate != TQUERY_SUCCESS)
{
log_amx("%s %s", IN_TAG, error)
return;
}
}
public OnClientDisconnect(id)
{
save_data(id)
LogOff(id)
}
public client_putinserver(id)
{
get_user_name(id, g_PlayerName[id], charsmax(g_PlayerName[]))
sql_escape(g_PlayerName[id])
rank[id] = 0
exp[id] = 0
}
public load_rank(id)
{
if( IsUserLogged(id))
{
return
}
Login(id)
new data[2]
data[0] = id
mysql_query( SQL_Handle, "_handler_load_data",
fmt("SELECT rank,exp FROM `rangos` WHERE user='%s'", g_PlayerName[id]),
data,
charsmax(data)
);
}
stock sql_escape(str[])
{
new len = 34
trim(str)
replace_all(str, len, "\", "\\")
replace_all(str, len, "^"", "\^"");
replace_all(str, len, "'", "\'");
}
public _handler_load_data(failstate, error[], errnum, data[], size, Float:queuetime)
{
if(failstate != TQUERY_SUCCESS)
{
log_amx("%s %s", IN_TAG, error)
set_fail_state(error)
return;
}
new id = data[0]
if( mysql_num_results() > 0)
{
rank[id] = mysql_read_result(0)
exp[id] = mysql_read_result(1)
}
check_rank(id)
}
public OnPlayerSpawn(id)
{
if(!is_user_alive(id))
{
return
}
load_rank(id)
}
save_data(id, const Handler[] = "_handler_save_data")
{
if(! IsUserLogged(id))
{
return
}
mysql_query( SQL_Handle, Handler,
fmt("INSERT INTO `rangos` (user,rank,exp) VALUES (^"%s^",'%i','%i') ON DUPLICATE KEY UPDATE rank='%i',exp='%i'",
g_PlayerName[id], rank[id], exp[id], rank[id], exp[id])
);
}
public _handler_save_data(failstate, error[], errnum, data[], size, Float:queuetime)
{
if(failstate != TQUERY_SUCCESS)
{
log_amx("%s %s", IN_TAG, error)
return;
}
}
public plugin_end()
{
g_last_query_count = 0
g_last_save_count = 0
for(new i = 1 ; i <= g_maxplayers ; i++)
{
if(IsUserLogged(i))
{
g_last_query_count +=1
}
}
for(new i = 1 ; i <= g_maxplayers ; i++)
{
if(IsUserLogged(i))
{
save_data(i, "_handler_last_save")
}
}
}
public _handler_last_save(failstate, error[], errnum, data[], size, Float:queuetime)
{
if(failstate != TQUERY_SUCCESS)
{
log_amx("%s %s", IN_TAG, error)
return;
}
g_last_save_count+=1
if(g_last_save_count >= g_last_query_count)
{
mysql_free( SQL_Handle);
}
}
public plugin_natives()
{
register_native("get_rank", "_native_get_rank")
register_native("get_exp", "_native_get_exp")
register_native("add_exp", "_native_add_exp")
}
public _native_get_rank()
{
if(is_user_connected(get_param(1)))
{
return rank[get_param(1)]
}
return 0;
}
public _native_get_exp()
{
if(is_user_connected(get_param(1)))
{
return exp[get_param(1)]
}
return 0;
}
public _native_add_exp()
{
add_exp(get_param(1), get_param(2))
}
stock add_exp(id, amount)
{
if(is_user_connected(id))
{
exp[id] += amount;
check_rank(id)
}
}
stock get_next_rank_exp(id)
{
if( ArraySize( g_ranks) - 1 > rank[id])
{
return ArrayGetCell( g_exps, rank[id] + 1)
}
return ArrayGetCell( g_exps, ArraySize( g_exps) - 1)
}
stock check_rank(id)
{
while( exp[id] >= get_next_rank_exp(id) && rank[id] < ArraySize( g_ranks) - 1)
{
rank[id] += 1
client_print_color(id, print_team_default, "^4[AMXX]^1 Felicidades, subiste al siguiente rango por superar la experiencia requerida.");
}
}
UpdateHud(id)
{
new szName[32]
get_user_name(id, szName, charsmax(szName));
set_hudmessage(247, 255, 0, 0.02, 0.15, 0, 0.0, 1.1, 0.0, 0.0, -1);
ShowSyncHudMsg(id, Sync, "Nick: %s^nHP: %d - AR: %d^nRango: %a^nExperiencia: %i/%i", szName, get_user_health(id), get_user_armor(id), ArrayGetStringHandle( g_ranks, rank[id]), exp[id], get_next_rank_exp(id))
}
public ShowHudRank()
{
static z
for(z = 0 ; z <= g_maxplayers ; z++)
{
if(IsUserLogged(z) && is_user_alive(z))
{
UpdateHud(z)
}
}
}
public OnPlayerKilled()
{
new id = read_data(2)
new attacker = read_data(1)
if(! is_user_connected(id) || ! is_user_connected( attacker) || id== attacker)
{
return;
}
if( read_data(3))
{
add_exp( attacker, 3);
client_print_color(attacker, print_team_default, "^4[AMXX]^1 Obtuviste^3 3 de experiencia^1 por matar a un enemigo de^4 Headshot.");
}
else
{
add_exp( attacker, 2);
client_print_color(attacker, print_team_default, "^4[AMXX]^1 Obtuviste^3 2 de experiencia^1 por matar a un^4 enemigo.");
}
UpdateHud( attacker)
}
En fin, se testeo en su momento y funciona perfecto, como ya no le doy uso de hace meses, prefiero que alguien mas le de el uso que desee.
Tiene ademas una serie de natives para que puedan darle otro tipo de usos de acuerdo a lo que ustedes estimen convenientes.