Vehicle ID Issue (REP+)
#1

I've persevered from my previous issue but now there's a new one. One with ID's. Because I'm working with three different ID's here, it's sort of difficult to pinpoint which one I should be using where. I'm working with the ROW when I load from MySQL, the DB ID of the vehicle, and the VID in game.

This is my load function: Rows are starting at zero bear in mind.

PHP код:
forward InitiateVehicles();
public 
InitiateVehicles()
{
    new 
rowsfieldsvehicles;
    
    
cache_get_data(rowsfields);
    for(new 
rowrow MAX_DYN_VEHICLESrow++)
    {
        
Vehicle[row][VehicleDatabaseID] = cache_get_field_content_int(row"id"SQL);       
        
Vehicle[row][Model] = cache_get_field_content_int(row"Model"SQL);
        
Vehicle[row][VehiclePos][0] = cache_get_field_content_float(row"X"SQL);
        
Vehicle[row][VehiclePos][1] = cache_get_field_content_float(row"Y"SQL);
        
Vehicle[row][VehiclePos][2] = cache_get_field_content_float(row"Z"SQL);
        
Vehicle[row][VehiclePos][3] = cache_get_field_content_float(row"A"SQL);
        
Vehicle[row][VehicleVW] = cache_get_field_content_int(row"VW"SQL);
        
Vehicle[row][VehicleInt] = cache_get_field_content_int(row"Int"SQL);
        
Vehicle[row][VehicleColour][0] = cache_get_field_content_int(row"Colour1"SQL);
        
Vehicle[row][VehicleColour][1] = cache_get_field_content_int(row"Colour2"SQL);
        
Vehicle[row][VehicleGroup] = cache_get_field_content_int(row"Group"SQL);
        
Vehicle[row][Siren] = cache_get_field_content_int(row"Siren"SQL);
        if(
Vehicle[row][VehiclePos][0] != 0.00000 && Vehicle[row][VehiclePos][1] != 0.00000 && Vehicle[row][VehiclePos][2] != 0.00000)
        {
            
Vehicle[row][VehID] = CreateVehicle(Vehicle[row][Model], Vehicle[row][VehiclePos][0], Vehicle[row][VehiclePos][1], Vehicle[row][VehiclePos][2], Vehicle[row][VehiclePos][3], Vehicle[row][VehicleColour][0], Vehicle[row][VehicleColour][1], -1Vehicle[row][Siren]);
            
SetVehicleVirtualWorld(Vehicle[row][VehID], Vehicle[row][VehicleVW]);
            
LinkVehicleToInterior(Vehicle[row][VehID], Vehicle[row][VehicleInt]);
        }
        
printf("%d | %d | %d"rowVehicle[row][VehicleDatabaseID], Vehicle[row][VehID]);
        
vehicles++;
    }
    switch(
vehicles)
    {
        case 
0printf("[SCRIPT-LOAD/ERR] The script initiated 0 vehicles."vehicles);
        default: 
printf("[SCRIPT-LOAD] The script has initiated %d vehicles"vehicles);
    }

This successfully creates vehicles and the print that I put in looks like this for the two cars I have created: (I've laid it out in a table)

pawn Код:
ROW|DID|VID
[18:53:18] 0 | 1 | 1
Perfect, it does what it's suppose to do. But when I do /editvehicle 1 spawn (which is designed to move vehicle ID 1's spawn and save it's new location) it moves vehicle ID 2, and saves it's coordinates to DBID 2 in the database. The possible issues I'm having are probably with wrongly used ID's somewhere in the /editvehicle command.

Here you go: (I'll only show the 'spawn' option just to spare you a headache.)

PHP код:
CMD:editvehicle(playeridparams[])
{
    new 
idusage[16], amount;
    if(
sscanf(params"ds[16]D(0)"idusageamount)) 
    {
        if(
Player[playerid][AdminLevel] >= 5)
        {
            
SendClientMessage(playeridWHITE"USAGE: /editvehicle [id] [usage] [(optional) amount]");
            return 
SendClientMessage(playeridGREY"Usages: spawn, colour(1-2), group, delete");
        }
    }
    else if(
Player[playerid][AdminLevel] >= 5)
    {
        if(
id || id MAX_VEHICLES) return SendClientMessage(playeridWHITE"That is not a valid vehicle ID!");
        if(
Vehicle[id][VehicleDatabaseID] < 1) return SendClientMessage(playeridWHITE"That is not a valid dynamic vehicle ID!");
        Array[
0] = 0;
        if(
strcmp(usage"spawn"true) == 0)
        {
            new 
Float:Pos[4];
            
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
            
GetPlayerFacingAngle(playeridPos[3]);
            
Vehicle[id][VehiclePos][0] = Pos[0];
            
Vehicle[id][VehiclePos][1] = Pos[1];
            
Vehicle[id][VehiclePos][2] = Pos[2];
            
Vehicle[id][VehiclePos][3] = Pos[3];
            
Vehicle[id][VehicleVW] = GetPlayerVirtualWorld(playerid);
            
Vehicle[id][VehicleInt] = GetPlayerInterior(playerid);
            
format(Array, sizeof(Array), "You have moved the spawn of vehicle %d"id);
            
SendClientMessage(playeridWHITE, Array);
            
format(Array, sizeof(Array), "[/EDITVEHICLE] %s has moved the spawn of vehicle %d to X: %f, Y: %f, Z: %f"GetName(playerid), idPos[0], Pos[1], Pos[2]);
        }
        else
        {
            
SendClientMessage(playeridWHITE"USAGE: /editvehicle [id] [usage] [(optional) amount]");
            return 
SendClientMessage(playeridGREY"Usages: spawn, colour(1-2), group, delete");
        }
        
Log(4, Array);
        
RespawnVehicle(id);
        
SaveVehicle(id);
    }
    else 
SendClientMessage(playeridWHITE"You are not authorized to preform this command.");
    return 
1;

Any reason why the ID's are getting mismatched and confused?
Reply
#2

because rows starts from 0 not 1 so you need use [id - 1]
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
because rows starts from 0 not 1 so you need use [id - 1]
Thank you! It works! But would I have to do this every time I want to mess with my dynamic vehicle system or could I just make it so the ID is 'corrected' when they initiate?

Edit: Also, say I have an admin spawned vehicle (different from a dynamic vehicle) that is occupying slot 1. I also have a dynamic vehicle occupying slot 2. If I delete the admin spawned vehicle, and then use the command /editvehicle, my dynamic vehicle will respawn to ID 1. I just tested this in game, but the script still thinks it has ID 2.

Here's my respawn function:

PHP код:
RespawnVehicle(id

    
DestroyVehicle(Vehicle[id][VehID]); 
    if(
Vehicle[id][VehiclePos][0] != 0.00000 && Vehicle[id][VehiclePos][1] != 0.00000 && Vehicle[id][VehiclePos][2] != 0.00000
    { 
        
Vehicle[id][VehID] = CreateVehicle(Vehicle[id][Model], Vehicle[id][VehiclePos][0], Vehicle[id][VehiclePos][1], Vehicle[id][VehiclePos][2], Vehicle[id][VehiclePos][3], Vehicle[id][VehicleColour][0], Vehicle[id][VehicleColour][1], -1Vehicle[id][Siren]); 
        
SetVehicleVirtualWorld(Vehicle[id][VehID], Vehicle[id][VehicleVW]); 
        
LinkVehicleToInterior(Vehicle[id][VehID], Vehicle[id][VehicleInt]); 
    } 
    return 
1

Reply
#4

Here must be too (id-1)
Reply
#5

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Here must be too (id-1)
It is:

PHP код:
else if(Player[playerid][AdminLevel] >= 5)
    {
        if(
id || id MAX_VEHICLES) return SendClientMessage(playeridWHITE"That is not a valid vehicle ID!");
        if(
Vehicle[id][VehID] > 1) return SendClientMessage(playeridWHITE"That is not a valid dynamic vehicle ID!");
        Array[
0] = 0;
        
id id 1// Here we subtract the ID the player put into the command.
        
if(strcmp(usage"spawn"true) == 0)
        {
            if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridWHITE"You must be in a vehicle to edit the spawn!");
            new 
Float:Pos[4];
            
GetVehiclePos(GetPlayerVehicleID(playerid), Pos[0], Pos[1], Pos[2]);
            
GetVehicleZAngle(GetPlayerVehicleID(playerid), Pos[3]);
            
Vehicle[id][VehiclePos][0] = Pos[0];
            
Vehicle[id][VehiclePos][1] = Pos[1];
            
Vehicle[id][VehiclePos][2] = Pos[2];
            
Vehicle[id][VehiclePos][3] = Pos[3];
            
Vehicle[id][VehicleVW] = GetPlayerVirtualWorld(playerid);
            
Vehicle[id][VehicleInt] = GetPlayerInterior(playerid);
            
format(Array, sizeof(Array), "You have moved the spawn of vehicle %d"id 1);
            
SendClientMessage(playeridWHITE, Array);
            
format(Array, sizeof(Array), "[/EDITVEHICLE] %s has moved the spawn of vehicle %d to X: %f, Y: %f, Z: %f"GetName(playerid), id 1Pos[0], Pos[1], Pos[2]);
        }
        else
        {
            
SendClientMessage(playeridWHITE"USAGE: /editvehicle [id] [usage] [(optional) amount]");
            return 
SendClientMessage(playeridGREY"Usages: spawn, colour(1-2), group, delete");
        }
        
Log(4, Array);
        
RespawnVehicle(id); // Here we respawn that ID.
        
SaveVehicle(id); 
Reply
#6

but id is 0 ( slot 1 ) Vehicle[id][VehID] so i dont understand you
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
but id is 0 ( slot 1 ) Vehicle[id][VehID] so i dont understand you
Say I have an NRG that is ID 1, it is not a dynamic vehicle. I have a sultan that is ID 2, it is a dynamic vehicle. I delete the NRG and respawn the sultan. The sultan is now ID 1, but the server still thinks it's ID 2. if I edit ID 1, it will update in the database but not respawn the car. If I edit ID 2, it won't update in the database but it will respawn the car.
Reply
#8

Show how you create this nrg and destroy
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Show how you create this nrg and destroy
PHP код:
CMD:spawnvehicle(playeridparams[]) 
{
    if(
Player[playerid][AdminLevel] >= 2
    {
        new 
vehiclecolour[2];
        if(
sscanf(params"iD(0)D(0)"vehiclecolour[0], colour[1])) return SendClientMessage(playeridWHITE"SYNTAX: /spawnvehicle [model] [(optional) colour] [(optional) colour]");
        else if(!(
400 <= vehicle <= 611)) return SendClientMessage(playeridWHITE"You specified an invalid model ID. (IDs start at 400, and end at 611).");
        else if(!(
<= colour[0] <= 255 && <= colour[1] <= 255)) return SendClientMessage(playeridWHITE"You specified an invalid colour ID. (IDs start at 0, and end at 255).");
        else for(new 
isizeof(AdminVehicles); i++) if(>= MAX_ADMIN_VEHICLES) return SendClientMessage(playeridWHITE"The maximum limit of 50 spawned vehicles has been reached.");
        else if(
AdminVehicles[i] == INVALID_VEHICLE_ID
        {
            new 
Float:Pos[4];
            
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
            
GetPlayerFacingAngle(playeridPos[3]);
            
AdminVehicles[i] = CreateVehicle(vehiclePos[0], Pos[1], Pos[2], Pos[3], colour[0], colour[1], -1);
            
LinkVehicleToInterior(AdminVehicles[i], GetPlayerInterior(playerid));
            
SetVehicleVirtualWorld(AdminVehicles[i], GetPlayerVirtualWorld(playerid));
            return 
SendClientMessage(playeridWHITE"You have successfully created a vehicle.");
        }
    }
    else 
SendClientMessage(playeridWHITE"You are not authorized to use that command.");
    return 
1;

PHP код:
CMD:destroyvehicles(playeridparams[])
{
    if(
Player[playerid][AdminLevel] >= 4
    {
        for(new 
0sizeof(AdminVehicles); i++) 
        {
            if(
AdminVehicles[i] != INVALID_VEHICLE_ID
            {
                
DestroyVehicle(AdminVehicles[i]);
                
AdminVehicles[i] = INVALID_VEHICLE_ID;
            }
        }
        
SendClientMessage(playeridWHITE"You have successfully destroyed all administrative spawned vehicles.");
    }
    else 
SendClientMessage(playeridWHITE"You are not authorized to preform this command.");
    return 
1;

Reply
#10

All what you need to save is databaseID ( Vehicle[row][VehicleDatabaseID] DID ) not vehicleID ( Vehicle[id][VehID] VID )
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)