#1

I have the code below, but when I use it and call that function, it only loads one vehicle.. Where as it's supposed to load 3 vehicles or however many the player has got?

Could someone help please?

Here's the code:

pawn Код:
stock LoadOwnedCars(playerid)
{
    new query[1024], savingstring[40], newcar, vID;
    format(query, sizeof(query), "SELECT * FROM OwnedVehicles WHERE OwnedVehicleOwner = '%s'", pName(playerid));
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(savingstring, "OwnedVehicleID"); vID = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleModel"); Vehicles[vID][vModel] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleColor1"); Vehicles[vID][vColor1] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleColor2"); Vehicles[vID][vColor2] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehiclePrice"); Vehicles[vID][vPrice] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleX"); Vehicles[vID][vPosX] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleY"); Vehicles[vID][vPosY] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleZ"); Vehicles[vID][vPosZ] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleA"); Vehicles[vID][vPosA] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleOwner"); strmid(Vehicles[vID][VehicleOwner], savingstring, 0, strlen(savingstring), 24);
        mysql_fetch_field_row(savingstring, "OwnedVehiclePlate"); strmid(Vehicles[vID][VehiclePlate], savingstring, 0, strlen(savingstring), 24);
        mysql_fetch_field_row(savingstring, "OwnedVehiclePaintJob"); Vehicles[vID][VehiclePaintJob] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleLock"); Vehicles[vID][vLocked] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleMoney"); Vehicles[vID][vTrunkMoney] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleMaterials"); Vehicles[vID][vTrunkMats] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleCocaine"); Vehicles[vID][vTrunkCocaine] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleMoonshine"); Vehicles[vID][vTrunkMoonshine] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleFuel"); Vehicles[vID][vFuel] = strval(savingstring);
        newcar = CreateVehicle(Vehicles[vID][vModel], Vehicles[vID][vPosX], Vehicles[vID][vPosY], Vehicles[vID][vPosZ], Vehicles[vID][vPosA], Vehicles[vID][vColor1], Vehicles[vID][vColor2], -1);
        format(Vehicles[vID][VehicleOwner], 24, "%s", Vehicles[vID][VehicleOwner]);
        format(Vehicles[vID][VehiclePlate], 32, "%s", Vehicles[vID][VehiclePlate]);
        SetVehicleNumberPlate(newcar, Vehicles[vID][VehiclePlate]);
        SetVehicleToRespawn(newcar);
        OwnedCar(newcar) = vID;
    }
    mysql_free_result();
    return 1;
}
Thanks!
Reply
#2

hi before response I suggest you to use new version of mysql plugins : https://sampforum.blast.hk/showthread.php?tid=337810 , easier and faster than old version.

anyway normaly your code should load all player vehicules but try this function :

Quote:

[PHP]
mysql_query("SELECT * FROM houses");
mysql_ store_result();

while(mysql_retrieve_row()) //this will be running until all rows are processed
{
//you can use mysql_fetch_field and mysql_fetch_field_row here
}

mysql_free_result();
[PHP]

normaly ,it load the row 0 then row 1 and 2 ..

Reply
#3

What does this line do, or what is it supposed to do:
pawn Код:
OwnedCar(newcar) = vID;
Also, do you somehow associate the newly created vehicle IDs with the player who they belong to?


Quote:
Originally Posted by marquezsanchez
Посмотреть сообщение
hi before response I suggest you to use new version of mysql plugins : https://sampforum.blast.hk/showthread.php?tid=337810 , easier and faster than old version.
Awww, so nice of you
Reply
#4

I don't use BlueG's, but thanks.

Also; the OwnedCar(newcar) = vID; is telling the script that it's an owned vehicle.

pawn Код:
mysql_query("SELECT * FROM houses");
mysql_ store_result();

while(mysql_retrieve_row()) //this will be running until all rows are processed
{
//you can use mysql_fetch_field and mysql_fetch_field_row here
}

mysql_free_result();
Will that work?
Reply
#5

I might just be tired and might not spot a (simple) mistake, but seriously, you have 1120 posts and run your own roleplay server (?). Learn to DEBUG your code.

1. See how many rows the script returns (printf("%d", mysql_num_rows())) after storing the result.
2. See what data is retrieved from each row (print retrieved data prior to the CreateVehicle line to determine and compare with the database to see if all data is retrieved correctly).
3. What kind a notation is the "OwnedCar(newcar) = vID;" line? Is it a function or a macro of some sort? If not then this must be something I've never seen before.
4. Print the newcar value.
Reply
#6

Quote:
Originally Posted by AndreT
Посмотреть сообщение
I might just be tired and might not spot a (simple) mistake, but seriously, you have 1120 posts and run your own roleplay server (?). Learn to DEBUG your code.

1. See how many rows the script returns (printf("%d", mysql_num_rows())) after storing the result.
2. See what data is retrieved from each row (print retrieved data prior to the CreateVehicle line to determine and compare with the database to see if all data is retrieved correctly).
3. What kind a notation is the "OwnedCar(newcar) = vID;" line? Is it a function or a macro of some sort? If not then this must be something I've never seen before.
4. Print the newcar value.
And you have the right to talk to anyone like that because?....

You know what, get off my post and I'll get other people that will be police to help me out.
Reply
#7

Quote:

You know what, get off my post and I'll get other people that will be police to help me out.

I present you with a method to find a solution for the issue you're experiencing and you're saying you want someone that will be police, not helpful?!

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)