SA-MP Forums Archive
Another question for today, CreateVehicle and GetPlayerVehicleID - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Another question for today, CreateVehicle and GetPlayerVehicleID (/showthread.php?tid=214640)



Another question for today, CreateVehicle and GetPlayerVehicleID - _Tommy - 21.01.2011

Another thing that I just could not set up right is the ID which my system store in each vehicle's stats.
This is my LoadVhicles function which gets called OnGameModeInit:
pawn Код:
LoadVehicles()
{
    totalVehicles = 0;
    mysql_query("SELECT * FROM `Vehicles`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Query))
        {
            sscanf(Query, "e<p<|>ddffffddddds[10]d>", Vehicles[totalVehicles]);
            SetVehicleNumberPlate(CreateVehicle(Vehicles[totalVehicles][Model],Vehicles[totalVehicles][PosX],Vehicles[totalVehicles][PosY],Vehicles[totalVehicles][PosZ],Vehicles[totalVehicles][Angle],Vehicles[totalVehicles][Color1],Vehicles[totalVehicles][Color2], -1), Vehicles[totalVehicles][Plate]);
            LinkVehicleToInterior(totalVehicles, 0);
            SetVehicleVirtualWorld(totalVehicles, 0);

            totalVehicles++;
        }
    }
    mysql_free_result();
    print("\n");
    printf("SERVER: Loaded %d MySQL vehicles successfully.", totalVehicles);
    return 1;
}
It loads all the vehicles as I want, but something goes wrong with my "VehicleID". There is my enum:
pawn Код:
enum VehicleData
{
    VehicleID,
    Model,
    Float: PosX,
    Float: PosY,
    Float: PosZ,
    Float: Angle,
    Color1,
    Color2,
    IsOwned,
    OwnerID,
    Faction,
    Plate,
    Locked
};
new Vehicles[MAX_VEHICLES][VehicleData];
new totalVehicles = 0;
My /getcarid whitch shows me wrong info:
pawn Код:
command(getcarid, playerid, params[])
{
    #pragma unused params
    if(!IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, COLOR_BRIGHTRED, "You are not in a vehicle, nothing was gotten!");

    new id = GetPlayerVehicleID(playerid);
    format(Query, sizeof(Query), "Server Vehicle ID: %d, Database Vehicle ID: %d", id, Vehicles[id][VehicleID]);
    SendClientMessage(playerid, COLOR_BRIGHTRED, Query);
    return 1;
}
It doesn't show me the right information, for example there is no carid 0 in my server, whitch I just don't understand how is that possible.. Its like everything the command shows is +1, the server vehicle id, and the stats loaded from the database, for example if I enter into my first spawned vehicle witch is ID 4 in my database(and the next vehicle's ID is 7), and the server vehicle ID should be 0, it shows me that the server vehicle id is 1(Instead of 0), and the database vehicle ID is 7(the next one in the list).

Can somebody help me fix this problem? I've been trying for a few hours without any luck.


Re: Another question for today, CreateVehicle and GetPlayerVehicleID - _Tommy - 21.01.2011

BUMP. Anyone? No idea how to go on..


Re: Another question for today, CreateVehicle and GetPlayerVehicleID - Vince - 21.01.2011

Vehicleids (unlike playerids) start at 1, not zero. This is done like that so you can do:

pawn Код:
if(GetPlayerVehicleID(playerid) == 0)
{
    // Not in a vehicle
}



Re: Another question for today, CreateVehicle and GetPlayerVehicleID - _Tommy - 21.01.2011

I was sure it starts with 0.. Well, so what's the problem in my code? Why it keeps getting the +1 vehicle id information, instead of the current one?


Re: Another question for today, CreateVehicle and GetPlayerVehicleID - _Tommy - 22.01.2011

Bump. Anyone?