Помогите поправить код: Ошибка в плагине ножей с сохранением mysql

Сообщения
6
Реакции
0
Предупреждения
1
Ошибка
L 01/13/2022 - 01:56:25: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20220113.log")
L 01/13/2022 - 01:56:25: [MySQL] No result set in this query!
L 01/13/2022 - 01:56:25: [AMXX] Displaying debug trace (plugin "hooligan_knife_manager.amxx", version "0.3")
L 01/13/2022 - 01:56:25: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 01/13/2022 - 01:56:25: [AMXX] [0] hooligan_knife_manager.sma::client_connect (line 62)
L 01/13/2022 - 01:56:25: [MySQL] No result set in this query!
L 01/13/2022 - 01:56:25: [AMXX] Displaying debug trace (plugin "hooligan_knife_manager.amxx", version "0.3")
L 01/13/2022 - 01:56:25: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 01/13/2022 - 01:56:25: [AMXX] [0] hooligan_knife_manager.sma::client_connect (line 62)
L 01/13/2022 - 01:56:25: [MySQL] No result set in this query!
L 01/13/2022 - 01:56:25: [AMXX] Displaying debug trace (plugin "hooligan_knife_manager.amxx", version "0.3")
L 01/13/2022 - 01:56:25: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 01/13/2022 - 01:56:25: [AMXX] [0] hooligan_knife_manager.sma::client_connect (line 62)
L 01/13/2022 - 01:56:26: [MySQL] No result set in this query!
L 01/13/2022 - 01:56:26: [AMXX] Displaying debug trace (plugin "hooligan_knife_manager.amxx", version "0.3")
L 01/13/2022 - 01:56:26: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 01/13/2022 - 01:56:26: [AMXX] [0] hooligan_knife_manager.sma::client_connect (line 62)
ОС
Linux
Amx Mod X
AMX Mod X 1.9.0.5294 (http://www.amxmodx.org)
Authors:
David "BAILOPAN" Anderson, Pavol "PM OnoTo" Marko
Felix "SniperBeamer" Geyer, Jonny "Got His Gun" Bergstrom
Lukasz "SidLuke" Wlasinski, Christian "Basic-Master" Hammacher
Borja "faluco" Ferrer, Scott "DS" Ehlert
Compiled: Dec 3 2021 15:54:56
Built from: https://github.com/alliedmodders/amxmodx/commit/363871a
Build ID: 5294:363871a
Core mode: JIT+ASM32
Билд
Protocol version 48
Exe version 1.1.2.7/Stdio (cstrike)
ReHLDS version: 3.11.0.767-dev
Build date: 03:13:55 Oct 25 2021 (2753)
Build from: https://github.com/dreamstalker/rehlds/commit/471158b
ReGamedll
ReGameDLL version: 5.21.0.540-dev
Build date: 17:33:16 Oct 25 2021
Build from: https://github.com/s1lentq/ReGameDLL_CS/commit/b9cccc6
Версия Metamod
Metamod-r v1.3.0.128, API (5:13)
Metamod-r build: 17:47:54 Aug 24 2018
Metamod-r from: https://github.com/theAsmodai/metamod-r/commit/0cf2f70
Список метамодулей
escription      stat pend  file                      vers             src  load  unload
[ 1] Reunion RUN - reunion.so v0.1.92d ini Start Never
[ 2] VoiceTranscoder RUN - VoiceTranscoder.so v2017RC5 ini ANY ANY
[ 3] AMX Mod X RUN - amxmodx.so v1.9.0.5294 ini Start ANY
[ 4] ReAuthCheck RUN - reauthcheck.so v0.1.6 ini Start Never
[ 5] Rechecker RUN - rechecker.so v2.7 ini Chlvl ANY
[ 6] ReSemiclip RUN - resemiclip.so v2.3.9 ini Chlvl ANY
[ 7] ReSRDetector RUN - resrdetector.so v0.1.0 ini Chlvl ANY
[ 8] SafeNameAndChat RUN - SafeNameAndChat.so v1.1 ini ANY ANY
[ 9] WHBlocker RUN - whblocker.so v1.5.697 ini Chlvl ANY
[10] YaPB RUN - yapb.so v4.2.598 ini Chlvl ANY
[11] CStrike RUN - cstrike_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
[12] CSX RUN - csx_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
[13] MySQL RUN - mysql_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
[14] SQLite RUN - sqlite_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
[15] ReAPI RUN - reapi_amxx_i386.so v5.21.0.248-dev pl3 ANY Never
[16] FakeMeta RUN - fakemeta_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
[17] Ham Sandwich RUN - hamsandwich_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
[18] Fun RUN - fun_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
[19] Engine RUN - engine_amxx_i386.so v1.9.0.5294 pl3 ANY ANY
19 plugins, 19 running
Список плагинов
[  1] GameCMS_GagManager      2.2.7 ReAp  zhorzh78          gamecms_gagmana  running
[ 2] GameCMS_API 5.5.3 zhorzh78 gamecms_api.amx running
[ 3] CSStatsX SQL 0.7.4+2 serfreeman1337 aes_csstatsx_sq running
[ 4] WebHS 0.1 kanagava fb_web_online.a running
[ 5] FreshBans 1.4.5b kanagava fresh_bans.amxx running
[ 6] Admin Commands 1.9.0.5294 AMXX Dev Team admincmd.amxx running
[ 7] Slots Reservation 1.9.0.5294 AMXX Dev Team adminslots.amxx running
[ 8] Menus Front-End 1.9.0.5294 AMXX Dev Team menufront.amxx running
[ 9] Commands Menu 1.9.0.5294 AMXX Dev Team cmdmenu.amxx running
[ 10] Players Menu 1.9.0.5271 AMXX Dev Team plmenu.amxx running
[ 11] Maps Menu 1.0 O.Hooligan mapsmenu.amxx running
[ 12] Plugin Menu 1.9.0.5294 AMXX Dev Team pluginmenu.amxx running
[ 13] Admin Chat 1.9.0.5294 AMXX Dev Team adminchat.amxx running
[ 14] Scrolling Message 1.9.0.5294 AMXX Dev Team scrollmsg.amxx running
[ 15] Info. Messages 1.9.0.5294 AMXX Dev Team imessage.amxx running
[ 16] Admin Votes 1.9.0.5294 AMXX Dev Team adminvote.amxx running
[ 17] TimeLeft 1.9.0.5294 AMXX Dev Team timeleft.amxx running
[ 18] Pause Plugins 1.9.0.5294 AMXX Dev Team pausecfg.amxx running
[ 19] Stats Configuration 1.9.0.5294 AMXX Dev Team statscfg.amxx running
[ 20] AES: StatsX 0.5.9 [REA serfreeman1337/s aes_statsx.amxx running
[ 21] StatsX 1.9.0.5294 AMXX Dev Team statsx.amxx running
[ 22] GameCMS_VipTest 3.8.1 zhorzh78 gamecms_viptest running
[ 23] GameCMS BonusSystem 1.1 +- DUKKHAZ0R gamecms_bonus.a running
[ 24] [GameCMS] Real Money R 1.0 InKay gamecms_bets.am running
[ 25] Hooligan VoteBan 1.4 O.Hooligan hooligan_voteba running
[ 26] Kill Assist 1.17 O.Hooligan hooligan_kill_a running
[ 27] Hooligan Vampire 1.2 O.Hooligan hooligan_vampir running
[ 28] Ping Control 1.31 O.Hooligan hooligan_ping.a running
[ 29] Lite Translit 2.8 neygomon hooligan_transl running
[ 30] Knife Duel 1.2 O.Hooligan hooligan_duel.a running
[ 31] Nice Voice 2.0 R sector hooligan_voice. running
[ 32] Advanced MapChooser 1.1.1 O.Hooligan hooligan_map_ch running
[ 33] VIP 1.5 O.Hooligan hooligan_vipmen running
[ 34] Menu 1.0 O.Hooligan hooligan_menu.a running
[ 35] Menu 1.0 O.Hooligan hooligan_cabine running
[ 36] Menu 1.0 O.Hooligan hooligan_menupr running
[ 37] AmxModMenu 1.2 O.Hooligan hooligan_adminm running
[ 38] Knife Manager 0.3 O.Hooligan hooligan_knife_ running
[ 39] unknown unknown unknown hooligan_teamba bad load
[ 40] Warn Menu 0.1 O.Hooligan hooligan_warn_m running
[ 41] GreetingMenu 1.0 O.Hooligan hooligan_ng.amx running
[ 42] Random Weapons WarmUP 2.4.1 O.Hooligan hooligan_razmin running
[ 43] Damager 0.0.5 steelzzz hooligan_damage running
[ 44] Free ammo 1.4 O.Hooligan hooligan_ammo.a running
[ 45] coin 1.0 O.Hooligan hooligan_coin.a running
[ 46] Flags 1.1 O.Hooligan hooligan_flags. running
[ 47] CMS_GM_Sorry_Addon 1.0 sorry.amxx running
[ 48] Reset Score 0.2 Silenttt / CepeH rs.amxx running
[ 49] Parachute 1.0 maeStro parachute.amxx running
[ 50] lite screen fade 1.0 AcE lite_screen_fad running
[ 51] kill_knife_money 1.0 IntelCom knife_kill_mone running
[ 52] [ReAPI] Healthnade 0.0.2 [email protected] reapi_healthnad running
[ 53] Killa HP 1.6 jas0n killa_hp.amxx running
[ 54] User Connect 0.1.1 Jumper connect_priv.am running
[ 55] Ultimate KillStreak Ad 0.7 SAMURAI ut_killstreak_a running
[ 56] [190] AC Spectator ESP 20.06.06 SKAJIbnEJIb & Ko ac_esp.amxx running
[ 57] Autoresponder/Advertis 0.5 MaximusBrood reklama_in_chat running
[ 58] Block Name Spam 0.1 s1lent block_name_spam running
[ 59] XMAS Skybox 1.0 SeMax xmas_sky.amxx running
[ 60] [ReAPI] AWPoff 1.4.3 PAffAEJIkA :3 awp_off.amxx running
[ 61] [ReAPI] No Team Flash 0.0.2 Vaqtincha no_team_flash.a running
[ 62] Afk Control 0.5.1 neygomon afk_control.amx running
[ 63] AES: StatsX Info Rank 0.1 serfreeman1337 aes_statsx_info running
[ 64] AES: Status Info 0.1 serfreeman1337 aes_status_info running
[ 65] DemoRecoder 1.1 neygomon demka.amxx running
[ 66] SITE 1.0 O.Hooligan site.amxx running
[ 67] Block grande info 1.0 O.Hooligan BlockGrenadeInf running
[ 68] Top Round Damage 1.0.4 ReAP Dager* *.* -G- top_damage.amxx running
[ 69] [ReAPI] Custom Models 1.6.1 neugomon custom_models.a running
[ 70] Santa Hat + Snow 1.3 xPaw SantaHat.amxx running
[ 71] CSS Bomb 0.0.1 Vaqtincha c4_ng.amxx running
[ 72] NY Kill Sprite 1.0 O.Hooligan ng_sprite.amxx running
[ 73] Advanced Experience Sy 0.5.9 [REA serfreeman1337/s aes_main.amxx running
[ 74] AES: CStrike Addon 0.5.9 [REA serfreeman1337/s aes_exp_cstrike running
[ 75] AES: Informer 0.5 Vega serfreeman1337 aes_informer.am running
[ 76] AES: Admin Tools 0.5.9 [REA serfreeman1337/s aes_exp_editor. running
[ 77] AES: Bonus System 0.5.9 Vega serfreeman1337/s aes_bonus_syste running
[ 78] AES: Bonus CSTRIKE 0.5.9.1 [R serfreeman1337/s aes_bonus_cstri running
78 plugins, 77 running
Автор плагина
Моя доработка
Версия плагина
0.3
Исходный код
#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <sqlx>
#define INFO_CHAT

//const MAX_PLAYERS = 32;
const MAX_NUMBER_PAGE = 8;
new Array:g_aKnifes;
new g_iKnifesSize;
new g_iUserKnife[MAX_PLAYERS];
new g_iMenuPosition[MAX_PLAYERS];
new MODEL_V1[128];
new MODEL_P1[128];
new g_EmptyUser[33];
new g_EmptyUserChange[33];

enum _:DATA_LOAD
{
KNIFE_NAME[64],
KNIFE_MODEL_V[128],
KNIFE_MODEL_P[128],
KNIFE_FLAG[2]
};
new Handle:SQL_Tuple
new Handle:SQL_Connection
public plugin_init(){
register_plugin("Knife Manager","0.3","O.Hooligan");
register_clcmd("say /knife","Cmd_KnifeMenu");
RegisterHam(Ham_Item_Deploy, "weapon_knife", "Ham_KnifeDeploy", true);
register_menucmd(register_menuid("Open_KnifeMenu"), 1023, "Close_KnifeMenu");

register_cvar("SQLx_host","127.0.0.1")
register_cvar("SQLx_db","game")
register_cvar("SQLx_user","eglee")
register_cvar("SQLx_password","1w3r5y7i")
}
public plugin_cfg(){
new host[33],dbase[33],user[33],pass[33]
get_cvar_string("SQLx_host",host,30)
get_cvar_string("SQLx_db",dbase,30)
get_cvar_string("SQLx_user",user,30)
get_cvar_string("SQLx_password",pass,30)
SQL_Tuple = SQL_MakeDbTuple(host,user,pass,dbase)
new err, error[256];
SQL_Connection = SQL_Connect(SQL_Tuple, err, error, charsmax(error))
if(SQL_Connection != Empty_Handle)
{
log_amx("[SQLx connect ok]") //Если соединение установлено
}else{
log_amx("[SQLX sql error] %s ",error) //Если нет и выводим причину(ошибку)
pause("a")
}
}
public client_connect(id)
{
new steam[32];
get_user_authid(id, steam, 31)
new Handle:Query = SQL_PrepareQuery(SQL_Connection,"SELECT * FROM `knife_manager` WHERE steamid = '%s'",steam)
SQL_Execute (Query)
if( SQL_NumResults(Query) > 0 )
SQL_ReadResult(Query, 2, MODEL_V1, 31)
SQL_ReadResult(Query, 3, MODEL_P1, 31)
{
g_EmptyUser[id] = 1
}
}
public plugin_precache() LOADING_INI();

LOADING_INI(){
new szCfgDir[64], szCfgFile[128];
get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir));

formatex(szCfgFile, charsmax(szCfgFile), "%s/knife_manager.ini", szCfgDir);
if(!file_exists(szCfgFile))
{
write_file(szCfgFile, ";# Файл менеджера ножей: knife_manager.ini");
write_file(szCfgFile, ";# (c) O.Hooligan 2021");
write_file(szCfgFile, ";#");
write_file(szCfgFile, ";# Пример добавления ножа");
write_file(szCfgFile, ";# ^"Название в меню^" ^"Модель V^" ^"Модель P^" ^"Флаг доступа^"");
write_file(szCfgFile, ";#");
write_file(szCfgFile, ";# Список ножей");
write_file(szCfgFile, "^"Стандартный^" ^"models/v_knife.mdl^" ^"models/p_knife.mdl^" ^"^"");
}
new GetArrayDataRead[DATA_LOAD], szBuffer[256], iLine, iLen;
g_aKnifes = ArrayCreate(DATA_LOAD);
while(read_file(szCfgFile, iLine++, szBuffer, charsmax(szBuffer), iLen))
{
if(!iLen || szBuffer[0] == ';') continue;
parse
(
szBuffer,
GetArrayDataRead[KNIFE_NAME], charsmax(GetArrayDataRead[KNIFE_NAME]),
GetArrayDataRead[KNIFE_MODEL_V], charsmax(GetArrayDataRead[KNIFE_MODEL_V]),
GetArrayDataRead[KNIFE_MODEL_P], charsmax(GetArrayDataRead[KNIFE_MODEL_P]),
GetArrayDataRead[KNIFE_FLAG], charsmax(GetArrayDataRead[KNIFE_FLAG])
);
engfunc(EngFunc_PrecacheModel, GetArrayDataRead[KNIFE_MODEL_V]);
engfunc(EngFunc_PrecacheModel, GetArrayDataRead[KNIFE_MODEL_P]);
ArrayPushArray(g_aKnifes, GetArrayDataRead);
}
g_iKnifesSize = ArraySize(g_aKnifes);
}

public Cmd_KnifeMenu(id) return Open_KnifeMenu(id,g_iMenuPosition[id] = 0);
Open_KnifeMenu(id, iPos)
{
if(iPos < 0) return PLUGIN_HANDLED;
new iStart = iPos * MAX_NUMBER_PAGE;
if(iStart > g_iKnifesSize) iStart = g_iKnifesSize;
iStart = iStart - (iStart % MAX_NUMBER_PAGE);
g_iMenuPosition[id] = iStart / MAX_NUMBER_PAGE;
new iEnd = iStart + MAX_NUMBER_PAGE;
if(iEnd > g_iKnifesSize) iEnd = g_iKnifesSize;
new szMenu[512], iLen, iPagesNum = (g_iKnifesSize / MAX_NUMBER_PAGE + ((g_iKnifesSize % MAX_NUMBER_PAGE) ? 1 : 0));
new iBitKeys = (1<<9), b;
iLen = formatex(szMenu, charsmax(szMenu), "\wВыбор ножа \r[%d|%d]^n^n", iPos + 1, iPagesNum);

for(new a = iStart; a < iEnd; a++)
{
new GetArrayData[DATA_LOAD];
ArrayGetArray(g_aKnifes, a, GetArrayData);

if(GetArrayData[KNIFE_FLAG]){
if(get_user_flags(id) & read_flags(GetArrayData[KNIFE_FLAG])){
if(g_iUserKnife[id] != a){
iBitKeys |= (1<<b);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r[\w%d\r] \w%s^n", ++b, GetArrayData[KNIFE_NAME]);

}else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\rNO\d] %s^n", GetArrayData[KNIFE_NAME]), ++b;
}else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\rNO\d] %s \r[Нет прав]^n", GetArrayData[KNIFE_NAME]), ++b;
}else{
if(g_iUserKnife[id] != a){
iBitKeys |= (1<<b);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r[\w%d\r] \w%s^n", ++b, GetArrayData[KNIFE_NAME]);
}else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\rNO\d] %s^n", GetArrayData[KNIFE_NAME]), ++b;
}
}
for(new i = b; i < MAX_NUMBER_PAGE; i++) iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n");
if(iEnd < g_iKnifesSize)
{
iBitKeys |= (1<<8);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r[\w9\r] \wДальше^n\r[\w0\r] \w%s", iPos ? "Назад" : "Выход");
}
else formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\r[\w0\r] \w%s", iPos ? "Назад" : "Выход");
return show_menu(id, iBitKeys, szMenu, -1, "Open_KnifeMenu");
}

public Close_KnifeMenu(id, iKey)
{
switch(iKey)
{
case 8: return Open_KnifeMenu(id, ++g_iMenuPosition[id]);
case 9: return Open_KnifeMenu(id, --g_iMenuPosition[id]);
default:
{
new GetArrayData[DATA_LOAD];
static iSelect; iSelect = g_iMenuPosition[id] * MAX_NUMBER_PAGE + iKey;
ArrayGetArray(g_aKnifes, iSelect, GetArrayData);

g_iUserKnife[id] = iSelect;
engclient_cmd(id, "weapon_knife");
static iActiveItem; iActiveItem = get_pdata_cbase(id, 373, 5);
if(iActiveItem > 0)

#if defined INFO_CHAT
replace_all(GetArrayData[KNIFE_NAME], charsmax(GetArrayData[KNIFE_NAME]), "\r", "");
replace_all(GetArrayData[KNIFE_NAME], charsmax(GetArrayData[KNIFE_NAME]), "\w", "");
replace_all(GetArrayData[KNIFE_NAME], charsmax(GetArrayData[KNIFE_NAME]), "\y", "");
chat(id,"!g[Сервер] !yВы взяли: %s!", GetArrayData[KNIFE_NAME]);
client_cmd(id, "say /knife","Cmd_KnifeMenu");
new steam[32];
get_user_authid(id, steam, 31)
new Handle:Query = SQL_PrepareQuery(SQL_Connection,"SELECT * FROM `knife_manager` WHERE steamid = '%s'",steam)
SQL_Execute (Query)
if( SQL_NumResults(Query) > 0 )
{
SQL_ReadResult(Query, 2, MODEL_V1, 31)
SQL_ReadResult(Query, 3, MODEL_P1, 31)
new query[256],data[2];
format(query,charsmax(query),"UPDATE `knife_manager` SET `steamid`='%s',`v_model`='%s',`p_model`='%s' WHERE steamid = '%s'",steam,GetArrayData[KNIFE_MODEL_V],GetArrayData[KNIFE_MODEL_P],steam);
SQL_ThreadQuery(SQL_Tuple,"QueryHandler",query,data,charsmax(data))
g_EmptyUserChange[id] = 1
ExecuteHamB(Ham_Item_Deploy, iActiveItem);



}
else
{

new query[256],data[2];
format(query,charsmax(query),"INSERT INTO `knife_manager`(`steamid`, `v_model`, `p_model`) VALUES ('%s','%s','%s')",steam,GetArrayData[KNIFE_MODEL_V],GetArrayData[KNIFE_MODEL_P]);
SQL_ThreadQuery(SQL_Tuple,"QueryHandler",query,data,charsmax(data))
g_EmptyUserChange[id] = 1
ExecuteHamB(Ham_Item_Deploy, iActiveItem);


}

ExecuteHamB(Ham_Item_Deploy, iActiveItem);


#endif
}
}
return PLUGIN_HANDLED;
}

public Ham_KnifeDeploy(iEntity)
{
new steam[32];
static id; id = get_pdata_cbase(iEntity, 41, 4)
get_user_authid(id, steam, 31)
static id2; id2 = get_pdata_cbase(iEntity, 41, 4)
if(g_EmptyUserChange[id] > 0){
new GetArrayData[DATA_LOAD];
ArrayGetArray(g_aKnifes, g_iUserKnife[id], GetArrayData);
set_pev(id, pev_viewmodel2, GetArrayData[KNIFE_MODEL_V]);
set_pev(id, pev_weaponmodel2, GetArrayData[KNIFE_MODEL_P]);
}else{
if(g_EmptyUser[id] > 0){
set_pev(id2, pev_viewmodel2, MODEL_V1)
set_pev(id2, pev_weaponmodel2, MODEL_P1)
}
else{
new GetArrayData[DATA_LOAD];
ArrayGetArray(g_aKnifes, g_iUserKnife[id], GetArrayData);
set_pev(id, pev_viewmodel2, GetArrayData[KNIFE_MODEL_V]);
set_pev(id, pev_weaponmodel2, GetArrayData[KNIFE_MODEL_P]);
}
}
return HAM_IGNORED;
}
#if defined INFO_CHAT
stock chat(pPlayer, const szMessage[], any:...){
new szBuffer[190];
if(numargs() > 2) vformat(szBuffer, charsmax(szBuffer), szMessage, 3);
else copy(szBuffer, charsmax(szBuffer), szMessage);
while(replace(szBuffer, charsmax(szBuffer), "!y", "^1")) {}
while(replace(szBuffer, charsmax(szBuffer), "!t", "^3")) {}
while(replace(szBuffer, charsmax(szBuffer), "!g", "^4")) {}
switch(pPlayer)
{
case 0:
{
for(new iPlayer = 1; iPlayer <= get_maxplayers(); iPlayer++)
{
if(!is_user_connected(iPlayer)) continue;
engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, 76, {0.0, 0.0, 0.0}, iPlayer);
write_byte(iPlayer);
write_string(szBuffer);
message_end();
}
}
default:
{
engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, 76, {0.0, 0.0, 0.0}, pPlayer);
write_byte(pPlayer);
write_string(szBuffer);
message_end();
}
}
}
#endif

public QueryHandler(FailState, Handle:Query, error[], err, data[], size, Float:querytime){

if(FailState != TQUERY_SUCCESS)
{
log_amx("sql error: %d (%s)", err, error)
return

}



}
public plugin_end(){
SQL_FreeHandle(SQL_Connection)
}
public client_disconnected(id){

}
Помогите исправить сделал сохранение в базу данных, в консоле когда кто то заходит эту ошибку выдаёт
 
В этой теме было размещено решение! Перейти к решению.
Последнее редактирование:
Сообщения
310
Реакции
103
Помог
8 раз(а)
Код конечно ужасный, чекай, и да, лучше используй асинхронный запрос


MODEL_V1 и MODEL_P1 не индексирован, один модель на всех?


Код:
#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <sqlx>
#define INFO_CHAT

//const MAX_PLAYERS = 32;
const MAX_NUMBER_PAGE = 8;
new Array:g_aKnifes;
new g_iKnifesSize;
new g_iUserKnife[MAX_PLAYERS];
new g_iMenuPosition[MAX_PLAYERS];
new MODEL_V1[33][128];
new MODEL_P1[33][128];
new g_EmptyUser[33];
new g_EmptyUserChange[33];

enum _:DATA_LOAD
{
    KNIFE_NAME[64],
    KNIFE_MODEL_V[128],
    KNIFE_MODEL_P[128],
    KNIFE_FLAG[2]
};
new Handle:SQL_Tuple
new Handle:SQL_Connection
public plugin_init(){
    register_plugin("Knife Manager","0.3","O.Hooligan");
    register_clcmd("say /knife","Cmd_KnifeMenu");
    RegisterHam(Ham_Item_Deploy, "weapon_knife", "Ham_KnifeDeploy", true);
    register_menucmd(register_menuid("Open_KnifeMenu"), 1023, "Close_KnifeMenu");
 
    register_cvar("SQLx_host","127.0.0.1")
    register_cvar("SQLx_db","game")
    register_cvar("SQLx_user","eglee")
    register_cvar("SQLx_password","1w3r5y7i")
}
public plugin_cfg(){
    new host[33],dbase[33],user[33],pass[33]
    get_cvar_string("SQLx_host",host,30)
    get_cvar_string("SQLx_db",dbase,30)
    get_cvar_string("SQLx_user",user,30)
    get_cvar_string("SQLx_password",pass,30)
    SQL_Tuple = SQL_MakeDbTuple(host,user,pass,dbase)
    new err, error[256];
    SQL_Connection = SQL_Connect(SQL_Tuple, err, error, charsmax(error))
    if(SQL_Connection != Empty_Handle)
    {
        log_amx("[SQLx connect ok]") //Если соединение установлено
    }else{
        log_amx("[SQLX sql error] %s ",error) //Если нет и выводим причину(ошибку)
        pause("a")
    }
}
public client_putinserver(id)
{
    new steam[32];
    get_user_authid(id, steam, charsmax(steam))
    new Handle:Query = SQL_PrepareQuery(SQL_Connection,"SELECT * FROM `knife_manager` WHERE steamid = '%s'",steam)
    if(!SQL_Execute(Query))
    {
        new Error[128]
        SQL_QueryError(Query, Error, charsmax(Error))
        log_to_file("mysqlt.log", "[DB_Create_Table]  %s", Error);
        SQL_FreeHandle(Query)
        return ;
    }
    if( SQL_NumResults(Query) > 0 )
    {
        SQL_ReadResult(Query, 2, MODEL_V1[id], charsmax(MODEL_V1[]))
        SQL_ReadResult(Query, 3, MODEL_P1[id], charsmax(MODEL_P1[]))
     
        if(checkin_model(id, MODEL_V1[id], MODEL_P1[id]))
            g_EmptyUser[id] = 1
     
    }
    SQL_FreeHandle(Query)
}
public plugin_precache() LOADING_INI();

LOADING_INI(){
    new szCfgDir[64], szCfgFile[128];
    get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir));

    formatex(szCfgFile, charsmax(szCfgFile), "%s/knife_manager.ini", szCfgDir);
    if(!file_exists(szCfgFile))
    {
        write_file(szCfgFile, ";# Файл менеджера ножей: knife_manager.ini");
        write_file(szCfgFile, ";#    (c) O.Hooligan 2021");
        write_file(szCfgFile, ";#");
        write_file(szCfgFile, ";# Пример добавления ножа");
        write_file(szCfgFile, ";# ^"Название в меню^" ^"Модель V^" ^"Модель P^" ^"Флаг доступа^"");
        write_file(szCfgFile, ";#");
        write_file(szCfgFile, ";# Список ножей");
        write_file(szCfgFile, "^"Стандартный^" ^"models/v_knife.mdl^" ^"models/p_knife.mdl^" ^"^"");
    }
    new GetArrayDataRead[DATA_LOAD], szBuffer[256], iLine, iLen;
    g_aKnifes = ArrayCreate(DATA_LOAD);
    while(read_file(szCfgFile, iLine++, szBuffer, charsmax(szBuffer), iLen))
    {
        if(!iLen || szBuffer[0] == ';') continue;
        parse
        (
        szBuffer,
        GetArrayDataRead[KNIFE_NAME],             charsmax(GetArrayDataRead[KNIFE_NAME]),
        GetArrayDataRead[KNIFE_MODEL_V],         charsmax(GetArrayDataRead[KNIFE_MODEL_V]),
        GetArrayDataRead[KNIFE_MODEL_P],        charsmax(GetArrayDataRead[KNIFE_MODEL_P]),
        GetArrayDataRead[KNIFE_FLAG],            charsmax(GetArrayDataRead[KNIFE_FLAG])
        );
        engfunc(EngFunc_PrecacheModel, GetArrayDataRead[KNIFE_MODEL_V]);
        engfunc(EngFunc_PrecacheModel, GetArrayDataRead[KNIFE_MODEL_P]);
        ArrayPushArray(g_aKnifes, GetArrayDataRead);
    }
    g_iKnifesSize = ArraySize(g_aKnifes);
}

public Cmd_KnifeMenu(id) return Open_KnifeMenu(id,g_iMenuPosition[id] = 0);
Open_KnifeMenu(id, iPos)
{
    if(iPos < 0) return PLUGIN_HANDLED;
    new iStart = iPos * MAX_NUMBER_PAGE;
    if(iStart > g_iKnifesSize) iStart = g_iKnifesSize;
    iStart = iStart - (iStart % MAX_NUMBER_PAGE);
    g_iMenuPosition[id] = iStart / MAX_NUMBER_PAGE;
    new iEnd = iStart + MAX_NUMBER_PAGE;
    if(iEnd > g_iKnifesSize) iEnd = g_iKnifesSize;
    new szMenu[512], iLen, iPagesNum = (g_iKnifesSize / MAX_NUMBER_PAGE + ((g_iKnifesSize % MAX_NUMBER_PAGE) ? 1 : 0));
    new iBitKeys = (1<<9), b;
    iLen = formatex(szMenu, charsmax(szMenu), "\wВыбор ножа \r[%d|%d]^n^n", iPos + 1, iPagesNum);
 
    for(new a = iStart; a < iEnd; a++)
    {
        new GetArrayData[DATA_LOAD];
        ArrayGetArray(g_aKnifes, a, GetArrayData);

        if(GetArrayData[KNIFE_FLAG]){
            if(get_user_flags(id) & read_flags(GetArrayData[KNIFE_FLAG])){
                if(g_iUserKnife[id] != a){
                    iBitKeys |= (1<<b);
                    iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r[\w%d\r] \w%s^n", ++b, GetArrayData[KNIFE_NAME]);
                 
                }else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\rNO\d] %s^n", GetArrayData[KNIFE_NAME]), ++b;
            }else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\rNO\d] %s \r[Нет прав]^n", GetArrayData[KNIFE_NAME]), ++b;
        }else{
            if(g_iUserKnife[id] != a){
                iBitKeys |= (1<<b);
                iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r[\w%d\r] \w%s^n", ++b, GetArrayData[KNIFE_NAME]);
            }else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\rNO\d] %s^n", GetArrayData[KNIFE_NAME]), ++b;
        }
    }
    for(new i = b; i < MAX_NUMBER_PAGE; i++) iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n");
    if(iEnd < g_iKnifesSize)
    {
        iBitKeys |= (1<<8);
        formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\r[\w9\r] \wДальше^n\r[\w0\r] \w%s", iPos ? "Назад" : "Выход");
    }
    else formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\r[\w0\r] \w%s", iPos ? "Назад" : "Выход");
    return show_menu(id, iBitKeys, szMenu, -1, "Open_KnifeMenu");
}

public Close_KnifeMenu(id, iKey)
{
    switch(iKey)
    {
    case 8: return Open_KnifeMenu(id, ++g_iMenuPosition[id]);
    case 9: return Open_KnifeMenu(id, --g_iMenuPosition[id]);
    default:
        {
            new GetArrayData[DATA_LOAD];
            static iSelect; iSelect = g_iMenuPosition[id] * MAX_NUMBER_PAGE + iKey;
            ArrayGetArray(g_aKnifes, iSelect, GetArrayData);
         
            g_iUserKnife[id] = iSelect;
            engclient_cmd(id, "weapon_knife");
            static iActiveItem; iActiveItem = get_pdata_cbase(id, 373, 5);
            if(iActiveItem > 0)
         
#if defined INFO_CHAT
            replace_all(GetArrayData[KNIFE_NAME], charsmax(GetArrayData[KNIFE_NAME]), "\r", "");
            replace_all(GetArrayData[KNIFE_NAME], charsmax(GetArrayData[KNIFE_NAME]), "\w", "");
            replace_all(GetArrayData[KNIFE_NAME], charsmax(GetArrayData[KNIFE_NAME]), "\y", "");
            chat(id,"!g[Сервер] !yВы взяли: %s!", GetArrayData[KNIFE_NAME]);
            client_cmd(id, "say /knife","Cmd_KnifeMenu");
            new steam[32];
            get_user_authid(id, steam, 31)
            new Handle:Query = SQL_PrepareQuery(SQL_Connection,"SELECT * FROM `knife_manager` WHERE steamid = '%s'",steam)
            if(!SQL_Execute(Query))
            {
                new Error[128]
                SQL_QueryError(Query, Error, charsmax(Error))
                log_to_file("mysqlt.log", "[DB_Create_Table]  %s", Error);
                SQL_FreeHandle(Query)
                return PLUGIN_HANDLED;
            }
            if( SQL_NumResults(Query) > 0 )
            {
                SQL_ReadResult(Query, 2, MODEL_V1[id], charsmax(MODEL_V1[]))
                SQL_ReadResult(Query, 3, MODEL_P1[id], charsmax(MODEL_P1[]))
                new query[256],data[2];
                format(query,charsmax(query),"UPDATE `knife_manager` SET `steamid`='%s',`v_model`='%s',`p_model`='%s' WHERE steamid = '%s'",steam,GetArrayData[KNIFE_MODEL_V],GetArrayData[KNIFE_MODEL_P],steam);
                SQL_ThreadQuery(SQL_Tuple,"QueryHandler",query,data,charsmax(data))
                g_EmptyUserChange[id] = 1
                ExecuteHamB(Ham_Item_Deploy, iActiveItem);

            }
            else
            {
             
                new query[256],data[2];
                format(query,charsmax(query),"INSERT INTO `knife_manager`(`steamid`, `v_model`, `p_model`) VALUES ('%s','%s','%s')",steam,GetArrayData[KNIFE_MODEL_V],GetArrayData[KNIFE_MODEL_P]);
                SQL_ThreadQuery(SQL_Tuple,"QueryHandler",query,data,charsmax(data))
                g_EmptyUserChange[id] = 1
                ExecuteHamB(Ham_Item_Deploy, iActiveItem);
            }
            SQL_FreeHandle(Query)
            ExecuteHamB(Ham_Item_Deploy, iActiveItem);
         

#endif
        }
    }
    return PLUGIN_HANDLED;
}

public Ham_KnifeDeploy(iEntity)
{
    new steam[32];
    static id; id = get_pdata_cbase(iEntity, 41, 4)
    get_user_authid(id, steam, 31)
    static id2; id2 = get_pdata_cbase(iEntity, 41, 4)
    if(g_EmptyUserChange[id] > 0){
        new GetArrayData[DATA_LOAD];
        ArrayGetArray(g_aKnifes, g_iUserKnife[id], GetArrayData);
        set_pev(id, pev_viewmodel2, GetArrayData[KNIFE_MODEL_V]);
        set_pev(id, pev_weaponmodel2, GetArrayData[KNIFE_MODEL_P]);
    }else{
     
        if(g_EmptyUser[id] > 0){
            set_pev(id2, pev_viewmodel2, MODEL_V1[id])
            set_pev(id2, pev_weaponmodel2, MODEL_P1[id])
        }
        else{
            new GetArrayData[DATA_LOAD];
            ArrayGetArray(g_aKnifes, g_iUserKnife[id], GetArrayData);
            set_pev(id, pev_viewmodel2, GetArrayData[KNIFE_MODEL_V]);
            set_pev(id, pev_weaponmodel2, GetArrayData[KNIFE_MODEL_P]);
        }
    }
    return HAM_IGNORED;
}
#if defined INFO_CHAT
stock chat(pPlayer, const szMessage[], any:...){
    new szBuffer[190];
    if(numargs() > 2) vformat(szBuffer, charsmax(szBuffer), szMessage, 3);
    else copy(szBuffer, charsmax(szBuffer), szMessage);
    while(replace(szBuffer, charsmax(szBuffer), "!y", "^1")) {}
    while(replace(szBuffer, charsmax(szBuffer), "!t", "^3")) {}
    while(replace(szBuffer, charsmax(szBuffer), "!g", "^4")) {}
    switch(pPlayer)
    {
    case 0:
        {
            for(new iPlayer = 1; iPlayer <= get_maxplayers(); iPlayer++)
            {
                if(!is_user_connected(iPlayer)) continue;
                engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, 76, {0.0, 0.0, 0.0}, iPlayer);
                write_byte(iPlayer);
                write_string(szBuffer);
                message_end();                      
            }
        }
    default:
        {
            engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, 76, {0.0, 0.0, 0.0}, pPlayer);
            write_byte(pPlayer);
            write_string(szBuffer);
            message_end();
        }
    }
}
#endif

public QueryHandler(FailState, Handle:Query, error[], err, data[], size, Float:querytime){

    if(FailState != TQUERY_SUCCESS)
    {
        log_amx("sql error: %d (%s)", err, error)
        return
     
    }
 

 
}
public plugin_end(){
    SQL_FreeHandle(SQL_Connection)  
}
public client_disconnected(id){
 
}

stock checkin_model(id, V_MODEL[], P_MODEL[])
{
    #pragma unused id
    new GetArrayData[DATA_LOAD];
    for(new i; i < ArraySize(g_aKnifes); i++)
    {
        ArrayGetArray(g_aKnifes, i, GetArrayData);
   
        if(equal(V_MODEL, GetArrayData[KNIFE_MODEL_V]) && equal(P_MODEL, GetArrayData[KNIFE_MODEL_P]))
            return true;
    }
    return false;
}
Также Данный тип реализации сохранения в БД не целесобразно, если в .ini удалите модель, то вы получите краш сервера из-за не прикешнутого моделя

попробуй с этой проверкой
Код:
stock checkin_model(id, V_MODEL[], P_MODEL[])
{
    #pragma unused id
    new GetArrayData[DATA_LOAD];
    for(new i; i < ArraySize(g_aKnifes); i++)
    {
        ArrayGetArray(g_aKnifes, i, GetArrayData);
   
        if(equal(V_MODEL, GetArrayData[KNIFE_MODEL_V]) && equal(P_MODEL, GetArrayData[KNIFE_MODEL_P]))
            return true;
    }
    return false;
}

имхо лучше хранить в БД индекс Array (g_aKnifes)
 
Последнее редактирование:
Сообщения
6
Реакции
0
Предупреждения
1
Limbooc, Работает но после смены карты в меню пишет стандартный тпи выбран а сама модель со старой карты как сделать чтоб присмены карты перезаходе в меню писало нож который выбрал
 
Сообщения
330
Реакции
169
Помог
3 раз(а)
Nezox2828, зачем для такой задачи дергать базу? Сохранение можно сделать и через nvault и через setinfo если вы его не юзаете в плагинах
 
Сообщения
310
Реакции
103
Помог
8 раз(а)
Limbooc, Работает но после смены карты в меню пишет стандартный тпи выбран а сама модель со старой карты как сделать чтоб присмены карты перезаходе в меню писало нож который выбрал
может быть вы потому сохранили модель ножа а не выбранного ножа?
 
Сообщения
6
Реакции
0
Предупреждения
1
Limbooc, можешь подсказать как сделать чтоб сохранялся и выбранный нож
14 Янв 2022
maFFyoZZyk, с nvault не шарю, и не хотелось искать код в инете чтоб сделать решил через базу
 
Сообщения
310
Реакции
103
Помог
8 раз(а)
Limbooc, можешь подсказать как сделать чтоб сохранялся и выбранный нож
14 Янв 2022
для начало пересоздай таблицу БД;
Код:
CREATE TABLE `knife_manager` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `steamid` VARCHAR(35) NULL DEFAULT NULL,
    `knife_id` INT(11) NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
)
ENGINE=InnoDB
;
меняешь запросы;
Код:
if( SQL_NumResults(Query) > 0 )
{
    g_iUserKnife[id] = SQL_ReadResult(query, SQL_FieldNameToNum(query,"knife_id"));
    new query[256],data[2];
    format(query,charsmax(query),"UPDATE `knife_manager` SET `knife_id` = '%d' WHERE steamid = '%s'",g_iUserKnife[id], steam);
    SQL_ThreadQuery(SQL_Tuple,"QueryHandler",query,data,charsmax(data))
    g_EmptyUserChange[id] = 1
    ExecuteHamB(Ham_Item_Deploy, iActiveItem);
}
else
{   
    new query[256],data[2];
    format(query,charsmax(query),"INSERT INTO `knife_manager`(`steamid`, `knife_id`) VALUES ('%s','%d')",steam, g_iUserKnife[id],);
    SQL_ThreadQuery(SQL_Tuple,"QueryHandler",query,data,charsmax(data))
    g_EmptyUserChange[id] = 1
    ExecuteHamB(Ham_Item_Deploy, iActiveItem);
}
и при коннекте
Код:
public client_putinserver(id)
{
    new steam[32];
    get_user_authid(id, steam, charsmax(steam))
    new Handle:Query = SQL_PrepareQuery(SQL_Connection,"SELECT * FROM `knife_manager` WHERE steamid = '%s'",steam)
    if(!SQL_Execute(Query))
    {
        new Error[128]
        SQL_QueryError(Query, Error, charsmax(Error))
        log_to_file("mysqlt.log", "[DB_Create_Table]  %s", Error);
        SQL_FreeHandle(Query)
        return ;
    }
    if( SQL_NumResults(Query) > 0 )
    {
        g_iUserKnife[id] = SQL_ReadResult(query, SQL_FieldNameToNum(query,"knife_id"));
    
        g_EmptyUser[id] = 1
    }
    SQL_FreeHandle(Query)
}

я всего лишь дал наводку, если вы сами не сможете сделать то что вам я скинул то вам в раздел Покупка | Dev-CS.ru
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу