Closed MatheusAgL closed 6 months ago
Please provide a script that causes this problem on restart and player disconnect
#endinput
#endif
#define _inc_safezones true
#include <YSI_Coding\y_hooks>
#define COLOR_SAFEZONE 0x9AFBD890
#define C_SAFEZONE "9AFBD8"
#define MAX_SAFE_ZONES 10
enum ENUM_SAFE_ZONE {
safeID,
safeGZ,
safeName[35],
Float:safeMinX,
Float:safeMinY,
Float:safeMaxX,
Float:safeMaxY,
gzInt,
gzWorld,
};
static SafeZone[MAX_SAFE_ZONES][ENUM_SAFE_ZONE];
static bool:playerInSafeZone[MAX_PLAYERS];
static Timer:timer_safe_set[MAX_PLAYERS];
stock SafeZone_SetID(safe, id)
SafeZone[safe][safeID] = id;
stock SafeZone_SetName(safe, const name[])
format(SafeZone[safe][safeName], 35, name);
stock SafeZone_SetMinX(safe, Float:min_x)
SafeZone[safe][safeMinX] = min_x;
stock SafeZone_SetMinY(safe, Float:min_y)
SafeZone[safe][safeMinY] = min_y;
stock SafeZone_SetMaxX(safe, Float:max_x)
SafeZone[safe][safeMaxX] = max_x;
stock SafeZone_SetMaxY(safe, Float:max_y)
SafeZone[safe][safeMaxY] = max_y;
stock SafeZone_SetInterior(safe, interior)
SafeZone[safe][gzInt] = interior;
stock SafeZone_SetWorld(safe, world)
SafeZone[safe][gzWorld] = world;
stock IsPlayerInSafeZone(playerid)
return playerInSafeZone[playerid];
// ------------------------ Sistema de Zona segura ------------------------
new Iterator: SafeZones<MAX_SAFE_ZONES>;
static
Statement: stmt_insertSafeZone,
Statement: stmt_selectSafeZone,
Statement: stmt_deleteSafeZone;
hook OnMySQLConnected()
{
static const query_insertSafeZone[] =
"INSERT INTO `safe_zone` (`id`, `name`, `min_x`, `min_y`, `max_x`, `max_y`, `interior`, `world`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)"
;
stmt_insertSafeZone = MySQL_PrepareStatement(MySQL_Handle, query_insertSafeZone);
static const query_selectSafeZone[] =
"SELECT id, name, min_x, min_y, max_x, max_y, interior, world FROM `safe_zone` LIMIT ?"
;
stmt_selectSafeZone = MySQL_PrepareStatement(MySQL_Handle, query_selectSafeZone);
static const query_deleteSafeZone[] =
"DELETE FROM `safe_zone` WHERE `id` = ?"
;
stmt_deleteSafeZone = MySQL_PrepareStatement(MySQL_Handle, query_deleteSafeZone);
return 1;
}
hook OnGameModeInit()
{
inline const OnLoadSafeZones()
{
new name[35],
Float:min_x,
Float:min_y,
Float:max_x,
Float:max_y,
interior,
world;
MySQL_BindResult(stmt_selectSafeZone, 1, name);
MySQL_BindResultFloat(stmt_selectSafeZone, 2, min_x);
MySQL_BindResultFloat(stmt_selectSafeZone, 3, min_y);
MySQL_BindResultFloat(stmt_selectSafeZone, 4, max_x);
MySQL_BindResultFloat(stmt_selectSafeZone, 5, max_y);
MySQL_BindResultInt(stmt_selectSafeZone, 6, interior);
MySQL_BindResultInt(stmt_selectSafeZone, 7, world);
while (MySQL_Statement_FetchRow(stmt_selectSafeZone)) {
SafeZone_Create(name, min_x, min_y, max_x, max_y, interior, world);
}
new count = Iter_Count(SafeZones);
printf("[SafeZones]: %d carregadas...", count);
}
MySQL_BindInt(stmt_selectSafeZone, 0, MAX_SAFE_ZONES);
MySQL_ExecuteParallel_Inline(stmt_selectSafeZone, using inline OnLoadSafeZones);
return 1;
}
hook OnPlayerConnect(playerid)
{
SafeZones_ShowForPlayer(playerid);
return 1;
}
hook OnPlayerDisconnect(playerid, reason)
{
playerInSafeZone[playerid] = false;
return 1;
}
timer Timer_SetPlayerSafeZone[1000 * 60](playerid) {
SendClientMessage(playerid, -1, "Você foi definido como protegido por area neutra");
return playerInSafeZone[playerid] = true;
}
hook OnPlayerEnterGangZone(playerid, zoneid)
{
foreach (new safe : SafeZones) {
if (zoneid == SafeZone[safe][safeGZ]) {
ShowPlayerBaloonInfo(playerid, "Voce entrou em uma ~g~area segura~w~, em 1 minuto estara ~g~~h~protegido.", 5000);
timer_safe_set[playerid] = defer Timer_SetPlayerSafeZone(playerid);
}
}
return 1;
}
hook OnPlayerLeaveGangZone(playerid, zoneid)
{
foreach (new safe : SafeZones) {
if (zoneid == SafeZone[safe][safeGZ]) {
stop timer_safe_set[playerid];
ShowPlayerBaloonInfo(playerid, "Voce saiu de uma ~g~area segura", 5000);
playerInSafeZone[playerid] = false;
}
}
return 1;
}
stock SafeZone_Insert(id, const name[], Float: min_x, Float: min_y, Float: max_x, Float: max_y, interior, world) {
MySQL_BindInt(stmt_insertSafeZone, 0, id);
MySQL_Bind(stmt_insertSafeZone, 1, name);
MySQL_BindFloat(stmt_insertSafeZone, 2, min_x);
MySQL_BindFloat(stmt_insertSafeZone, 3, min_y);
MySQL_BindFloat(stmt_insertSafeZone, 4, max_x);
MySQL_BindFloat(stmt_insertSafeZone, 5, max_y);
MySQL_BindInt(stmt_insertSafeZone, 6, interior);
MySQL_BindInt(stmt_insertSafeZone, 7, world);
MySQL_ExecuteThreaded(stmt_insertSafeZone);
}
stock SafeZone_Create(const name[], Float:min_x, Float:min_y, Float:max_x, Float:max_y, interior = 0, world = 0) {
new id = Iter_Free(SafeZones);
if (id != -1) {
Iter_Add(SafeZones, id);
SafeZone_SetID(id, id);
SafeZone_SetName(id, name);
SafeZone_SetMinX(id, min_x);
SafeZone_SetMinY(id, min_y);
SafeZone_SetMaxX(id, max_x);
SafeZone_SetMaxY(id, max_y);
SafeZone_SetInterior(id, interior);
SafeZone_SetWorld(id, world);
if (interior == 0)
SafeZone[id][safeGZ] = GangZoneCreate(min_x, min_y, max_x, max_y);
UseGangZoneCheck(SafeZone[id][safeGZ], true);
GangZoneShowForAll(SafeZone[id][safeGZ], COLOR_SAFEZONE);
return 1;
}
return 0;
}
stock SafeZone_Destroy(safe) {
new id = Iter_Contains(SafeZones, safe);
if (id != -1) {
Iter_Remove(SafeZones, safe);
GangZoneDestroy(SafeZone[safe][safeGZ]);
MySQL_BindInt(stmt_deleteSafeZone, 0, SafeZone[safe][safeID]);
MySQL_ExecuteThreaded(stmt_deleteSafeZone);
}
}
stock SafeZone_IsPlayerIn(playerid) {
foreach (new safe : SafeZones) if (IsPlayerInGangZone(playerid, safe)) {
return safe;
}
return -1;
}
stock SafeZones_ShowForPlayer(playerid) {
foreach (new safe : SafeZones) GangZoneShowForPlayer(playerid, SafeZone[safe][safeGZ], COLOR_SAFEZONE);
}```
Please provide a minimum, complete and verifiable example that still causes the bug; i.e. I should be able to reproduce the problem without the use of any third-party libraries.
For instance, you are using several y_iterate functions incorrectly:
Iter_Free
and Iter_Alloc
return INVALID_ITERATOR_SLOT
when there's no more free slot. The library defines this as cellmin
, not -1.Iter_Contains
returns a boolean, not an index or value, and its return value will therefore never be equal to -1.Thanks for the information about code errors, I made the corrections due.
I found that the error was for not using GangZoneDestroy
in OnGameModeExit
.
Describe the bug Every time the server is restarted when it comes back, and a player disconnects, this error is presented by CrashDetect
To Reproduce Steps to reproduce the behavior: Restart the server The first player who lodges
Expected behavior Do not crashed
Screenshots and/or logs