Vehicle Saving Issue (REP+)
#1

So I'm making a dynamic vehicle system. I hope I give enough information to answer my question but not too much to be a headache. Below we have some of my /editvehicle command.

pawn Код:
CMD:editvehicle(playerid, params[])
{
    new id, usage[16], amount;
    if(sscanf(params, "ds[16]D(0)", id, usage, amount))
    {
        if(Player[playerid][AdminLevel] >= 4)
        {
            SendClientMessage(playerid, WHITE, "USAGE: /editvehicle [id] [usage] [(optional) amount]");
            return SendClientMessage(playerid, GREY, "Usages: spawn, colour(1-2), group, delete");
        }
    }
    else if(Player[playerid][AdminLevel] >= 4)
    {
        if(id < 0 || id > MAX_DYN_VEHICLES) return SendClientMessage(playerid, WHITE, "That is not a valid vehicle ID!");
        Array[0] = 0;
        if(strcmp(usage, "spawn", true) == 0)
        {
            new Float:Pos[4];
            GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
            GetPlayerFacingAngle(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);
            SendClientMessage(playerid, WHITE, Array);

            format(Array, sizeof(Array), "[/EDITVEHICLE] %s has moved the spawn of vehicle %d to X: %f, Y: %f, Z: %f", GetName(playerid), id, Pos[0], Pos[1], Pos[2]);
        }
        else
        {
            SendClientMessage(playerid, WHITE, "USAGE: /editvehicle [id] [usage] [(optional) amount]");
            return SendClientMessage(playerid, GREY, "Usages: spawn, colour(1-2), group, delete");
        }

        Log(4, Array);
        SaveVehicle(Vehicle[id][VehID]);
        RespawnVehicle(Vehicle[id][VehID]);
    }
    else SendClientMessage(playerid, WHITE, "You are not authorized to preform this command.");
    return 1;
}
The car deletes like it's suppose to do with RespawnVehicle, but it doesn't come back. Probably because the database doesn't update but I'll show you the RespawnVehicle function:

pawn Код:
RespawnVehicle(id)
{
    DestroyVehicle(id);
    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], -1, Vehicle[id][Siren]);
        SetVehicleVirtualWorld(Vehicle[id][VehID], Vehicle[id][VehicleVW]);
        LinkVehicleToInterior(Vehicle[id][VehID], Vehicle[id][VehicleInt]);
    }
    return 1;
}
And yes I know about SetVehicleToRespawn but this gives me more freedom.

But when I edit the spawn of the car, the database doesn't update. I'm not sure if the ID's are getting confused or what exactly is happening. But does anyone see why this would be happening?

I'll throw in my save function just incase.

pawn Код:
SaveVehicle(id)
{
    Array[0] = 0;

    format(Array, sizeof Array, "UPDATE `vehicles` SET \
        `Model` = '%d', `X` = '%f', `Y` = '%f', `Z` = '%f', `A` = %f, `VW` = '%d', `Int` = '%d', `Colour1` = '%d', `Colour2` = '%d', `Group` = '%d', `Siren` = '%d' WHERE `id` = '%d'"
,
        Vehicle[id][Model], Vehicle[id][VehiclePos][0], Vehicle[id][VehiclePos][1], Vehicle[id][VehiclePos][2], Vehicle[id][VehiclePos][3], Vehicle[id][VehicleVW], Vehicle[id][VehicleInt],
        Vehicle[id][VehicleColour][0], Vehicle[id][VehicleColour][1], Vehicle[id][VehicleGroup], Vehicle[id][Siren], Vehicle[id][VehicleDatabaseID]
    );
    mysql_tquery(SQL, Array, "", "");
    return 1;
}
Reply
#2

PHP код:
format(Array, sizeof Array, "UPDATE `vehicles` SET \
        `Model` = '%d', `X` = '%f', `Y` = '%f', `Z` = '%f 
Set \

?
Reply
#3

Quote:
Originally Posted by justjamie
Посмотреть сообщение
PHP код:
format(Array, sizeof Array, "UPDATE `vehicles` SET \
        `Model` = '%d', `X` = '%f', `Y` = '%f', `Z` = '%f 
Set \

?
That's a way to make another line so your query is readable and all on one page. Basically so I don't have to scroll horizontally to read the entire query.
Reply
#4

PHP код:
RespawnVehicle(id)
{
    
DestroyVehicle(id);
    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;

This is what you are doing:

PHP код:
Vehicle[Vehicle[id][VehID]][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]); 
And for all it will be unknown id

Change like this

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;

And in cmd:editvehicle

PHP код:
RespawnVehicle(id); 
Reply
#5

Quote:
Originally Posted by ilijap
Посмотреть сообщение
PHP код:
RespawnVehicle(id)
{
    
DestroyVehicle(id);
    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;

This is what you are doing:

PHP код:
Vehicle[Vehicle[id][VehID]][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]); 
And for all it will be unknown id

Change like this

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;

And in cmd:editvehicle

PHP код:
RespawnVehicle(id); 
I see what you are saying, but the vehicle still doesn't destroy or save.
Reply
#6

What is Array[0] = 0; O.o
Reply
#7

Quote:
Originally Posted by ilijap
Посмотреть сообщение
What is Array[0] = 0; O.o
pawn Код:
new Array[4096]; // Much cleaner way of doing this, define it globally and use it when needed. Rather than defining strings locally. (Added 5/13/2016 - Do not remove, unless you want errors)
Reply
#8

Check in mysql_log ...
Reply
#9

Quote:
Originally Posted by ilijap
Посмотреть сообщение
Check in mysql_log ...
There's no SQL errors.
Reply
#10

Mine is like this :
PHP код:
public OnVehicleSpawn(vehicleid)
{
    
SetVehiclePos(vehicleidPlayerVehicle[vehicleid][vX], PlayerVehicle[vehicleid][vY], PlayerVehicle[vehicleid][vZ]);
    
SetVehicleZAngle(vehicleidPlayerVehicle[vehicleid][vZr]);
    
SetVehicleHealth(vehicleidPlayerVehicle[vehicleid][vHealth]);
    return 
1;

PHP код:
CMD:respawnall(playerid,params[])
{
    if(
PlayerInfo[playerid][pAdminlvl] >= 2)
    {
        for(new 
GetVehiclePoolSize(); 0i--)
        {
            
SetVehicleToRespawn(i);
        }
        
SendClientMessageToAll(red"[SYSTEM] "blancU"All vehicle respawned");
        
aAlert("/respawnall"playerid);
        return 
1;
    }
    else return 
SendClientMessage(playeridred"You are not allowed to use this command");

I think problem comes from DestroyVehicle(id);
You can't respawn a vehicle which get destroyed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)