I need some suggestions about [MAX_VEHICLES]
#1

So today I started to think about one thing, well Im going to make variable assigned to vehicle like Water[MAX_VEHICLES]; , but I will use it only on certain vehicle and their IDs is one after another.

So now we start to talk about optimization, and I started to think why does I need to use it for all vehicles ( 2000 ), if I need it only for 5 cars, so I could make Water[5]; and I guess everyone already seen how much cells I could save ( 1995 ).

So I need some advice how to assign only on these 5 cars.

I want try like this, not tested I just write it here on forum
pawn Код:
new Water[5];
But how to in place where I need this value I could make that its read like GetPlayerVehicleID(... if(Water[..] > 0) ..


I know its posibble, just my brains dont work at morning, and I can only imaginate how much memory I can save.
Reply
#2

I don't really understand what you mean. Something like this?
pawn Код:
#define MAX_WATER_VEHICLES 5

new
    Water[ MAX_WATER_VEHICLES ] = { INVALID_VEHICLE_ID, ... }
;

public OnGameModeInit( )
{
    new
        i = 0
    ;
   
    Water[ i++ ] = AddStaticVehicle( 400, 0.0, 0.0, 3.0, 0.0, -1, -1 ); // 1
    Water[ i++ ] = AddStaticVehicle( 400, 0.0, 0.0, 3.0, 0.0, -1, -1 ); // 2
    Water[ i++ ] = AddStaticVehicle( 400, 0.0, 0.0, 3.0, 0.0, -1, -1 ); // 3
    Water[ i++ ] = AddStaticVehicle( 400, 0.0, 0.0, 3.0, 0.0, -1, -1 ); // 4
    Water[ i++ ] = AddStaticVehicle( 400, 0.0, 0.0, 3.0, 0.0, -1, -1 ); // 5
}

stock IsPlayerInWaterVehicle( playerid )
{
    new
        vehicleid = GetPlayerVehicleID( playerid )
    ;
   
    if ( !vehicleid )
        return false;
   
    for ( new i = 0; i < MAX_WATER_VEHICLES; i++ )
    {
        if ( Water[ i ] == vehicleid )
            return true;
    }
   
    return false;
}
Reply
#3

yes, something like that, just in your example where you writed [ i++ ] should need to be vehicleid
like OnInit Water[somehow get id] = 100;

and later
by Getting vehicle ID know how much water have in it, and check only these 5 cars, not all MAX_VEHICLES.
Reply
#4

Hmm, but this anyway just say that Im in water car

Same way I have made, FireCar[0] = AddStaticVeh... , and its return veh id , not that, that in it have 100 waters
How could I read if that water vehicle have 100 waters in it?
Reply
#5

I'm really not sure what you mean this time. Here's code to count the number of water vehicles with players inside.

pawn Код:
stock GetNumberOfActiveWaterVehicles( )
{
    new
        count = 0,
        playerid,
        i
    ;
   
    for ( playerid = 0; playerid < MAX_PLAYERS; playerid++ )
    {
        if ( !IsPlayerConnected( playerid ) )
            continue;
       
        for ( i = 0; i < MAX_WATER_VEHICLES; i++ )
        {
            if ( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER && GetPlayerVehicleID( playerid ) == Water[ i ] )
                ++count;
        }
    }
   
    return count;
}
Reply
#6

I needed a way how to know how much water is in car
not using
pawn Код:
new WaterLevelInCar[MAX_VEHICLES];
but using this
pawn Код:
new WaterLevelInCar[5]; // because I have only 5 fire trucks
But I figure out it by self.

like
pawn Код:
new water;
if(GetPlayerVehicleID(playerid) == FireTruck[0])
{
water = WaterLevelInCar[0];
}

I dont know maybe this has been discovered before, but I guess I found good way how to save memory.
Reply
#7

pawn Код:
new WaterLevelInCar[MAX_WATER_VEHICLES];

stock GetWaterLevel(vehicleid)
{
    for(new i; i < MAX_WATER_VEHICLES; i++)
    {
        if(Water[i] == vehicleid)
        {
            return WaterLevelInCar[i];
        }
    }

    return 0;
}

stock SetWaterLevel(vehicleid, waterlevel)
{
    for(new i; i < MAX_WATER_VEHICLES; i++)
    {
        if(Water[i] == vehicleid)
        {
            WaterLevelInCar[i] = waterlevel;

            return 1;
        }
    }

    return 0;
}
Reply
#8

Thank you , but I already made same way by self
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)