SQLite VehLock Saving
#1

Hey Everyone,

I'm working on a SQLite game mode. A friend of mine helped me with this SQLite Vehicle System. This script doesnt creates the table if it doesnt exist. So first of all i got it working , Now it Creates the table with the given Types of fields for the table. I made this new Column called "locked" and this new VehicleVar called "Vehicle[vehicleid][vLocked]"

Now the problem is. This array works fine in game. That means if this array is 0 then it will be zero also in game . I can lock a vehicle and see the printf which shows that this array is changed to 1 and then the SaveVehicle() is called , it saves the vehicles and printf's the Vehicle Vars. Lock is the same as it was in the database , i.e if it was zero then it will zero , if it was one then it will be one here. Vehicle Vars changes in the game but doenst save properly. They load just fine. But saving is the problem i dont know why.

Everything use to work fine before. But after adding this new column called "locked" and PVar "Vehicle[vehicleid][vLocked]" in the game mode. It doesnt save the lock variable , everything is stored and loaded just fine. Its just the problem with lock (Saving Not Loading)

My SaveVehicle(vehicleid) callback.

pawn Код:
public SaveVehicle(vehicleid)
{
    if(VehicleExistsArray(vehicleid))
    {
        new array_id = VEHICLE_ARRAY_ID[vehicleid];
        //printf("SV ARRAY_ID %d", array_id);
        format(query, sizeof(query), "UPDATE `Vehicle` SET `x` = '%f', `y` = '%f', `z` = '%f', `model` = '%d', `color1` = '%d', `color2` = '%d', `angle` = '%f', `world` = '%d', `price` = '%d', `forsale` = '%d', `factionid` = '%d', `locked` = '%d', `owner_id` = '%d', `owned` = '%d' WHERE `id` = '%d'",
        Vehicle[array_id][vX],
        Vehicle[array_id][vY],
        Vehicle[array_id][vZ],
        Vehicle[array_id][vModel],
        Vehicle[array_id][vColor1],
        Vehicle[array_id][vColor2],
        Vehicle[array_id][vAngle],
        Vehicle[array_id][vWorld],
        Vehicle[array_id][vPrice],
        Vehicle[array_id][vForSale],
        Vehicle[array_id][vFactionID],
        Vehicle[array_id][vLocked],
        Vehicle[array_id][vOwner_ID],
        Vehicle[array_id][vOwned],
        Vehicle[array_id][vSQLID]);
        db_free_result(db_query(database,query));
        printf("[VEH]%d (%d) saved. [%d|%d|%d|Lock:%d]", Vehicle[array_id][vSQLID], Vehicle[array_id][vID], Vehicle[array_id][vOwner_ID], Vehicle[array_id][vOwned], array_id, Vehicle[array_id][vLocked]);
    }
    return true;
}
Reply
#2

Can you print the query and paste that here? Also, are you updating the vehicle ID to the correct ID?
Reply
#3

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
Can you print the query and paste that here? Also, are you updating the vehicle ID to the correct ID?
Yes everything is saving/loading perfectly. Its just the problem with Lock!

Which Query are you talking about?
Reply
#4

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
Yes everything is saving/loading perfectly. Its just the problem with Lock!

Which Query are you talking about?
pawn Код:
format(query, sizeof(query), "UPDATE `Vehicle` SET `x` = '%f', `y` = '%f', `z` = '%f', `model` = '%d', `color1` = '%d', `color2` = '%d', `angle` = '%f', `world` = '%d', `price` = '%d', `forsale` = '%d', `factionid` = '%d', `locked` = '%d', `owner_id` = '%d', `owned` = '%d' WHERE `id` = '%d'"
See what that query prints, there might be a tad of insufficient cells for the query.
Reply
#5

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
pawn Код:
format(query, sizeof(query), "UPDATE `Vehicle` SET `x` = '%f', `y` = '%f', `z` = '%f', `model` = '%d', `color1` = '%d', `color2` = '%d', `angle` = '%f', `world` = '%d', `price` = '%d', `forsale` = '%d', `factionid` = '%d', `locked` = '%d', `owner_id` = '%d', `owned` = '%d' WHERE `id` = '%d'"
See what that query prints, there might be a tad of insufficient cells for the query.
When i lock a vehicle. It calls the SaveVehicle callback automatically. So i added the printf on SaveVehicle , and this is what i get now.

Код:
[11:43:26] [SAVE] Vehicle Locked = 1
[11:43:26] UPDATE `Vehicle` SET `locked` = '0', `x` = '1536.859008', `y` = '-1708.180175', `z` = '13.252328', `model` = '560', `color1` = '0', `color2` = '0', `angle` = '179.860809', `world` = '0', `price` = '1', `forsale` = '0', `factionid` = '-1', `owner_id` = '65', `owned` = '1' WHERE `id` = '1'
Vehicle Array was set to 1 but it didnt save as 1 , it saved as zero? Why?
Reply
#6

So i made a new callback to save the vehicle lock variable. Here it is:
pawn Код:
public SaveVehicleLock(vehicleid)
{
    if(VehicleExistsArray(vehicleid))
    {
        new array_id = VEHICLE_ARRAY_ID[vehicleid];
        //printf("SV ARRAY_ID %d", array_id);
        format(query, sizeof(query), "UPDATE `Vehicle` SET `locked` = '%d' WHERE `id` = '%d'",
        Vehicle[array_id][vLocked],
        Vehicle[array_id][vSQLID]);
        db_free_result(db_query(database,query));
        printf(query);
    }
    return true;
}
I printf the query after locking the vehicle. So the same thing. If it was zero , its still zero. If it was one its still one. It changes in game buy why doesnt it save? Damn
Reply
#7

post what printf(query); displays.
Reply
#8

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
post what printf(query); displays.
Код:
[11:43:26] [SAVE] Vehicle Locked = 1
[11:43:26] UPDATE `Vehicle` SET `locked` = '0' WHERE `id` = '1'
Reply
#9

It must be something wrong with your arrays.
pawn Код:
new array_id = VEHICLE_ARRAY_ID[vehicleid];
That line specifically might be your problem, try just using "VEHICLE_ARRAY_ID[vehicleid]".
Reply
#10

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
It must be something wrong with your arrays.
pawn Код:
new array_id = VEHICLE_ARRAY_ID[vehicleid];
That line specifically might be your problem, try just using "VEHICLE_ARRAY_ID[vehicleid]".
No Help from that. Cause everything was working before. What the heck is the problem Vinci? Any Suggestions or alternatives?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)