Spawning Private Vehicles[MySQL]
#1

I've had problems getting this script to load player vehicles. The query is working as i've debugged it but the problem is, no vehicles are being created.

Here is what I have:

PHP Code:
stock LoadPlayerVehicles(playerid)
{
    new 
str[256];
    new 
query[128];
    for (new 
1MAX_PLAYER_OWNED_CARS 1+= 1)
    {
        
format(querysizeof(query), "SELECT * FROM `playervehicles` WHERE `OwnerName` = '%s' AND `VehicleSlot` = '%d'"PlayerName(playerid), i);
        
mysql_query(query);
        
mysql_store_result();
        if(
mysql_num_rows())
        {
            
sscanf(str"p<|>e<sdffffdddddddddddddddddddddddddddddddddddd>"PlayerOwnedVehicles[playerid][i]);
            
PlayerOwnedVehicles[playerid][i][pCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][pCarModel], PlayerOwnedVehicles[playerid][i][pCarX], PlayerOwnedVehicles[playerid][i][pCarY], PlayerOwnedVehicles[playerid][i][pCarZ], PlayerOwnedVehicles[playerid][i][pCarRot], PlayerOwnedVehicles[playerid][i][pCarColor1], PlayerOwnedVehicles[playerid][i][pCarColor2], -1);
            
AddVehicleMods(playeridi);
        }
        
mysql_free_result();
    }
    return 
true;

Reply
#2

Bump, I've tried changing the sscanf order so the P<|> is inside the enum specifier, nothing had changed though.
Reply
#3

EDIT:
I thought the time was 48 hrs. NVM.
Reply
#4

What are you trying to infer. I've waited 24 hours.
Reply
#5

This way of loading vehicles defeats the whole purpose of using MySQL! (no offense) You're supposed to fetch all matching records and then loop through them. Also, you should look into upgrading to R7, taking advantage of the cache_functions, and implementing a primary key for each user so your database only has to compare integers instead of strings.

Anyways, I haven't tested this code, but try it.
pawn Code:
stock LoadPlayerVehicles(playerid)
{
    new query[400];
    format(query, sizeof(query), "SELECT * FROM `playervehicles` WHERE `OwnerName` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();

    new i;

    whie(i < MAX_PLAYER_OWNED_CARS && mysql_retrieve_row())
    {
        mysql_fetch_row(query);
        sscanf(query, "p<|>e<sdffffdddddddddddddddddddddddddddddddddddd>", PlayerOwnedVehicles[playerid][i]);
        PlayerOwnedVehicles[playerid][i][pCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][pCarModel], PlayerOwnedVehicles[playerid][i][pCarX], PlayerOwnedVehicles[playerid][i][pCarY], PlayerOwnedVehicles[playerid][i][pCarZ], PlayerOwnedVehicles[playerid][i][pCarRot], PlayerOwnedVehicles[playerid][i][pCarColor1], PlayerOwnedVehicles[playerid][i][pCarColor2], -1);
        AddVehicleMods(playerid, i);
        i++;
    }
    mysql_free_result();
    return true;
}
Reply
#6

This isn't working either.
Reply
#7

does the enum format in the sscanf line match your database structure?
Reply
#8

I have 42 in my database and 43 in my enum. The last integer in my enum is pCarID which doesn't need to be called from the database, aswell as the fact that I'm not getting any MySQL reading errors.

The first S and the last D integers are in the enum but not in the database.
Reply
#9

Bump.

I've been debugging the code aswell as working with SSCANF.

PHP Code:
stock LoadPlayerVehicles(playerid)
{
    new 
query[400];
    
format(querysizeof(query), "SELECT * FROM `playervehicles` WHERE `OwnerName` = '%s'"PlayerName(playerid));
    
mysql_query(query);
    
mysql_store_result();
    new 
i;
    while(
MAX_PLAYER_OWNED_CARS && mysql_retrieve_row())
    {
        
mysql_fetch_row_format(query);
        
sscanf(query"e<p<|>s[25]dffffdddddddddddddddddddddddddddddddddddd{d}>"PlayerOwnedVehicles[playerid][i]);
        
PlayerOwnedVehicles[playerid][i][pCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][pCarModel], PlayerOwnedVehicles[playerid][i][pCarX], PlayerOwnedVehicles[playerid][i][pCarY], PlayerOwnedVehicles[playerid][i][pCarZ], PlayerOwnedVehicles[playerid][i][pCarRot], PlayerOwnedVehicles[playerid][i][pCarColor1], PlayerOwnedVehicles[playerid][i][pCarColor2], -1);
        
AddVehicleMods(playeridi);
        
i++;
    }
    
mysql_free_result();
    return 
true;

This what I have and it keeps telling me that I have a buffer overflow when I add a size to the S variable.

For the post above the S variable signifies the vehicle owners name and the D at the end of the SSCANF is the carid that comes out once the vehicle has been spawned, the owners name is in the database but the carid isn't as it's dynamic, though it's in the enum. I would really love to see this fixed and behind me. Thankyou all for the support so far. Aswell as the vehicles aswell are still not spawning.
Reply
#10

Post your enum structure for the vehicles.
Reply
#11

PHP Code:
enum PlayerCarData
{
    
playerCarOwner[MAX_PLAYER_NAME],
    
playerCarModel,
    
Float:playerCarX,
    
Float:playerCarY,
    
Float:playerCarZ,
    
Float:playerCarRot,
    
playerCarColor1,
    
playerCarColor2,
    
playerCarPaintjob,
    
playerCarMod1,
    
playerCarMod2,
    
playerCarMod3,
    
playerCarMod4,
    
playerCarMod5,
    
playerCarMod6,
    
playerCarMod7,
    
playerCarMod8,
    
playerCarMod9,
    
playerCarMod10,
    
playerCarMod11,
    
playerCarMod12,
    
playerCarMod13,
    
playerCarMod14,
    
playerCarMod15,
    
playerCarMod16,
    
playerCarMod17,
    
playerCarHasLock,
    
playerCarLocked,
    
playerCarTrunkCash,
    
playerCarTrunkGun1,
    
playerCarTrunkGun2,
    
playerCarTrunkGun3,
    
playerCarTrunkGun4,
    
playerCarTrunkAmmo1,
    
playerCarTrunkAmmo2,
    
playerCarTrunkAmmo3,
    
playerCarTrunkAmmo4,
    
playerCarSpawned,
    
playerCarOwned,
    
playerCarOwnerID,
    
playerCarFuel,
    
pSlotID,
    
playerCarID,
}; 
I write it in PHP tags as I think it looks much neater.
Reply
#12

Well to explain the buffer overflow in your post before, in the sscanf line, you used s[25], when the max length of the owner name was 24.

Anyways, you're better off without the e specifier.
pawn Code:
stock LoadPlayerVehicles(playerid)
{
    new query[400];
    format(query, sizeof(query), "SELECT * FROM `playervehicles` WHERE `OwnerName` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    new i;
    while(i < MAX_PLAYER_OWNED_CARS && mysql_retrieve_row())
    {
        mysql_fetch_row_format(query);

        sscanf(query, "p<|>s[" #MAX_PLAYER_NAME "]dffffdddddddddddddddddddddddddddddddddddd",
            PlayerOwnedVehicles[playerid][i][playerCarOwner],
            PlayerOwnedVehicles[playerid][i][playerCarModel],
            PlayerOwnedVehicles[playerid][i][playerCarX],
            PlayerOwnedVehicles[playerid][i][playerCarY],
            PlayerOwnedVehicles[playerid][i][playerCarZ],
            PlayerOwnedVehicles[playerid][i][playerCarRot],
            PlayerOwnedVehicles[playerid][i][playerCarColor1],
            PlayerOwnedVehicles[playerid][i][playerCarColor2],
            PlayerOwnedVehicles[playerid][i][playerCarPaintjob],
            PlayerOwnedVehicles[playerid][i][playerCarMod1],
            PlayerOwnedVehicles[playerid][i][playerCarMod2],
            PlayerOwnedVehicles[playerid][i][playerCarMod3],
            PlayerOwnedVehicles[playerid][i][playerCarMod4],
            PlayerOwnedVehicles[playerid][i][playerCarMod5],
            PlayerOwnedVehicles[playerid][i][playerCarMod6],
            PlayerOwnedVehicles[playerid][i][playerCarMod7],
            PlayerOwnedVehicles[playerid][i][playerCarMod8],
            PlayerOwnedVehicles[playerid][i][playerCarMod9],
            PlayerOwnedVehicles[playerid][i][playerCarMod10],
            PlayerOwnedVehicles[playerid][i][playerCarMod11],
            PlayerOwnedVehicles[playerid][i][playerCarMod12],
            PlayerOwnedVehicles[playerid][i][playerCarMod13],
            PlayerOwnedVehicles[playerid][i][playerCarMod14],
            PlayerOwnedVehicles[playerid][i][playerCarMod15],
            PlayerOwnedVehicles[playerid][i][playerCarMod16],
            PlayerOwnedVehicles[playerid][i][playerCarMod17],
            PlayerOwnedVehicles[playerid][i][playerCarHasLock],
            PlayerOwnedVehicles[playerid][i][playerCarLocked],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkCash],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkGun1],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkGun2],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkGun3],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkGun4],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo1],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo2],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo3],
            PlayerOwnedVehicles[playerid][i][playerCarTrunkAmmo4],
            PlayerOwnedVehicles[playerid][i][playerCarSpawned],
            PlayerOwnedVehicles[playerid][i][playerCarOwned],
            PlayerOwnedVehicles[playerid][i][playerCarOwnerID],
            PlayerOwnedVehicles[playerid][i][playerCarFuel],
            PlayerOwnedVehicles[playerid][i][playerCarSlotID]
        );

        PlayerOwnedVehicles[playerid][i][pCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][pCarModel], PlayerOwnedVehicles[playerid][i][pCarX], PlayerOwnedVehicles[playerid][i][pCarY], PlayerOwnedVehicles[playerid][i][pCarZ], PlayerOwnedVehicles[playerid][i][pCarRot], PlayerOwnedVehicles[playerid][i][pCarColor1], PlayerOwnedVehicles[playerid][i][pCarColor2], -1);
        AddVehicleMods(playerid, i);
        i++;
    }
    mysql_free_result();
    return true;
}
Also make sure the order of the variables of the code above matches the order of fields in your playerCars table. If that still doesn't work, enable debugging and check mysql_log.txt. It also couldn't hurt to print(query); after the mysql_fetch_row_format line
Reply
#13

I will, one last thing.

Something seems to be wrong with this line:
PHP Code:
PlayerOwnedVehicles[playerid][i][playerCarID] = CreateVehicle(PlayerOwnedVehicles[playerid][i][pCarModel], PlayerOwnedVehicles[playerid][i][pCarX], PlayerOwnedVehicles[playerid][i][pCarY], PlayerOwnedVehicles[playerid][i][pCarZ], PlayerOwnedVehicles[playerid][i][pCarRot], PlayerOwnedVehicles[playerid][i][pCarColor1], PlayerOwnedVehicles[playerid][i][pCarColor2], -1); 
warning 213: tag mismatch
error 032: array index out of bounds (variable "PlayerOwnedVehicles")

I hope that this will be fixed after this, Merry Christmas to you and thankyou for your help to far
Reply
#14

Could you maybe show how you declare/define PlayerOwnedVehicles?

And on which lines you get this errors/warnings?
Reply
#15

It's defined by
PHP Code:
new PlayerOwnedVehicles[MAX_PLAYERS][MAX_PLAYER_OWNED_VEHICLES +1][PlayerCarData];
#define MAX_PLAYER_OWNED_VEHICLES 4 
Merry Christmas!
Reply
#16

Quote:
Originally Posted by Peach
View Post
It's defined by
PHP Code:
new PlayerOwnedVehicles[MAX_PLAYERS][MAX_PLAYER_OWNED_VEHICLES +1][PlayerCarData];
#define MAX_PLAYER_OWNED_VEHICLES 4 
Merry Christmas!
If the define is under the PlayerOwnedVehicles variable, then is that maybe the problem..
Set your define MAX_PLAYER_OWNED_VEHICLES above the PlayerOwnedVehicles variable.
Reply
#17

I fixed the error, thankyou for your help, time to see if the system actually works. It wasn't the fact that I had +1.. somehow there was just something different on that line so I fixed it with a backup I had had of that line.

Edit: Still getting "String Buffer Overflow".
Reply
#18

Quote:
Originally Posted by Peach
View Post
I fixed the error, thankyou for your help, time to see if the system actually works. It wasn't the fact that I had +1.. somehow there was just something different on that line so I fixed it with a backup I had had of that line.

Edit: Still getting "String Buffer Overflow".
On which line you get "String Buffer Overflow"?
Reply
#19

I'm getting it printed through the console. I'm thinking it's the S integer in the sscanf string.

"S[24]" - That's getting the players name of the car.

I've tried changing it to [MAX_PLAYER_NAME] - That then gives me a different warning of all three:
Code:
sscanf warning: Invalid data length.
sscanf warning: Invalid character in data length.
sscanf warning: String buffer overflow.
Reply
#20

Quote:
Originally Posted by Peach
View Post
I'm getting it printed through the console. I'm thinking it's the S integer in the sscanf string.

"S[24]" - That's getting the players name of the car.

I've tried changing it to [MAX_PLAYER_NAME] - That then gives me a different warning of all three:
Code:
sscanf warning: Invalid data length.
sscanf warning: Invalid character in data length.
sscanf warning: String buffer overflow.
Why you don't try "s" instead of "S[24]"?
Maybe that will solve the problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)