DenisPukin
Капитан Костыль
- Сообщения
- 185
- Реакции
- 34
Все привет! Недавно столкнулся с плагином shavit's simple bhop timer в нём не работает поддержка sql.
Разработчик плагина предложил какую то таблицу:
CREATE TABLE IF NOT EXISTS `playertimes` (`id` INT NOT NULL AUTO_INCREMENT, `auth` VARCHAR(32), `map` VARCHAR(128), `time` FLOAT, `jumps` VARCHAR(32), `style` VARCHAR(32), `date` DATE, PRIMARY KEY (`id`));
Я попробовал её создать в базе данных через SQLiteStudio. Все получилось в игре таблица открывается, но рекорды не сохраняются пишет ошибку:
SQL query failed. Reason: near "(": syntax error
Возможно в этом коде скрипта что то не хватает?
Прошу помочь!
[HIDE="1"]public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps)
{
BhopStyle bsStyle = view_as<BhopStyle>(style);
char sTime[32];
FormatSeconds(time, sTime, 32);
// k people I made this forward so I'll use it to make cool text messages on WR (check timer-misc soon™)
if(time < gF_WRTime[style] || gF_WRTime[style] == 0.0) // WR?
{
Call_StartForward(gH_OnWorldRecord);
Call_PushCell(client);
Call_PushCell(style);
Call_PushCell(time);
Call_PushCell(jumps);
Call_Finish();
UpdateWRCache();
}
// 0 - no query
// 1 - insert
// 2 - update
int overwrite;
if(gF_PlayerRecord[client][style] == 0.0)
{
overwrite = 1;
}
else if(time < gF_PlayerRecord[client][style])
{
overwrite = 2;
}
float fDifference = (gF_PlayerRecord[client][style] - time) * -1.0;
char sDifference[16];
FormatSeconds(fDifference, sDifference, 16, true);
if(overwrite > 0)
{
char sAuthID[32];
GetClientAuthId(client, AuthId_Steam3, sAuthID, 32);
char sQuery[256];
if(overwrite == 1) // insert
{
PrintToChatAll("%s \x03%N\x01 Прошел карту (%s) за \x07%s\x01 с %d прыжками.", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps);
FormatEx(sQuery, 256, "INSERT INTO playertimes (auth, map, time, jumps, date, style) VALUES ('%s', '%s', %.03f, %d, CURRENT_TIMESTAMP(), '%d');", sAuthID, gS_Map, time, jumps, style);
}
else // update
{
PrintToChatAll("%s \x03%N\x01 Прошел карту (%s) за \x07%s\x01 с %d прыжками. \x0C(%s)", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference);
FormatEx(sQuery, 256, "UPDATE playertimes SET time = '%.03f', jumps = '%d', date = CURRENT_TIMESTAMP() WHERE map = '%s' AND auth = '%s' AND style = '%d';", time, jumps, gS_Map, sAuthID, style);
}
SQL_TQuery(gH_SQL, SQL_OnFinish_Callback, sQuery, GetClientSerial(client));
}
else
{
if(!overwrite)
{
PrintToChat(client, "%s Вы прошли карту (%s) за \x07%s\x01 с %d прыжками. \x08(+%s)", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference);
}
else
{
PrintToChat(client, "%s Вы прошли карту (%s) за \x07%s\x01 с %d прыжками.", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps);
}
}
}
public void SQL_OnFinish_Callback(Handle owner, Handle hndl, const char[] error, any data)
{
if(hndl == null)
{
LogError("Timer (WR OnFinish) SQL query failed. Reason: %s", error);
return;
}
int client = GetClientFromSerial(data);
if(!client)
{
return;
}
UpdateWRCache();
UpdateClientCache(client);
}[/HIDE]
Разработчик плагина предложил какую то таблицу:
CREATE TABLE IF NOT EXISTS `playertimes` (`id` INT NOT NULL AUTO_INCREMENT, `auth` VARCHAR(32), `map` VARCHAR(128), `time` FLOAT, `jumps` VARCHAR(32), `style` VARCHAR(32), `date` DATE, PRIMARY KEY (`id`));
Я попробовал её создать в базе данных через SQLiteStudio. Все получилось в игре таблица открывается, но рекорды не сохраняются пишет ошибку:
SQL query failed. Reason: near "(": syntax error
Возможно в этом коде скрипта что то не хватает?
Прошу помочь!
[HIDE="1"]public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps)
{
BhopStyle bsStyle = view_as<BhopStyle>(style);
char sTime[32];
FormatSeconds(time, sTime, 32);
// k people I made this forward so I'll use it to make cool text messages on WR (check timer-misc soon™)
if(time < gF_WRTime[style] || gF_WRTime[style] == 0.0) // WR?
{
Call_StartForward(gH_OnWorldRecord);
Call_PushCell(client);
Call_PushCell(style);
Call_PushCell(time);
Call_PushCell(jumps);
Call_Finish();
UpdateWRCache();
}
// 0 - no query
// 1 - insert
// 2 - update
int overwrite;
if(gF_PlayerRecord[client][style] == 0.0)
{
overwrite = 1;
}
else if(time < gF_PlayerRecord[client][style])
{
overwrite = 2;
}
float fDifference = (gF_PlayerRecord[client][style] - time) * -1.0;
char sDifference[16];
FormatSeconds(fDifference, sDifference, 16, true);
if(overwrite > 0)
{
char sAuthID[32];
GetClientAuthId(client, AuthId_Steam3, sAuthID, 32);
char sQuery[256];
if(overwrite == 1) // insert
{
PrintToChatAll("%s \x03%N\x01 Прошел карту (%s) за \x07%s\x01 с %d прыжками.", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps);
FormatEx(sQuery, 256, "INSERT INTO playertimes (auth, map, time, jumps, date, style) VALUES ('%s', '%s', %.03f, %d, CURRENT_TIMESTAMP(), '%d');", sAuthID, gS_Map, time, jumps, style);
}
else // update
{
PrintToChatAll("%s \x03%N\x01 Прошел карту (%s) за \x07%s\x01 с %d прыжками. \x0C(%s)", PREFIX, client, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference);
FormatEx(sQuery, 256, "UPDATE playertimes SET time = '%.03f', jumps = '%d', date = CURRENT_TIMESTAMP() WHERE map = '%s' AND auth = '%s' AND style = '%d';", time, jumps, gS_Map, sAuthID, style);
}
SQL_TQuery(gH_SQL, SQL_OnFinish_Callback, sQuery, GetClientSerial(client));
}
else
{
if(!overwrite)
{
PrintToChat(client, "%s Вы прошли карту (%s) за \x07%s\x01 с %d прыжками. \x08(+%s)", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps, sDifference);
}
else
{
PrintToChat(client, "%s Вы прошли карту (%s) за \x07%s\x01 с %d прыжками.", PREFIX, bsStyle == Style_Forwards? "Forwards":"Sideways", sTime, jumps);
}
}
}
public void SQL_OnFinish_Callback(Handle owner, Handle hndl, const char[] error, any data)
{
if(hndl == null)
{
LogError("Timer (WR OnFinish) SQL query failed. Reason: %s", error);
return;
}
int client = GetClientFromSerial(data);
if(!client)
{
return;
}
UpdateWRCache();
UpdateClientCache(client);
}[/HIDE]