- 73
- 7
Кто знает как это решить ? Все данные кроме targetid и playerid берутся коректно, делал запрос напрямую в sql все ок выводит, но при запросе в коде в playerid и targetId ставит 0.
Вот код:
вот что выводит в консоли:
[10:54:59] Parameters: targetName='Test_Test', category='R', reason='тест' [10:54:59] Executed query: SELECT id, last_game_ip, login FROM accounts WHERE login = 'Test_Test' [10:54:59] OnOfBanPlayerFoundStep1 called: playerid=0, reason='тест', category='R', adminName='Samuel_Goldie' [10:54:59] Retrieved values: targetId=0, targetIp='62.122.70.14', targetName='Test_Test' [10:54:59] Error: targetId is 0. Player might not exist.
Вот код:
pawn:
CMD:ofban(playerid, params[])
{
if (!CheckAdmin(playerid, ADMIN_LEVEL_3))
return SendNotAdmin(playerid);
new targetName[24];
new category[3];
new reason[64];
if (sscanf(params, "s[24]s[3]s[64]", targetName, category, reason))
return SendSpecialMessage(playerid, "Подсказка:: /ofban [Имя игрока] [Категория (R, HR, C, HC)] [Причина]");
new adminName[24];
GetPlayerName(playerid, adminName, sizeof(adminName));
printf("Parameters: targetName='%s', category='%s', reason='%s'", targetName, category, reason);
// Выполнение первого запроса для получения id и last_game_ip
new query[256];
mysql_format(dbHandle, query, sizeof(query),
"SELECT id, last_game_ip, login FROM accounts WHERE login = '%s'",
targetName);
mysql_tquery(dbHandle, query, "OnOfBanPlayerFoundStep1", "dsss", playerid, reason, category, adminName);
printf("Executed query: %s", query);
return 1;
}
forward OnOfBanPlayerFoundStep1(playerid, reason[], category[], adminName[], queryHandle);
public OnOfBanPlayerFoundStep1(playerid, reason[], category[], adminName[], queryHandle)
{
printf("OnOfBanPlayerFoundStep1 called: playerid=%d, reason='%s', category='%s', adminName='%s'", playerid, reason, category, adminName);
if (cache_get_row_count() == 0)
{
printf("Player not found in accounts.");
SendSpecialMessage(playerid, "Игрок с таким именем не найден.");
return 1;
}
new targetId;
new targetIp[24];
new targetName[24];
cache_get_field_content_int(0, "id", targetId);
cache_get_field_content(0, "last_game_ip", targetIp, sizeof(targetIp));
cache_get_field_content(0, "login", targetName, sizeof(targetName));
printf("Retrieved values: targetId=%d, targetIp='%s', targetName='%s'", targetId, targetIp, targetName);
if (targetId == 0)
{
printf("Error: targetId is 0. Player might not exist.");
SendSpecialMessage(playerid, "Ошибка: игрок с таким ID не существует.");
return 1;
}
printf("Player found in accounts: targetId=%d, targetIp='%s', targetName='%s'", targetId, targetIp, targetName);
// Выполнение второго запроса для получения уровня игрока
new query[256];
mysql_format(dbHandle, query, sizeof(query),
"SELECT level FROM users WHERE accountid = %d",
targetId);
mysql_tquery(dbHandle, query, "OnOfBanPlayerFoundStep2", "dsssi", playerid, reason, category, adminName, targetId, targetIp, targetName);
printf("Executed query: %s", query);
return 1;
}
forward OnOfBanPlayerFoundStep2(playerid, reason[], category[], adminName[], targetId, targetIp[], targetName[], queryHandle);
public OnOfBanPlayerFoundStep2(playerid, reason[], category[], adminName[], targetId, targetIp[], targetName[], queryHandle)
{
printf("OnOfBanPlayerFoundStep2 called: playerid=%d, reason='%s', category='%s', adminName='%s', targetId=%d, targetIp='%s', targetName='%s'", playerid, reason, category, adminName, targetId, targetIp, targetName);
if (cache_get_row_count() == 0)
{
printf("Player not found in users.");
SendSpecialMessage(playerid, "Игрок с таким ID не найден.");
return 1;
}
new playerLevel;
cache_get_field_content_int(0, "level", playerLevel);
printf("Player found in users: playerLevel=%d", playerLevel);
new banDuration, unbanTime;
new currentTime = GetCurrentUnixTime(); // Получаем текущее время в формате UNIX
if (strcmp(category, "R", true) == 0)
{
if (playerLevel <= 1) banDuration = 1440; // 1 день в минутах
else if (playerLevel <= 3) banDuration = 4320; // 3 дня в минутах
else if (playerLevel <= 5) banDuration = 7200; // 5 дней в минутах
else if (playerLevel <= 7) banDuration = 10080; // 7 дней в минутах
else if (playerLevel <= 9) banDuration = 14400; // 10 дней в минутах
else if (playerLevel <= 11) banDuration = 20160; // 14 дней в минутах
else banDuration = 43200; // 30 дней в минутах
unbanTime = currentTime + (banDuration * SECONDS_IN_MINUTE); // Устанавливаем unbanTime в формате UNIX времени
}
else if (strcmp(category, "HR", true) == 0)
{
unbanTime = -1; // Бессрочный бан
}
else if (strcmp(category, "C", true) == 0)
{
if (playerLevel <= 1) banDuration = 2880; // 2 дня в минутах
else if (playerLevel <= 3) banDuration = 5760; // 4 дня в минутах
else if (playerLevel <= 5) banDuration = 8640; // 6 дней в минутах
else if (playerLevel <= 7) banDuration = 11520; // 8 дней в минутах
else if (playerLevel <= 10) banDuration = 14400; // 10 дней в минутах
else if (playerLevel <= 12) banDuration = 20160; // 14 дней в минутах
else banDuration = 43200; // 30 дней в минутах
unbanTime = currentTime + (banDuration * SECONDS_IN_MINUTE); // Устанавливаем unbanTime в формате UNIX времени
}
else if (strcmp(category, "HC", true) == 0)
{
unbanTime = -1; // Бессрочный бан
}
else
{
printf("Invalid category: category='%s'", category);
return SendSpecialMessage(playerid, "Неверная категория. Доступные категории: R, HR, C, HC.");
}
new banTimeString[20];
new unbanTimeString[20];
FormatDateTime(currentTime, banTimeString, sizeof(banTimeString)); // Запись текущего времени
if (unbanTime != -1)
{
FormatDateTime(unbanTime, unbanTimeString, sizeof(unbanTimeString)); // Запись времени окончания бана
}
else
{
format(unbanTimeString, sizeof(unbanTimeString), "9999-12-31 23:59:59"); // Для бессрочного бана
}
printf("Ban details: banTimeString='%s', unbanTimeString='%s'", banTimeString, unbanTimeString);
new query[512];
mysql_format(dbHandle, query, sizeof(query),
"INSERT INTO bans (player_id, login, ip, reason, admin, ban_time, unban_time, category, comment) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '/ofban')",
targetId,
targetName,
targetIp,
reason,
adminName,
banTimeString,
unbanTimeString,
category
);
mysql_tquery(dbHandle, query);
printf("Ban query executed: %s", query);
SendAdmMessage("%s забанил игрока %s [%s] %s.", adminName, targetName, category, reason);
return 1;
}
[10:54:59] Parameters: targetName='Test_Test', category='R', reason='тест' [10:54:59] Executed query: SELECT id, last_game_ip, login FROM accounts WHERE login = 'Test_Test' [10:54:59] OnOfBanPlayerFoundStep1 called: playerid=0, reason='тест', category='R', adminName='Samuel_Goldie' [10:54:59] Retrieved values: targetId=0, targetIp='62.122.70.14', targetName='Test_Test' [10:54:59] Error: targetId is 0. Player might not exist.