[18:09:34] [debug] Run time error 4: "Array index out of bounds"
[18:09:34] [debug] Attempted to read/write array element at negative index -1
[18:09:34] [debug] AMX backtrace:
[18:09:34] [debug] #0 00042230 in public Iter_OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\gamemodes\game.pwn:890
[18:09:34] [debug] #1 native CallLocalFunction () in server
[18:09:34] [debug] #2 00038a38 in public SSCANF_OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\pawno\include\foreach.inc:833
[18:09:34] [debug] #3 00031860 in public WC_OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\pawno\include\sscanf2.inc:266
[18:09:34] [debug] #4 00014b98 in public FIXES_OnPlayerDisconnect (1, 0) at C:\Users\ert\OneDrive\Desktop\game\pawno\include\weapon-config.inc:2243
[18:09:34] [debug] #5 00004960 in public OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\pawno\include\fixes.inc:6522
format(str, sizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]", GetName(playerid), GetName(id), GetName(id), health, armour);
public OnPlayerDisconnect(playerid, reason)
{
//another checks...
if(PlayerInfo[playerid][inDuel] == 1)
{
new id = PlayerInfo[playerid][Duelingto], Float:health, Float:armour, str[124];
GetPlayerHealth(id, health);
GetPlayerArmour(id, armour);
ResetPlayerWeapons(id);
SetPlayerVirtualWorld(id, 0);
SetPlayerInterior(id, 0);
SetPlayerHealth(id, 100);
SpawnPlayer(id);
format(str, sizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]", GetName(playerid), GetName(id), GetName(id), health, armour);
SendClientMessageToAll(CDUEL, str);
PlayerInfo[id][Duelingto] = -1;
PlayerInfo[id][Maker] = -1;
PlayerInfo[id][Opponent] = -1;
PlayerInfo[playerid][LoseDuels] ++;
PlayerInfo[id][WinDuels] ++;
}
// another checks etc
return 1;
}
Which line is 890? The issue could come from the fact that -if i'm not mistaken-, unless you store the player's name before he disconnects, GetName can't access the player's name anymore as he disconnected. Although this would be weird assuming that the message is sent correctly.
|
format(str, sizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]", GetName(playerid), GetName(id), GetName(id), health, armour);
PlayerInfo[id][Duelingto] = -1;
PlayerInfo[id][Maker] = -1;
PlayerInfo[id][Opponent] = -1;
PlayerInfo[playerid][LoseDuels] ++;
PlayerInfo[id][WinDuels] ++;
PlayerInfo[playerid][inDuel] = 0;
PlayerInfo[id][inDuel] = 0;
Are you resetting the PlayerInfo array when the player disconnects? If so, make sure to do the duel check before you reset it, otherwise I assume you set the value to -1 before you actually do your check, so "id" will always be -1 which isn't a valid player ID.
You also have a typo in your parameters, while it's unrelated to your problem, you gotta figure it out. |
Since arrays start from 0, -1 looks like an arbitrary value you give to it.
Post OnPlayerDisconnect entirely, maybe we can help. |
PHP Code:
PHP Code:
|
public OnPlayerDisconnect(playerid, reason)
{
if(gTeam[playerid][TEAMATT] == 1)
{
CountAtt --;
}
if(gTeam[playerid][TEAMDEF] == 1)
{
CountDef --;
}
if(PlayerInfo[playerid][inDuel] == 1)
{
new id = PlayerInfo[playerid][Duelingto], Float:health, Float:armour, str[124];
GetPlayerHealth(id, health);
GetPlayerArmour(id, armour);
ResetPlayerWeapons(id);
SetPlayerVirtualWorld(id, 0);
SetPlayerInterior(id, 0);
SetPlayerHealth(id, 100);
SpawnPlayer(id);
format(str, sizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]", GetName(playerid), GetName(id), GetName(id), health, armour);
SendClientMessageToAll(CDUEL, str);
PlayerInfo[id][Duelingto] = -1;
PlayerInfo[id][Maker] = -1;
PlayerInfo[id][Opponent] = -1;
PlayerInfo[playerid][LoseDuels] ++;
PlayerInfo[id][WinDuels] ++;
}
if(PlayerInfo[playerid][Inviter] == 1)
{
new id = PlayerInfo[playerid][Inviter], str[124];
PlayerInfo[id][Invited] = 0;
KillTimer(InviteTimer[id]);
format(str, sizeof(str), "%s disconnected in the mid of the invite. The invite is cancelled.", GetName(playerid));
SendClientMessage(id, CDUEL, str);
}
if(PlayerInfo[playerid][Invited] == 1)
{
new id = PlayerInfo[playerid][Invited], str[124];
PlayerInfo[id][Inviter] = 0;
KillTimer(InviteTimer[id]);
format(str, sizeof(str), "%s disconnected in the mid of the invite. The invite is cancelled.", GetName(playerid));
SendClientMessage(id, CDUEL, str);
}
if(SniperGame[playerid] == 1)
{
new str[124];
countsniper --;
format(str, sizeof(str), "%s disconnected in the mid of sniper game. (%d players).", GetName(playerid), countsniper);
SendClientMessageToAll(-1, str);
}
Saving(playerid);
PlayerInfo[playerid][Logged] = 0;
PlayerInfo[playerid][pDeaths] = 0;
PlayerInfo[playerid][pKills] = 0;
PlayerInfo[playerid][Invisible] = 0;
PlayerInfo[playerid][God] = 0;
PlayerInfo[playerid][PMs] = 0;
PlayerInfo[playerid][Muted] = 0;
PlayerInfo[playerid][Admin] = 0;
PlayerInfo[playerid][Skin] = 0;
PlayerInfo[playerid][ATT] = 0;
PlayerInfo[playerid][DEF] = 0;
PlayerInfo[playerid][DMG] = 0;
PlayerInfo[playerid][TotalDMG] = 0;
PlayerInfo[playerid][FPSCheck] = 0;
PlayerInfo[playerid][FPSKick] = 0;
PlayerInfo[playerid][MsKick] = 0;
PlayerInfo[playerid][MsCheck] = 0;
PlayerInfo[playerid][NetCheck] = 0;
PlayerInfo[playerid][RestartSpawn] = 0;
PlayerInfo[playerid][WinRounds] = 0;
PlayerInfo[playerid][LoseRounds] = 0;
PlayerInfo[playerid][Hora] = 0;
PlayerInfo[playerid][Clima] = 0;
PlayerInfo[playerid][Warns] = 0;
PlayerInfo[playerid][Kicks] = 0;
PlayerInfo[playerid][Maker] = -1;
PlayerInfo[playerid][Opponent] = -1;
PlayerInfo[playerid][inDuel] = 0;
PlayerInfo[playerid][DuelMap] = 0;
PlayerInfo[playerid][DuelPack] = 0;
PlayerInfo[playerid][DuelArmour] = 0;
PlayerInfo[playerid][WeapDuel] = 0;
PlayerInfo[playerid][OnWeap] = 0;
PlayerInfo[playerid][Inviter] = 0;
PlayerInfo[playerid][Invited] = 0;
PlayerInfo[playerid][Duelingto] = -1;
PlayerInfo[playerid][WinDuels] = 0;
PlayerInfo[playerid][LoseDuels] = 0;
PlayerInfo[playerid][Duelos] = 1;
PlayerInfo[playerid][Duty] = 1;
gTeam[playerid][TEAMATT] = 0;
gTeam[playerid][TEAMDEF] = 0;
Streaks[playerid] = 0;
Voted[playerid] = 0;
LastPm[playerid] = -1;
onspec[playerid] = -1;
SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
TextDrawHideForPlayer(playerid, TextdrawLogo1);
TextDrawHideForPlayer(playerid, Textdraw2);
TextDrawHideForPlayer(playerid, TextdrawDMG[playerid]);
return 1;
}
In your code you are using "id" to refer to the player that this disconnected player was duelling but you are not considering whether the id value is -1 (the value you're resetting it to) or not. You should check if id isn't -1 before continuing with the rest of the related code, because if it is -1 that means that the target player will never be valid, so there's no reason to continue with it.
|