SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 31/10/2019, 09:11 PM   #1
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 276
Reputation: 8
Default Runtime Error

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerInPubg(playerid))
    {
        SetPVarInt(playerid, "JoinedPubg", 0);
        SetTimerEx("ResetPlayerPubg", 2000, false, "d", playerid);
        if(killerid != INVALID_PLAYER_ID)
        {
        SetTimerEx("HideTextDrawKill", 3000, false, "d", playerid);
        SetTimerEx("HideTextDrawKill", 3000, 0, "d", killerid);
        new string[128], Name[24], weapon[48];
        GetPlayerName(playerid, Name, sizeof(Name));
        GetWeaponName(reason, weapon, sizeof(weapon));
        pCountKills[killerid]++;
        format(string, sizeof string, "~W~YOU killed %s with %s~n~~r~%i kills", Name, weapon, pCountKills[killerid]);
        TextDrawSetString(TexDraw_Kill[killerid], string);
        TextDrawShowForPlayer(killerid, TexDraw_Kill[killerid]);
        GetPlayerName(killerid, Name, sizeof(Name));
        format(string, sizeof string, "~W~%s killed YOU with %s", Name, weapon);
        TextDrawSetString(TexDraw_Kill[playerid], string);
        TextDrawShowForPlayer(playerid, TexDraw_Kill[playerid]);
        }
    }
    return 1;
}

function HideTextDrawKill(playerid)
{
    TextDrawHideForPlayer(playerid, TexDraw_Kill[playerid]);
    return 1;
}

Code:
[31/10/2019 21:09:46] [debug] Run time error 4: "Array index out of bounds"
[31/10/2019 21:09:46] [debug]  Attempted to read/write array element at index 65535 in array of size 120
[31/10/2019 21:09:46] [debug] AMX backtrace:
[31/10/2019 21:09:46] [debug] #0 00013210 in public OnPlayerDeath (playerid=9, killerid=65535, reason=255) at Pubg.pwn:1433
[31/10/2019 21:09:49] [debug] Run time error 4: "Array index out of bounds"
[31/10/2019 21:09:49] [debug]  Attempted to read/write array element at index 65535 in array of size 120
[31/10/2019 21:09:49] [debug] AMX backtrace:
[31/10/2019 21:09:49] [debug] #0 00013504 in public HideTextDrawKill (playerid=65535) at Pubg.pwn:1448
I don't know where my code is wrong.
Vizi10 is offline   Reply With Quote
Old 31/10/2019, 11:04 PM   #2
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,230
Reputation: 993
Default Re: Runtime Error

Classic. killerid will be INVALID_PLAYER_ID (65535) if the player dies from suicide. Using killerid without first checking it is valid (i.e. not INVALID_) in an array will cause this RT error.

pawn Code:
if(killerid != INVALID_PLAYER_ID)
{
    // Do stuff involving killerid
}
__________________
Click banner above for more info. View trailers here.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 31/10/2019, 11:59 PM   #3
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 276
Reputation: 8
Default Re: Runtime Error

Quote:
Originally Posted by MP2 View Post
Classic. killerid will be INVALID_PLAYER_ID (65535) if the player dies from suicide. Using killerid without first checking it is valid (i.e. not INVALID_) in an array will cause this RT error.

pawn Code:
if(killerid != INVALID_PLAYER_ID)
{
    // Do stuff involving killerid
}
Did you see my code? I have it.
Vizi10 is offline   Reply With Quote
Old 01/11/2019, 01:05 AM   #4
Unte99
Gangsta
 
Unte99's Avatar
 
Join Date: Jul 2010
Location: Lithuania
Posts: 629
Reputation: 65
Default Re: Runtime Error

What if you add these checks?

pawn Code:
if(killerid != INVALID_PLAYER_ID && killerid >= 0 && killerid < MAX_PLAYERS)

Do you have any filterscripts?
Unte99 is offline   Reply With Quote
Old 01/11/2019, 09:07 PM   #5
Markski
Big Clucker
 
Markski's Avatar
 
Join Date: Apr 2015
Location: La Plata, Argentina
Posts: 119
Reputation: 37
Default Re: Runtime Error

Quote:
Originally Posted by Vizi10 View Post
Did you see my code? I have it.
You have the check indeed, but the problem remains the same. You may wanna check you don't have any filterscript or hook for OnPlayerDeath which runs code that might be not checking for a valid killerid.

I also find it curious that the timer seems to run with an invalid player id too, despite it being impossible to make a call for an invalid id based in your OnPlayerDeath callback, unless that timer is also set elsewhere. Maybe check for invalid id on the timer's function too.
Markski 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
Runtime error ? , but already downloaded Runtime. TheSentinels Client Support 8 04/10/2013 04:57 PM
Error 19; Runtime error: File or function cannot be found. Josh_Main Scripting Help 9 17/08/2012 02:15 PM
RunTIme Error from Client... Mircrosoft Visual c++ Runtime Libary asdfgh98 Client Support 0 22/02/2010 04:08 PM
Microsoft visual c++ runtime library Runtime error! waringzone Client Support 3 16/06/2009 08:41 PM


All times are GMT. The time now is 01:32 AM.


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