SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 02/06/2020, 08:51 AM   #1
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 236
Reputation: 4
Default another backtrace

Hello! I found this recently:

PHP Code:
[18:09:34] [debugRun 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] [debugAMX 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 
This happens if a player disconnects in the middle of a duel. Line:

PHP Code:
format(strsizeof(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), healtharmour); 
OnPlayerDisconnect:

PHP Code:
public OnPlayerDisconnect(playeridreason)
{
   
//another checks...
    
if(PlayerInfo[playerid][inDuel] == 1)
    {
        new 
id PlayerInfo[playerid][Duelingto], Float:healthFloat:armourstr[124];
        
GetPlayerHealth(idhealth);
        
GetPlayerArmour(idarmour);
        
ResetPlayerWeapons(id);
        
SetPlayerVirtualWorld(id0);
        
SetPlayerInterior(id0);
        
SetPlayerHealth(id100);
        
SpawnPlayer(id);
        
format(strsizeof(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), healtharmour);
        
SendClientMessageToAll(CDUELstr);

        
PlayerInfo[id][Duelingto] = -1;
        
PlayerInfo[id][Maker] = -1;
        
PlayerInfo[id][Opponent] = -1;
        
PlayerInfo[playerid][LoseDuels] ++;
        
PlayerInfo[id][WinDuels] ++;
    }

   
// another checks etc
   
return 1;

The message is sent correctly to the other player and runs well the code but i founded this in the log
Ertouq is offline   Reply With Quote
Old 02/06/2020, 09:00 AM   #2
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 485
Reputation: 37
Default Re: another backtrace

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.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Old 02/06/2020, 09:14 AM   #3
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 236
Reputation: 4
Default Re: another backtrace

Quote:
Originally Posted by Adamoneoone View Post
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.
The line is the one I put in:

PHP Code:
format(strsizeof(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), healtharmour); 
I think it's the GetName(playerid) but it's sent correctly anyway. So I don't know why I get that. I don't save the names in a variable, instead I use the GetName().
Ertouq is offline   Reply With Quote
Old 02/06/2020, 11:56 PM   #4
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 236
Reputation: 4
Default Re: another backtrace

Bump
Ertouq is offline   Reply With Quote
Old 03/06/2020, 12:04 AM   #5
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Posts: 828
Reputation: 200
Default Re: another backtrace

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.
__________________
Need a game server? Contact me for information.
Variable™ is offline   Reply With Quote
Old 03/06/2020, 12:20 AM   #6
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Posts: 497
Reputation: 35
Default Re: another backtrace

Since arrays start from 0, -1 looks like an arbitrary value you give to it.

Post OnPlayerDisconnect entirely, maybe we can help.
__________________
My test server: 51.91.122.18:7778
My Discord contact: [SF]kAn3#9933
YT https://www.youtube.com/channel/UCrM...QtP2pczguqvppw
v1k1nG is offline   Reply With Quote
Old 03/06/2020, 01:23 AM   #7
ItsRobinson
Big Clucker
 
ItsRobinson's Avatar
 
Join Date: Sep 2017
Posts: 111
Reputation: 21
Default Re: another backtrace

PHP Code:
        PlayerInfo[id][Duelingto] = -1;
        
PlayerInfo[id][Maker] = -1;
        
PlayerInfo[id][Opponent] = -1;
        
PlayerInfo[playerid][LoseDuels] ++;
        
PlayerInfo[id][WinDuels] ++; 
We can't see your whole code, but I'd presuming these would need to be in the above bit no?

PHP Code:
        PlayerInfo[playerid][inDuel] = 0;
        
PlayerInfo[id][inDuel] = 0
__________________
EX-

ItsRobinson is offline   Reply With Quote
Old 03/06/2020, 07:31 AM   #8
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 236
Reputation: 4
Default Re: another backtrace

Quote:
Originally Posted by Variable™ View Post
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.

I checked and I don't see anything wrong, could you tell me a clue? I will post the code.

Quote:
Originally Posted by v1k1nG View Post
Since arrays start from 0, -1 looks like an arbitrary value you give to it.

Post OnPlayerDisconnect entirely, maybe we can help.
Quote:
Originally Posted by ItsRobinson View Post
PHP Code:
        PlayerInfo[id][Duelingto] = -1;
        
PlayerInfo[id][Maker] = -1;
        
PlayerInfo[id][Opponent] = -1;
        
PlayerInfo[playerid][LoseDuels] ++;
        
PlayerInfo[id][WinDuels] ++; 
We can't see your whole code, but I'd presuming these would need to be in the above bit no?

PHP Code:
        PlayerInfo[playerid][inDuel] = 0;
        
PlayerInfo[id][inDuel] = 0



PHP Code:
public OnPlayerDisconnect(playeridreason)
{

    if(
gTeam[playerid][TEAMATT] == 1)
    {
        
CountAtt --;
    }
    if(
gTeam[playerid][TEAMDEF] == 1)
    {
        
CountDef --;
    }
    if(
PlayerInfo[playerid][inDuel] == 1)
    {
        new 
id PlayerInfo[playerid][Duelingto], Float:healthFloat:armourstr[124];
        
GetPlayerHealth(idhealth);
        
GetPlayerArmour(idarmour);
        
ResetPlayerWeapons(id);
        
SetPlayerVirtualWorld(id0);
        
SetPlayerInterior(id0);
        
SetPlayerHealth(id100);
        
SpawnPlayer(id);
        
format(strsizeof(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), healtharmour); 
        
SendClientMessageToAll(CDUELstr);

        
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(strsizeof(str), "%s disconnected in the mid of the invite. The invite is cancelled."GetName(playerid));
        
SendClientMessage(idCDUELstr);
    }
    if(
PlayerInfo[playerid][Invited] == 1)
    {
        new 
id PlayerInfo[playerid][Invited], str[124];
        
PlayerInfo[id][Inviter] = 0;
        
KillTimer(InviteTimer[id]);
        
format(strsizeof(str), "%s disconnected in the mid of the invite. The invite is cancelled."GetName(playerid));
        
SendClientMessage(idCDUELstr);
    }
    if(
SniperGame[playerid] == 1)
    {
        new 
str[124];
        
countsniper --;
        
format(strsizeof(str), "%s disconnected in the mid of sniper game. (%d players)."GetName(playerid), countsniper);
        
SendClientMessageToAll(-1str);
    }
    
    
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_IDplayerid201);
    
TextDrawHideForPlayer(playeridTextdrawLogo1);
    
TextDrawHideForPlayer(playeridTextdraw2);
    
TextDrawHideForPlayer(playeridTextdrawDMG[playerid]);


    return 
1;

Ertouq is offline   Reply With Quote
Old 03/06/2020, 07:37 AM   #9
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Posts: 828
Reputation: 200
Default Re: another backtrace

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.
__________________
Need a game server? Contact me for information.
Variable™ is offline   Reply With Quote
Old 03/06/2020, 07:42 AM   #10
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 236
Reputation: 4
Default Re: another backtrace

Quote:
Originally Posted by Variable™ View Post
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.
Uh, I didn't quite understand, could you give me an example?
Ertouq is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
backtrace Ertouq Scripting Help 5 29/05/2020 10:57 AM
amx backtrace XSharkX Scripting Help 5 31/05/2018 04:48 PM
AMX Backtrace help ohmy Scripting Help 1 22/05/2018 06:04 AM
AMX backtrace Auri Scripting Help 3 02/02/2016 11:32 AM
AMX Backtrace [+Rep] RayC Scripting Help 2 04/01/2015 07:51 PM


All times are GMT. The time now is 03:05 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.