Player-unique-car
#1

Hey, it's me again

My Carsystem is right so far, but i still have a problem.
How can i load the player-unique cars? If i connect, it loads all cars in the DB, not those who are mine.

Codes:
Код:
enum cardata
{
	id,
	owner[MAX_PLAYER_NAME],
	plate[20],
	Float:spawnx,
	Float:spawny,
	Float:spawnz,
	Float:spawnr,
	modelid,
	c1,
	c2,
	price,
	car
}
new Playercar[MAX_CARS][cardata];
Код:
stock LoadPlayerCars()
{

    mysql_query_callback(1, "SELECT * FROM cars",  "OnPlayerCarsLoaded");
}
forward OnPlayerCarsLoaded();
public OnPlayerCarsLoaded()
{
    new
    	idx,
        result[256],
        query[128];
		new downer,dplate,Float:sx,Float:sy,Float:sz,model,colo1,colo2,dprice,dcar,iD,Float:sr;
        format(result, 128, "SELECT * FROM `cars` WHERE `ID` = '%d'", id);
		mysql_query(query);
        mysql_store_result();
       while(mysql_fetch_row_format(result, "|"))
       {
       		sscanf(result, "p<|>is[16]ffffiiis[20]i",iD,downer,sx,sy,sz,sr,model,colo1,colo2,dplate,dprice);
			Playercar[idx][owner] = downer;
			Playercar[idx][plate] = dplate;
			Playercar[idx][spawnx] = sx;
			Playercar[idx][spawny] = sy;
			Playercar[idx][spawnz] = sz;
			Playercar[idx][spawnr] = sr;
			Playercar[idx][modelid] = model;
			Playercar[idx][c1] = colo1;
			Playercar[idx][c2] = colo2;
			Playercar[idx][price] = dprice;
   			Playercar[idx][car] = AddStaticVehicleEx(Playercar[idx][modelid],Playercar[idx][spawnx],Playercar[idx][spawny],Playercar[idx][spawnz],Playercar[idx]   [spawnr],Playercar[idx][c1],Playercar[idx][c2],60);
      		idx++;
        }
        printf(" ||CAR: %s %i %f %f %f %f %i %i %i", downer,modelid,sx,sy,sz,sr,colo1,colo2,price);
       	mysql_free_result();
       	printf("[mysql] Succesful. %i ausgelesen", idx); //
       	return 1;
}
How can i solve it? And could you please descripe it? I dont want to create a new thread for every problem

You could also post a good mysql tutorial which explains my problems.
Reply
#2

le push
Reply
#3

i know that im annoyin you but i'd be happy if i could finish this
Reply
#4

le push
Reply
#5

where do you get "id" variable?
pawn Код:
format(result, 128, "SELECT * FROM `cars` WHERE `ID` = '%d'", id);
mysql_query(query);
The code loads only vehicle with this id. To load the player's vehicle you need to push the player's info to the function and search by Owner field, not ID.
Reply
#6

sorry, i already fixxed that. my code is

pawn Код:
public OnPlayerCarsLoaded(playerid)
{
    new
        idx,
        result[256],
        query[128];
        new downer[MAX_PLAYER_NAME],dplate[20],Float:sx,Float:sy,Float:sz,model,colo1,colo2,dprice,dcar,iD,Float:sr;

        format(result, 128, "SELECT * FROM `cars` WHERE `owner` = '%s'", SpielerName(playerid));  //owner = so wie owner eben in der DB heiЯt
       
        mysql_query(query);
        mysql_store_result();
       while(mysql_fetch_row_format(result, "|"))
       {
            print(result);
            sscanf(result, "p<|>is[16]ffffiiis[20]i",iD,downer,sx,sy,sz,sr,model,colo1,colo2,dplate,dprice);
            Playercar[idx][owner] = downer;
            Playercar[idx][plate] = dplate;
            Playercar[idx][spawnx] = sx;
            Playercar[idx][spawny] = sy;
            Playercar[idx][spawnz] = sz;
            Playercar[idx][spawnr] = sr;
            Playercar[idx][modelid] = model;
            Playercar[idx][c1] = colo1;
            Playercar[idx][c2] = colo2;
            Playercar[idx][price] = dprice;
            Playercar[idx][car] = AddStaticVehicleEx(Playercar[idx][modelid],Playercar[idx][spawnx],Playercar[idx][spawny],Playercar[idx][spawnz],Playercar[idx]   [spawnr],Playercar[idx][c1],Playercar[idx][c2],60);
            idx++;
        }
        printf(" ||CAR: %s %i %f %f %f %f %i %i %i", downer,modelid,sx,sy,sz,sr,colo1,colo2,price);
        mysql_free_result();
        printf("[mysql] Succesful. %i ausgelesen", idx); //
        return 1;
}
Reply
#7

Problem solved!
mysql_query(result);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)