Array errors
#1

Hello,
I have a whole bunch of array errors with my code.

Code:
pawn Код:
/*//////////////////////////
Countryside Cops and Robbers created by CaptainPrice
for the SA-MP DJCabo community.

Forums: www.dc-samp.com

Credits:
CaptainPrice - Making the script
Nirzor - Requesting the script
DJ Cabo - For the DC SA-MP ccommunity
*/


#include <a_samp>

//Teams
#define TEAM_COP 0
#define TEAM_ROB 1
#define TEAM_TER 2

new pVehicles[12];

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n=====================================");
    print(" Countryside CNR by CaptainPrice loaded");
    print("=======================================\n");
}

#endif

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("CSCNR v1.0");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
   
    //Police Vehicles
    pVehicles[0] = AddStaticVehicleEx(599,613.20001221,-601.50000000,17.60000038,270.00000000,-1,-1,15); //Police Ranger
    pVehicles[1] = AddStaticVehicleEx(599,621.20001221,-609.70001221,17.20000076,270.00000000,-1,-1,15); //Police Ranger
    pVehicles[2] = AddStaticVehicleEx(599,613.19921875,-596.79980469,17.60000038,270.00000000,-1,-1,15); //Police Ranger
    pVehicles[3] = AddStaticVehicleEx(599,621.00000000,-605.90002441,17.20000076,270.00000000,-1,-1,15); //Police Ranger
    pVehicles[4] = AddStaticVehicleEx(599,615.79998779,-590.79998779,17.60000038,270.00000000,-1,-1,15); //Police Ranger
    pVehicles[5] = AddStaticVehicleEx(497,612.40002441,-600.50000000,22.79999924,180.00000000,-1,1,15); //Police Maverick
    pVehicles[6] = AddStaticVehicleEx(497,613.40002441,-577.09997559,26.20000076,267.99499512,-1,1,15); //Police Maverick
    pVehicles[7] = AddStaticVehicleEx(523,642.70001221,-610.50000000,16.00000000,0.00000000,-1,-1,15); //HPV1000
    pVehicles[8] = AddStaticVehicleEx(523,640.40002441,-610.50000000,16.00000000,0.00000000,-1,-1,15); //HPV1000
    pVehicles[9] = AddStaticVehicleEx(523,638.00000000,-610.50000000,16.00000000,0.00000000,-1,-1,15); //HPV1000
    pVehicles[10] = AddStaticVehicleEx(523,614.50000000,-586.90002441,16.89999962,268.00000000,-1,-1,15); //HPV1000
    pVehicles[11] = AddStaticVehicleEx(523,632.40002441,-610.50000000,16.00000000,0.00000000,-1,-1,15); //HPV1000
    pVehicles[12] = AddStaticVehicleEx(523,635.09997559,-610.50000000,16.00000000,0.00000000,-1,-1,15); //HPV1000
   
    //Objects
    CreateObject(3928,553.48144531,-590.88085938,22.13276482,0.00000000,0.00000000,0.00000000); //object(helipad) (1)
    CreateObject(3934,613.20001221,-576.90002441,25.20000076,0.00000000,0.00000000,0.00000000); //object(helipad01) (1)
    CreateObject(3934,612.40002441,-599.90002441,21.79999924,0.00000000,0.00000000,0.00000000); //object(helipad01) (2)
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);

        if(GetVehicleModel(vehicleid) == pVehicles[0] || GetVehicleModel(vehicleid) == pVehicles[1] || GetVehicleModel(vehicleid) == pVehicles[2] || GetVehicleModel(vehicleid) == pVehicles[3] || GetVehicleModel(vehicleid) == pVehicles[4] || GetVehicleModel(vehicleid) == pVehicles[5] || GetVehicleModel(vehicleid) == pVehicles[6] || GetVehicleModel(vehicleid) == pVehicles[7] || GetVehicleModel(vehicleid) == pVehicles[8] || GetVehicleModel(vehicleid) == pVehicles[9] || GetVehicleModel(vehicleid) == pVehicles[10] || GetVehicleModel(vehicleid) == pVehicles[11] || GetVehicleModel(vehicleid) == pVehicles[12])
        {
            if(GetPlayerTeam(playerid) = TEAM_ROB || GetPlayerTeam(playerid) == TEAM_TER)
            {
                SendClientMessage(playerid, COLOR_RED, "[INFO] Your wanted level has increased by 4 for stealing a police vehicle");
                IncreaseWantedLevel(playerid, 4);
            }
        }
    }
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}

stock IncreaseWantedLevel(playerid, amount)
{
    new level = GetPlayerWantedLevel(playerid);
    SetPlayerWantedLevel(playerid, level+amount);
    return 1;
}
Errors:
Код:
C:\Users\Keegan\Desktop\gamemodes\CSCNR.pwn(67) : error 032: array index out of bounds (variable "pVehicles")
C:\Users\Keegan\Desktop\gamemodes\CSCNR.pwn(149) : error 075: input line too long (after substitutions)
C:\Users\Keegan\Desktop\gamemodes\CSCNR.pwn(151) : error 029: invalid expression, assumed zero
C:\Users\Keegan\Desktop\gamemodes\CSCNR.pwn(151) : error 032: array index out of bounds (variable "pVehicles")
C:\Users\Keegan\Desktop\gamemodes\CSCNR.pwn(151) : warning 217: loose indentation
C:\Users\Keegan\Desktop\gamemodes\CSCNR.pwn(151) : error 029: invalid expression, assumed zero
C:\Users\Keegan\Desktop\gamemodes\CSCNR.pwn(151) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Errors.
Please help.
Reply
#2

Your array is 12 elements long, so it has indexes from 0 to 11. 12 index doesn't exist

@down
No, I meant to make him read the wiki about arrays.
Reply
#3

Misuir meant to change:

pawn Код:
new pVehicles[12];
To

pawn Код:
new pVehicles[13];
Reply
#4

Nevermind, my mistake.
Reply
#5

That's because of too long line in OnPlayerStateChange, the one that checks vehicles
Reply
#6

pawn Код:
if(GetVehicleModel(vehicleid) == pVehicles[0] || GetVehicleModel(vehicleid) == pVehicles[1] || GetVehicleModel(vehicleid) == pVehicles[2] || GetVehicleModel(vehicleid) == pVehicles[3] || GetVehicleModel(vehicleid) == pVehicles[4] || GetVehicleModel(vehicleid) == pVehicles[5] || GetVehicleModel(vehicleid) == pVehicles[6] || GetVehicleModel(vehicleid) == pVehicles[7] || GetVehicleModel(vehicleid) == pVehicles[8] || GetVehicleModel(vehicleid) == pVehicles[9] || GetVehicleModel(vehicleid) == pVehicles[10] || GetVehicleModel(vehicleid) == pVehicles[11] || GetVehicleModel(vehicleid) == pVehicles[12])
        {
// to
if(GetVehicleModel(vehicleid) == pVehicles[12])
        {
and change new pVehicles[12] to pVehicles[13];
Simple as that.
Reply
#7

No, it's error from other line. The line is too long, exchange it for (at least) 2 overlapping if's
pawn Код:
if(GetVehicleModel(vehicleid) == pVehicles[0] || GetVehicleModel(vehicleid) == pVehicles[1] || GetVehicleModel(vehicleid) == pVehicles[2] || GetVehicleModel(vehicleid) == pVehicles[3] || GetVehicleModel(vehicleid) == pVehicles[4] || GetVehicleModel(vehicleid) == pVehicles[5] || GetVehicleModel(vehicleid) == pVehicles[6] || GetVehicleModel(vehicleid) == pVehicles[7] || GetVehicleModel(vehicleid) == pVehicles[8] || GetVehicleModel(vehicleid) == pVehicles[9] || GetVehicleModel(vehicleid) == pVehicles[10] || GetVehicleModel(vehicleid) == pVehicles[11] || GetVehicleModel(vehicleid) == pVehicles[12])
e:
You guys are fast
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)