SERVER - MAX_VEHICLES exceed
#1

Hello guys. I don't know why but on my server after 5-6 hours, when someone try to take a vehicle with /car command that will crash:

pawn Код:
[18:41:44] [debug] Run time error 4: "Array index out of bounds"
[18:41:44] [debug]  Accessing element at index 65535 past array upper bound 1999
I tried to remove all the vehicles from the server and the private vehicles so the vehicles from server will be spawned just with /car command but nothing works. I don't fuc%!@ know what to do...

pawn Код:
CMD:car( playerid, params[ ] )
{
    new
        Car[ 30 ],
        Color[ 2 ]
    ;
    if ( sscanf( params, "s[30]D(-1)D(-1)", Car, Color[ 0 ], Color[ 1 ] ) )
        return SendClientMessage( playerid, COLOR_ULTRARED, "USAGE: {33CCFF}/car [Name/Model] [Color1] [Color2]" );

    if ( IsPlayerInAnyVehicle( playerid ) )
        return SendError( playerid, "You are already in a vehicle!" );

    new sCarModel;
    if ( IsNumeric( Car ) )
        sCarModel = strval( Car );
    else
        sCarModel = GetVehicleModelIDFromName( Car );

    if ( sCarModel < 400 || sCarModel > 611 )
        return SendError( playerid, "Invalid vehicle model/name!" );

    if ( Color[ 0 ] == -1 )
        Color[ 0 ] = random( 250 );

    if ( Color[ 1 ] == -1 )
        Color[ 1 ] = random( 250 );

    if ( PlayerInfo[ playerid ][ pCar ] != -1 )
        CarDeleter( PlayerInfo[ playerid ][ pCar ] );

    new Float:cPos[ 4 ], LVehicleID, int1;

    GetPlayerPos( playerid, cPos[ 0 ], cPos[ 1 ], cPos[ 2 ] );
    GetPlayerFacingAngle( playerid, cPos[ 3 ] );

    int1 = GetPlayerInterior( playerid );
    LVehicleID = AddStaticVehicleEx( sCarModel, cPos[ 0 ]+3, cPos[ 1 ], cPos[ 2 ], cPos[ 3 ], Color[ 0 ], Color[ 1 ], -1 );
    LinkVehicleToInterior( LVehicleID, int1 );

    SetVehicleNumberPlate( LVehicleID, ""R"S"W"tun"O"T" );
    SetVehicleVirtualWorld( LVehicleID, GetPlayerVirtualWorld( playerid ) );

    PutPlayerInVehicle( playerid, LVehicleID, 0 );

    PlayerInfo[ playerid ][ pCar ] = LVehicleID;

    DestroyNeons( playerid );
    for ( new Any = 0; Any < MAX_VEHICLE_ATTACHED_OBJECTS; Any++ )
            if ( IsValidDynamicObject( p_Object[ playerid ][ Any ] ) )
                DestroyDynamicObject( p_Object[ playerid ][ Any ] );

    FormatMSG( playerid, ~1, "You have spawned a \"{FF9900}%s"W"\" {FF0000}(Model: %d). "W"Colors {FF9900}(%d, %d)", vNames[ sCarModel-400 ], sCarModel, Color[ 0 ], Color[ 1 ] );
    return ( 1 );
}
public OnPlayerDisconnect( playerid, reason )
{
    if ( PlayerInfo[ playerid ][ pCar ] != -1 )
        CarDeleter( PlayerInfo[ playerid ][ pCar ] );


}
Reply
#2

If you don't use the latest version (4.12), then update it: https://github.com/Zeex/samp-plugin-...ases/tag/v4.12

Re-compile your script with debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info

Run your server and when it gives the runtime error again, it may print the line was caused at.
Reply
#3

I don't need the line... it's all about exceding the MAX_VEHICLES limit...
Reply
#4

65535 is INVALID_VEHICLE_ID your problem is here or at least part of it

LVehicleID = AddStaticVehicleEx( sCarModel, cPos[ 0 ]+3, cPos[ 1 ], cPos[ 2 ], cPos[ 3 ], Color[ 0 ], Color[ 1 ], -1);

You need to use CreateVehicle() instead but there are some other problems your dynamic system design is terrible let me show you a simple example that will work for almost any dynamic system.

You will notice some very important design aspects.

pawn Код:
// Hearts - simple dynamic system concept

#include <a_samp>

// We'll use ZCMD
#include <zcmd>

// We always need to define how many elements a dynamic system contains
#define         MAX_HEARTS          1000

// Heart object for this dynamic system
#define         HEART_OBJECT        1240

// The drawdistance for hearts
#define         HEART_DRAW_DIST     150.0

// This is a bounds checking macro to make sure that referenced array elements are not out of bounds
#define HeartBounds(%0,%1); \
    if(%0 < 0 || %0 > MAX_HEARTS) \
    { \
        printf("Array Out Of Bounds Index: %i", %1); \
        return 0; \
    }

// We need to define an enum which is basically the structure of the values that will be saved in the dynamic system
enum HEARTINFO
{
    HeartObject,
    Float:xPos,
    Float:yPos,
    Float:zPos,
}

// Create a new variable to store the heart information
new HeartData[MAX_HEARTS][HEARTINFO];

// When any dynamic system initializes we need to set any required default values in this case it is the heartobject which
// determines if the dynamic element exists
public OnFilterScriptInit()
{
    // Loop through each element
    for(new i = 0; i < MAX_HEARTS; i++)
    {
        // This marks the element as unused
        HeartData[i][HeartObject] = INVALID_OBJECT_ID;
    }
    return 1;
}

// Destroy any created hearts
public OnFilterScriptExit()
{
    for(new i = 0; i < MAX_HEARTS; i++)
    {
        if(HeartData[i][HeartObject] != INVALID_OBJECT_ID) DestroyObject(HeartData[i][HeartObject]);
    }
    return 1;

}

// Add a new heart
stock AddHeart(Float:x, Float:y, Float:z)
{
    // Loop through hearts for a free slot
    for(new i = 0; i < MAX_HEARTS; i++)
    {
        // Slot was not free continue
        if(HeartData[i][HeartObject] != INVALID_OBJECT_ID) continue;

        // We have a free slot create the new heart element
        HeartData[i][HeartObject] = CreateObject(HEART_OBJECT, x, y, z, 0.0, 0.0, 0.0, HEART_DRAW_DIST);

        // Set any additional data
        HeartData[i][xPos] = x;
        HeartData[i][yPos] = y;
        HeartData[i][zPos] = z;
       
        // Return the id of the heart that was created
        return HeartData[i][HeartObject];
    }
    // There are too many hearts
    print("ERROR: Tried to add too many hearts");
    return INVALID_OBJECT_ID;
}

// Remove a heart
stock RemoveHeart(hid)
{
    // Check the bounds to make sure they are valid
    HeartBounds(hid, "Bounds error: RemoveHeart");
   
    // Does the heart exist?
    if(HeartData[hid][HeartObject] != INVALID_OBJECT_ID)
    {
        // Destroy heart
        DestroyObject(HeartData[hid][HeartObject]);

        // We only need to reset the heart objectid this element can now be re-used
        HeartData[hid][HeartObject] = INVALID_OBJECT_ID;
        return 1;
    }
    // Return 0 heart did not exist
    return 0;
}

// Command for adding a heart
CMD:addheart(playerid, arg[])
{
    // Get the players position
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    z += 1.0;
   
    // Adding the heart was not success
    if(AddHeart(x, y, z) == -1) return SendClientMessage(playerid, 0xFF0000FF, "There are too many hearts");

    // Successfully added!
    SendClientMessage(playerid, -1, "Added a new heart!");
    return 1;
}

// Remove heart
CMD:removeheart(playerid, arg[])
{
    // Remove was successful
    if(RemoveHeart(strval(arg))) return SendClientMessage(playerid, -1, "Heart Removed");
    // That heart does not exist!
    SendClientMessage(playerid, -1, "Heart does not exist");
    return 1;
}

// Checks if the player is near a heart
CMD:nearheart(playerid, arg[])
{
    // Count how many hearts the player is near
    new heartcount;

    // Loop throuugh hearts
    for(new i = 0; i < MAX_HEARTS; i++)
    {
        // Heart does not exist
        if(HeartData[i][HeartObject] == INVALID_OBJECT_ID) continue;

        // Player was in range of a heart increment the heart count
        if(IsPlayerInRangeOfPoint(playerid, 5.0, HeartData[i][xPos], HeartData[i][yPos], HeartData[i][zPos])) heartcount++;
    }

    // There were hearts found show the player how many
    if(heartcount)
    {
        new line[128];
        format(line, sizeof(line), "You are near %i hearts!", heartcount);
        SendClientMessage(playerid, -1, line);
    }
    else SendClientMessage(playerid, 0xFF0000FF, "You are not near any hearts!");
   
    return 1;
}
Reply
#5

Do you even know what "Index out of bounds" is?

pawn Код:
new
    Some_Vehicle[ MAX_VEHICLES ]
;
You can use indexes 0-1999

However, it passes 65535 (INVALID_VEHICLE_ID) when the max value it could get is MAX_VEHICLES - 1.

You do not need the line? Okay, have fun searching what caused it..

@Pottus: Even if AddStaticVehicleEx returned INVALID_VEHICLE_ID because it reached the limit or due to an invalid modelid, he does not pass LVehicleID (which may be is INVALID_VEHICLE_ID) into any array to that command so the mistake is somewhere else.
Reply
#6

So you guys think that one "command" or "line" with an invalid vehicle id will fuc& up entire server's vehicles ? I'm getting that runtime error every time i want to create a vehicle.

@[uL]Pottus that kind of scripting it's for n00bs to understand functions. My style of scripting is more different than yours.
Reply
#7

That is because as I mentioned your dynamic system design is poor I've provided you with an example of a dynamic system it doesn't matter what kind of system you make it's almost always the same. However for vehicles there is a small difference you won't need to do any look up for a free slot since creating a vehicle will return the vehicleid which can be used to reference the array index element.

@Edit No it's not for noobs to understand functions its for people to understand how a dynamic system operates which you clearly have an obtuse and obfuscated design ideology.
Reply
#8

Just stop writing shits My whole server it's scripted better than what you're trying to show me. I'm telling you again. Your script it's just basic/n00b scripted
Reply
#9

Well I'm done trying to help you, I'm sure Konstantinos won't care either with that attitude you wouldn't be asking for help if you knew what you were doing obviously you claim that you do but after looking at your code the quality certainly does not reinforce your assertions.
Reply
#10

Quote:
Originally Posted by nGen.SoNNy
Посмотреть сообщение
Just stop writing shits My whole server it's scripted better than what you're trying to show me. I'm telling you again. Your script it's just basic/n00b scripted
What an ungrateful idiot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)