SA-MP Forums Archive
Player-unique-car - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Player-unique-car (/showthread.php?tid=492344)



Player-unique-car - yellow - 03.02.2014

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.


AW: Player-unique-car - yellow - 03.02.2014

le push


AW: Player-unique-car - yellow - 04.02.2014

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


AW: Player-unique-car - yellow - 05.02.2014

le push


Re: Player-unique-car - Borg - 05.02.2014

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.


AW: Player-unique-car - yellow - 05.02.2014

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;
}



AW: Player-unique-car - yellow - 05.02.2014

Problem solved!
mysql_query(result);