Либо дело либо не пиши! дождусь чела который шарит и поможет может быть! "Надежда"Анатолий, Тебе уже помогли, но почти никто за тебя думать или писать код не будет. Можем только направление дать )
Либо дело либо не пиши! дождусь чела который шарит и поможет может быть! "Надежда"Анатолий, Тебе уже помогли, но почти никто за тебя думать или писать код не будет. Можем только направление дать )
выходишь с сервера сохранение идет в базу. сохраняет норм) заходишь на сервер скилл сразу L- 0 тоесть сохраняет норм но прочитать число не получается вот и сбрасывает на 0 как я понялПроследите в какой момент идет сброс на 0 - при заходе на сервер, или же после убийств. Это покажет в каком участке кода копать.
в базе число целое сохраняет например 120 но когда заходишь на сервер вновь сразу скилл 0 и это число сохраняет в базу 0Проследите в какой момент идет сброс на 0 - при заходе на сервер, или же после убийств. Это покажет в каком участке кода копать.
format(szTemp, charsmax(szTemp), "UPDATE `%s` SET `skill` = '%i' WHERE `%s`.`steamid` = '%s'", szTable, g_user_skill[id][Skill], szTable, szSteamId)
я пробывал меня на что угодно не помогает все равно сохраняет норм в базу но читает 0Вооот теперь все встало на места и я заметил кажется косячок)
вот тут:
%i замени на %d (если целое число) или на %f (если дробное)Код:format(szTemp, charsmax(szTemp), "UPDATE `%s` SET `skill` = '%i' WHERE `%s`.`steamid` = '%s'", szTable, g_user_skill[id][Skill], szTable, szSteamId)
смотри не по первому коду а по этомуя пробывал меня на что угодно не помогает все равно сохраняет норм в базу но читает 0
#include <amxmodx>
#include <sqlx>
#include <skill_elo>
#if AMXX_VERSION_NUM < 183
#define client_disconnected client_disconnect
#endif
new Handle:g_SqlTuple
new g_Cvar[11], g_Error[512]
new szHost[64], szUser[64], szPass[64], szBase[64], szTable[64], szDriver[10]
new const g_arrItemSkills[] = {0, 60, 75, 85, 100, 115, 130, 140, 150, 165, 180, 195, 210}
new const g_arrViewSkills[][] = {"S_1", "S_2", "S_3", "S_4", "S_5", "S_6", "S_7", "S_8", "S_9", "S_10", "S_11", "S_12", "S_13"}
enum _:SKILL_DATA {KILLS, Float:Skill}
new g_user_skill[33][SKILL_DATA + 1]
public plugin_init()
{
register_plugin("Skill The ELO Method", "1.0", "AcE")
g_Cvar[1] = register_cvar("skill_start", "100")
g_Cvar[2] = register_cvar("skill_need_frags", "100")
g_Cvar[3] = register_cvar("skill_start_koef", "2.0")
g_Cvar[4] = register_cvar("skill_next_koef", "1.5")
g_Cvar[5] = register_cvar("skill_sql_host", "")
g_Cvar[6] = register_cvar("skill_sql_user", "")
g_Cvar[7] = register_cvar("skill_sql_pass", "")
g_Cvar[8] = register_cvar("skill_sql_db", "")
g_Cvar[9] = register_cvar("skill_sql_table", "")
g_Cvar[10] = register_cvar("skill_sql_type", "mysql")
register_event("DeathMsg", "EventDeath", "a", "1>0")
register_dictionary("skill_elo.txt")
set_task(1.0, "MySql_Init")
}
public plugin_cfg()
server_cmd("exec addons/amxmodx/configs/skill_elo.cfg")
public client_putinserver(id) Load_MySql(id)
public client_disconnected(id) Save_MySql(id)
public plugin_end() SQL_FreeHandle(g_SqlTuple)
public EventDeath()
{
new killer = read_data(1)
new victim = read_data(2)
if (killer == victim) return
new Float:delta = 1.0 / (1.0 + floatpower(10.0, (g_user_skill[killer][Skill] - g_user_skill[victim][Skill]) / 100.0))
g_user_skill[killer][Skill] += (g_user_skill[killer][KILLS] < get_pcvar_num(g_Cvar[2])) ? (delta * get_pcvar_float(g_Cvar[3])) : (delta * get_pcvar_float(g_Cvar[4]))
g_user_skill[victim][Skill] -= (g_user_skill[victim][KILLS] < get_pcvar_num(g_Cvar[2])) ? (delta * get_pcvar_float(g_Cvar[3])) : (delta * get_pcvar_float(g_Cvar[4]))
}
public MySql_Init()
{
get_pcvar_string(g_Cvar[5], szHost, charsmax(szHost))
get_pcvar_string(g_Cvar[6], szUser, charsmax(szUser))
get_pcvar_string(g_Cvar[7], szPass, charsmax(szPass))
get_pcvar_string(g_Cvar[8], szBase, charsmax(szBase))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
get_pcvar_string(g_Cvar[10], szDriver, charsmax(szDriver))
SQL_SetAffinity(szDriver)
g_SqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szBase)
new ErrorCode, Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, g_Error, charsmax(g_Error))
if (SqlConnection == Empty_Handle)
set_fail_state(g_Error)
new Handle:Queries
Queries = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS `%s` (`id` int(11) NOT NULL AUTO_INCREMENT, `steam` char(32), `skill` float NOT NULL, PRIMARY KEY (`id`))", szTable)
if (!SQL_Execute(Queries))
{
SQL_QueryError(Queries, g_Error, charsmax(g_Error))
set_fail_state(g_Error)
}
SQL_FreeHandle(Queries)
SQL_FreeHandle(SqlConnection)
}
public Load_MySql(id)
{
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
new Data[1]; Data[0] = id
format(szTemp, charsmax(szTemp), "SELECT * FROM `%s` WHERE (`%s`. `steam` = '%s')", szTable, szTable, szSteamId)
SQL_ThreadQuery(g_SqlTuple, "register_client", szTemp, Data, 1)
}
public register_client(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
if (FailState == TQUERY_CONNECT_FAILED)
{
log_to_file("skill_elo.txt", "Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
}
else if (FailState == TQUERY_QUERY_FAILED)
{
log_to_file("skill_elo.txt", "Load Query failed. [%d] %s", Errcode, Error)
}
new id; id = Data[0]
if (SQL_NumResults(Query) < 1)
{
new szSteamId[32]
get_user_authid(id, szSteamId, charsmax(szSteamId))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
if (equal(szSteamId, "ID_PENDING"))
return PLUGIN_HANDLED
new szTemp[512]
format(szTemp, charsmax(szTemp), "INSERT INTO `%s` (`steam`, `skill`) VALUES ('%s', '0')", szTable, szSteamId)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", szTemp)
g_user_skill[id][Skill] = float(get_pcvar_num(g_Cvar[1]))
}
else
{
g_user_skill[id][Skill] = Float:SQL_ReadResult(Query, 1)
}
return PLUGIN_HANDLED
}
public Save_MySql(id)
{
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
format(szTemp, charsmax(szTemp), "UPDATE `%s` SET `skill` = '%.2f' WHERE `%s`. `steam` = '%s'", szTable, g_user_skill[id][Skill], szTable, szSteamId)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", szTemp)
}
public IgnoreHandle(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
SQL_FreeHandle(Query)
return PLUGIN_HANDLED
}
stock get_skill_id(Float:skill)
{
for (new i, sk = floatround(skill); i < sizeof g_arrViewSkills; i++)
{
if (i && g_arrItemSkills[i] > sk)
return i - 1
else if ((!i && g_arrItemSkills[i] > sk) || i == charsmax(g_arrViewSkills))
return i
}
return 0
}
public plugin_natives()
{
register_library("skill_elo")
register_native("get_skill_name", "_get_skill_name")
register_native("get_user_skill", "_get_user_skill", 1)
register_native("set_user_skill", "_set_user_skill", 1)
}
public Float:_get_user_skill(id)
return g_user_skill[id][Skill]
public _set_user_skill(id, Float:num)
g_user_skill[id][Skill] = num
public _get_skill_name(plugin, params)
{
new id = get_param(1)
new len = get_param(3)
new Float:skill, skill_id
skill = g_user_skill[id][Skill]
skill_id = get_skill_id(skill)
new buffer[192]; format(buffer, len, "%L", LANG_SERVER, g_arrViewSkills[skill_id])
set_string(2, buffer, len)
}
#include <amxmodx>
#include <sqlx>
#include <skill_elo>
#if AMXX_VERSION_NUM < 183
#define client_disconnected client_disconnect
#endif
new Handle:g_SqlTuple
new g_Cvar[11], g_Error[512]
new szHost[64], szUser[64], szPass[64], szBase[64], szTable[64], szDriver[10]
new const g_arrItemSkills[] = {0, 60, 75, 85, 100, 115, 130, 140, 150, 165, 180, 195, 210}
new const g_arrViewSkills[][] = {"S_1", "S_2", "S_3", "S_4", "S_5", "S_6", "S_7", "S_8", "S_9", "S_10", "S_11", "S_12", "S_13"}
enum _:SKILL_DATA {KILLS, Float:Skill}
new g_user_skill[33][SKILL_DATA + 1]
public plugin_init()
{
register_plugin("Skill The ELO Method", "1.0", "AcE")
g_Cvar[1] = register_cvar("skill_start", "100")
g_Cvar[2] = register_cvar("skill_need_frags", "100")
g_Cvar[3] = register_cvar("skill_start_koef", "2.0")
g_Cvar[4] = register_cvar("skill_next_koef", "1.5")
g_Cvar[5] = register_cvar("skill_sql_host", "")
g_Cvar[6] = register_cvar("skill_sql_user", "")
g_Cvar[7] = register_cvar("skill_sql_pass", "")
g_Cvar[8] = register_cvar("skill_sql_db", "")
g_Cvar[9] = register_cvar("skill_sql_table", "")
g_Cvar[10] = register_cvar("skill_sql_type", "mysql")
register_event("DeathMsg", "EventDeath", "a", "1>0")
register_dictionary("skill_elo.txt")
set_task(1.0, "MySql_Init")
}
public plugin_cfg()
server_cmd("exec addons/amxmodx/configs/skill_elo.cfg")
public client_putinserver(id) Load_MySql(id)
public client_disconnected(id) Save_MySql(id)
public plugin_end() SQL_FreeHandle(g_SqlTuple)
public EventDeath()
{
new killer = read_data(1)
new victim = read_data(2)
if (killer == victim) return
new Float:delta = 1.0 / (1.0 + floatpower(10.0, (g_user_skill[killer][Skill] - g_user_skill[victim][Skill]) / 100.0))
g_user_skill[killer][Skill] += (g_user_skill[killer][KILLS] < get_pcvar_num(g_Cvar[2])) ? (delta * get_pcvar_float(g_Cvar[3])) : (delta * get_pcvar_float(g_Cvar[4]))
g_user_skill[victim][Skill] -= (g_user_skill[victim][KILLS] < get_pcvar_num(g_Cvar[2])) ? (delta * get_pcvar_float(g_Cvar[3])) : (delta * get_pcvar_float(g_Cvar[4]))
}
public MySql_Init()
{
get_pcvar_string(g_Cvar[5], szHost, charsmax(szHost))
get_pcvar_string(g_Cvar[6], szUser, charsmax(szUser))
get_pcvar_string(g_Cvar[7], szPass, charsmax(szPass))
get_pcvar_string(g_Cvar[8], szBase, charsmax(szBase))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
get_pcvar_string(g_Cvar[10], szDriver, charsmax(szDriver))
SQL_SetAffinity(szDriver)
g_SqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szBase)
new ErrorCode, Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, g_Error, charsmax(g_Error))
if (SqlConnection == Empty_Handle)
set_fail_state(g_Error)
new Handle:Queries
Queries = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS `%s` (`id` int(11) NOT NULL AUTO_INCREMENT, `steam` char(32), `skill` DOUBLE(53,2) NOT NULL, PRIMARY KEY (`id`))", szTable)
if (!SQL_Execute(Queries))
{
SQL_QueryError(Queries, g_Error, charsmax(g_Error))
set_fail_state(g_Error)
}
SQL_FreeHandle(Queries)
SQL_FreeHandle(SqlConnection)
}
public Load_MySql(id)
{
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
new Data[1]; Data[0] = id
format(szTemp, charsmax(szTemp), "SELECT * FROM `%s` WHERE (`%s`. `steam` = '%s')", szTable, szTable, szSteamId)
SQL_ThreadQuery(g_SqlTuple, "register_client", szTemp, Data, 1)
}
public register_client(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
if (FailState == TQUERY_CONNECT_FAILED)
{
log_to_file("skill_elo.txt", "Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
}
else if (FailState == TQUERY_QUERY_FAILED)
{
log_to_file("skill_elo.txt", "Load Query failed. [%d] %s", Errcode, Error)
}
new id; id = Data[0]
if (SQL_NumResults(Query) < 1)
{
new szSteamId[32]
get_user_authid(id, szSteamId, charsmax(szSteamId))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
if (equal(szSteamId, "ID_PENDING"))
return PLUGIN_HANDLED
new szTemp[512]
format(szTemp, charsmax(szTemp), "INSERT INTO `%s` (`steam`, `skill`) VALUES ('%s', '0.0')", szTable, szSteamId)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", szTemp)
g_user_skill[id][Skill] = float(get_pcvar_num(g_Cvar[1]))
}
else
{
g_user_skill[id][Skill] = Float:SQL_ReadResult(Query, 1)
}
return PLUGIN_HANDLED
}
public Save_MySql(id)
{
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
get_pcvar_string(g_Cvar[9], szTable, charsmax(szTable))
format(szTemp, charsmax(szTemp), "UPDATE `%s` SET `skill` = '%f' WHERE `%s`. `steam` = '%s'", szTable, g_user_skill[id][Skill], szTable, szSteamId)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", szTemp)
}
public IgnoreHandle(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
SQL_FreeHandle(Query)
return PLUGIN_HANDLED
}
stock get_skill_id(Float:skill)
{
for (new i, sk = floatround(skill); i < sizeof g_arrViewSkills; i++)
{
if (i && g_arrItemSkills[i] > sk)
return i - 1
else if ((!i && g_arrItemSkills[i] > sk) || i == charsmax(g_arrViewSkills))
return i
}
return 0
}
public plugin_natives()
{
register_library("skill_elo")
register_native("get_skill_name", "_get_skill_name")
register_native("get_user_skill", "_get_user_skill", 1)
register_native("set_user_skill", "_set_user_skill", 1)
}
public Float:_get_user_skill(id)
return g_user_skill[id][Skill]
public _set_user_skill(id, Float:num)
g_user_skill[id][Skill] = num
public _get_skill_name(plugin, params)
{
new id = get_param(1)
new len = get_param(3)
new Float:skill, skill_id
skill = g_user_skill[id][Skill]
skill_id = get_skill_id(skill)
new buffer[192]; format(buffer, len, "%L", LANG_SERVER, g_arrViewSkills[skill_id])
set_string(2, buffer, len)
}