SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 19/05/2019, 12:23 AM   #1
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Run time error 4: "Array index out of bounds"

We just go to the problem, I make the command /storecrate, when I use it I get an error at server_log.txt containing:

Code:
[00:15:28] [zcmd] [B.G]: /storecrate
[00:15:28] [debug] Run time error 4: "Array index out of bounds"
[00:15:28] [debug]  Attempted to read/write array element at index 168 in array of size 5
[00:15:28] [debug] AMX backtrace:
[00:15:28] [debug] #0 0062b4f0 in public cmd_storecrate (playerid=0, params[]=@06190f64 "") at HLRPEjo.pwn:33663
[00:15:28] [debug] #1 native CallLocalFunction () in samp03svr-erp
[00:15:28] [debug] #2 00051a94 in public OnPlayerCommandText (playerid=0, cmdtext[]=@06190f34 "/storecrate") at F:\SAMPSERVER\WeAreGameMode\pawno\include\izcmd.inc:118
Then I checked in the code (line 33663), the code is like this:
PHP Code:
CMD:storecrate(playeridparams[])
{
    if(
PlayerInfo[playerid][pJob] == 22 || PlayerInfo[playerid][pJob2] == 22)
    {
        if(
GetPVarInt(playerid"CarryingCrate") != 1) return SCM(playeridCOLOR_LIGHTBLUE"Trucker: {FFFFFF}Kamu tidak sedang membawa crate");
        new 
closesttruck GetClosestVehicle(playerid7.0);
        new 
trucktype GetVehicleModel(closesttruck);
        if(
trucktype == 456 || trucktype == 499 || trucktype == 455 || trucktype == 498 || trucktype == 609 || trucktype == 414)
        {
            if(
GetPlayerVehicle(playeridclosesttruck) == -1) return SEM(playerid"Trucker: {FFFFFF}Truck ini bukan milikmu!");
            new 
Float:vXFloat:vYFloat:vZ;
            
GetPosBehindVehicle(closesttruckvXvYvZ);
            if(
IsPlayerInRangeOfPoint(playerid2.5vXvYvZ))
            {
                if(
PlayerVehicleInfo[playerid][closesttruck][pvCrates] != PlayerVehicleInfo[playerid][closesttruck][pvMaxCrates]) // LINE 33663 !ERROR!
                
{
                    new 
string[128];
                    
PlayerVehicleInfo[playerid][closesttruck][pvCrates]++;
                    
DropDaCrate(playerid);
                    
SCM(playeridCOLOR_LIGHTBLUE"Trucker: {FFFFFF}Kamu telah meletakkan crate ke bagasi {FFFF00}%s"GetVehicleName(closesttruck));
                    
SCM(playeridCOLOR_YELLOW"INFO: {FFFFFF}Sisa slot bagasi: {FFFF00}%d{FFFFFF}/{FF0000}%d"PlayerVehicleInfo[playerid][closesttruck][pvCrates], PlayerVehicleInfo[playerid][closesttruck][pvMaxCrates]);
                    
format(stringsizeof(string), "{FFFF00}%d{FFFFFF}/{FF0000}%d"PlayerVehicleInfo[playerid][closesttruck][pvCrates], PlayerVehicleInfo[playerid][closesttruck][pvMaxCrates]);
                    
TextDrawSetString(textdraw_4string);
                }
                else return 
SEM(playerid"Trucker: {FFFFFF}Bagasi sudah penuh dengan crates");
            }
            else return 
SEM(playerid"Trucker: {FFFFFF}Kamu tidak berada di bagasi truck");
        }
        else return 
SEM(playerid"Trucker: {FFFFFF}Kamu tidak dekat dengan truck apapun");
    }
    else return 
SEM(playerid"Trucker: {FFFFFF}Kamu bukan seorang trucker!");
    return 
1;

How to fix thiss? please help me ...
Thanks
KinxpIn is offline   Reply With Quote
Old 19/05/2019, 12:25 AM   #2
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: Run time error 4: "Array index out of bounds"

Additional:

PHP Code:
enum pvInfo
{
        
//blablablabla
    
pvMaxCrates,
    
pvCrates
};
new 
PlayerVehicleInfo[MAX_PLAYERS+1][MAX_PLAYERVEHICLES][pvInfo]; 
KinxpIn is offline   Reply With Quote
Old 19/05/2019, 01:31 AM   #3
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: Run time error 4: "Array index out of bounds"

bump, help mee guyss
KinxpIn is offline   Reply With Quote
Old 19/05/2019, 03:12 AM   #4
Ejected
Big Clucker
 
Ejected's Avatar
 
Join Date: Jul 2012
Location: United States Discord: ABC#6701
Posts: 155
Reputation: 16
Default Re: Run time error 4: "Array index out of bounds"

Try this

PHP Code:
new PlayerVehicleInfo[MAX_PLAYERS+1][MAX_VEHICLES][pvInfo]; 
If that works then the problem is MAX_PLAYERVEHICLES definition
Ejected is offline   Reply With Quote
Old 19/05/2019, 09:46 AM   #5
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: Run time error 4: "Array index out of bounds"

Quote:
Originally Posted by Ejected View Post
Try this

PHP Code:
new PlayerVehicleInfo[MAX_PLAYERS+1][MAX_VEHICLES][pvInfo]; 
If that works then the problem is MAX_PLAYERVEHICLES definition
This enum is for player vehicle, max player vehicles is only 5...
KinxpIn 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
Run time error 4: "Array index out of bounds" in Server Console! HAGAKURE Scripting Help 6 13/07/2016 09:18 PM
[debug] Run time error 4: "Array index out of bounds" skiplovebra Scripting Help 2 13/04/2016 03:53 PM
[REP++ WHO HELPS] Run time error 4: "Array index out of bounds" buburuzu19 Scripting Help 3 14/08/2015 09:21 AM
[debug] Run time error 4: "Array index out of bounds" and many more errors :P ntmp Scripting Help 2 11/08/2014 02:10 PM
Run time error 4: "Array index out of bounds" in public turftaking [SF]OutLawZ Scripting Help 1 01/08/2012 05:07 AM


All times are GMT. The time now is 09:30 PM.


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