Jump to content
  • 0

Problema ordinea preturilor


LeetRomania

Question

Buna seara. Am o problema la comanda /buycar. As dori cand afiseaza masinile disponibile din baza de date in /buycar sa fie in ordinea pretului nu dupa ID-ul din baza de date.

Asta imi arata masinile doar ca nu in ordinea pretului:

 

new stringzz[2000],stringy[2000];
for(new xf = 0; xf < MAX_PERSONAL_CARS; xf++)
{
  if(Stock[xf][vPrice] > 0 && Stock[xf][vPrice] <= 7000000)
  {
    format(stringy, sizeof(stringy), "%s ($%s)\n", Stock[xf][vName], NumberFormat(Stock[xf][vPrice]));
    strcat(stringzz,stringy);
  }
}
ShowPlayerDialog(playerid, DIALOG_CARBUY2, DIALOG_STYLE_LIST, "Buy a car", stringzz, "Select", "Back");

 

Link to comment
Share on other sites

Recommended Posts

  • 0

In acea iteratie modifica new i in new i = 0 (doar ca sa fi sigur ca o sa fie 0). Dupa asta nu face Stock[x][...] pentru ca daca tu o sa ai un id lipsa in baza de date o sa-ti dea crash, de exemplu sa zicem ca ai urmatoarele id-uri 1, 2, 3, 6, 8, tu o sa incepti sa accesezi pozitiile 6 si 8, dar ele nu exista in vectorul tau, asa ca foloseste pozitia curenta din vector, adica i-ul.

Link to comment
Share on other sites

  • 0

Am facut asa:

new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price` ASC");

dar tot face la fel.. Cand dau /buycar le pune in ordinea din baza de date..

Tot publicul este:

public IniStock()
{
	new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price` ASC");

	new x;

	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "ID", result); x = strval(result);
		cache_get_field_content(i, "Stock", result);  Stock[x][vStock] = strval(result);
		cache_get_field_content(i, "Price", result);  Stock[x][vPrice] = strval(result);
		cache_get_field_content(i, "Model", result);  Stock[x][vModel] = strval(result);
		cache_get_field_content(i, "Speed", result);  Stock[x][vSpeed] = strval(result);
		cache_get_field_content(i, "Car", result); format(Stock[x][vName], 32, result);

		systemVariables[dsvehicle]++;
	}
	printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
	cache_delete(result1);
	return 1;
}

 

Link to comment
Share on other sites

  • 0
public IniStock()
{
	new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price` DESC LIMIT 150");

	new x;

	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "ID", result); x = strval(result);
		cache_get_field_content(i, "Stock", result);  Stock[x][vStock] = strval(result);
		cache_get_field_content(i, "Price", result);  Stock[x][vPrice] = strval(result);
		cache_get_field_content(i, "Model", result);  Stock[x][vModel] = strval(result);
		cache_get_field_content(i, "Speed", result);  Stock[x][vSpeed] = strval(result);
		cache_get_field_content(i, "Car", result); format(Stock[x][vName], 32, result);

		systemVariables[dsvehicle]++;
	}
	printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
	cache_delete(result1);
	return 1;
}

 

                        

 

 

Link to comment
Share on other sites

  • 0
7 minutes ago, RWRobiBG said:

public IniStock()
{
	new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price` DESC LIMIT 150");

	new x;

	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "ID", result); x = strval(result);
		cache_get_field_content(i, "Stock", result);  Stock[x][vStock] = strval(result);
		cache_get_field_content(i, "Price", result);  Stock[x][vPrice] = strval(result);
		cache_get_field_content(i, "Model", result);  Stock[x][vModel] = strval(result);
		cache_get_field_content(i, "Speed", result);  Stock[x][vSpeed] = strval(result);
		cache_get_field_content(i, "Car", result); format(Stock[x][vName], 32, result);

		systemVariables[dsvehicle]++;
	}
	printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
	cache_delete(result1);
	return 1;
}

 

Nu s-a rezolvat nimic daca am facut asta. Se pun la fel ca in baza de date la ordine. Mentionez ca in baza de date ID-ul este PRIMARY. Conteaza asta?

Link to comment
Share on other sites

  • 0
Chiar acum, LeetRomania a spus:

Nu s-a rezolvat nimic daca am facut asta. Se pun la fel ca in baza de date la ordine. Mentionez ca in baza de date ID-ul este PRIMARY. Conteaza asta?

Hopa. e posibil sa iti arate invers, dami o poza cum iti arata, gen de la cel mai mare la cel mai mic.

                        

 

 

Link to comment
Share on other sites

  • 0
3 minutes ago, RWRobiBG said:

Hopa. e posibil sa iti arate invers, dami o poza cum iti arata, gen de la cel mai mare la cel mai mic.

Aceasta este poza din joc: http://imgur.com/a/x93p1

Se poate observa ca nu s-a pus in ordine.. Se pune fix cum sunt si in baza de date: Poza cu baza de date = http://imgur.com/a/dgDGu

 

Link to comment
Share on other sites

  • 0
public IniStock()
{
	new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price`");

	new x;

	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "ID", result); x = strval(result);
		cache_get_field_content(i, "Stock", result);  Stock[x][vStock] = strval(result);
		cache_get_field_content(i, "Price", result);  Stock[x][vPrice] = strval(result);
		cache_get_field_content(i, "Model", result);  Stock[x][vModel] = strval(result);
		cache_get_field_content(i, "Speed", result);  Stock[x][vSpeed] = strval(result);
		cache_get_field_content(i, "Car", result); format(Stock[x][vName], 32, result);

		systemVariables[dsvehicle]++;
	}
	printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
	cache_delete(result1);
	return 1;
}

Nu are cum sa nu mearga ce ti-am dat eu mai sus...

                        

 

 

Link to comment
Share on other sites

  • 0
3 minutes ago, RWRobiBG said:

public IniStock()
{
	new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price`");

	new x;

	for ( new i, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "ID", result); x = strval(result);
		cache_get_field_content(i, "Stock", result);  Stock[x][vStock] = strval(result);
		cache_get_field_content(i, "Price", result);  Stock[x][vPrice] = strval(result);
		cache_get_field_content(i, "Model", result);  Stock[x][vModel] = strval(result);
		cache_get_field_content(i, "Speed", result);  Stock[x][vSpeed] = strval(result);
		cache_get_field_content(i, "Car", result); format(Stock[x][vName], 32, result);

		systemVariables[dsvehicle]++;
	}
	printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
	cache_delete(result1);
	return 1;
}

Nu are cum sa nu mearga ce ti-am dat eu mai sus...

Chiar nu merge.. :( 

Link to comment
Share on other sites

  • 0
23 minutes ago, RWRobiBG said:

 

Propun ca topicul sa fie inchis, creatorul refuza sa primeasca ajutor prin TW, pretinzand ca vrem sa-i furam faimosul GM.

Nu am de unde sa stiu ca nu il furi. Nu este greu sa dai CTRL+ A pe urma CTRL + C. Am mai patit si de asta. Poti sa imi explici frumos si in acest topic ce trebuie sa fac. Am deschis topicul pe forum si cer aici ajutor nu pe TW. Daca chiar voiai sa ajuti, ajutai.

Link to comment
Share on other sites

  • 0
6 minutes ago, LeetRomania said:

Nu am de unde sa stiu ca nu il furi. Nu este greu sa dai CTRL+ A pe urma CTRL + C. Am mai patit si de asta. Poti sa imi explici frumos si in acest topic ce trebuie sa fac. Am deschis topicul pe forum si cer aici ajutor nu pe TW. Daca chiar voiai sa ajuti, ajutai.

Alti cer ajutor in privat si ii refuzam noi, nu am mai intalnit pana acum sa refuze invers :)

In fine asta e singura rezolvare asigurate ca macar compilezi gmul

new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price` ASC");

 

PS: Nu se poate fura gmul doar cu ctrl+a are nevoie si de includeuri

 

    __  ____      __           
   /  |/  (_)____/ /____  _____
  / /|_/ / / ___/ __/ _ \/ ___/
 / /  / / (__  ) /_/  __/ /    
/_/  /_/_/____/\__/\___/_/     
SERVICII SCRIPTING DE CALITATE
Pagina     Scripting     pawn
Link to comment
Share on other sites

  • 0
4 minutes ago, Mister said:

Alti cer ajutor in privat si ii refuzam noi, nu am mai intalnit pana acum sa refuze invers :)

In fine asta e singura rezolvare asigurate ca macar compilezi gmul


new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price` ASC");

 

PS: Nu se poate fura gmul doar cu ctrl+a are nevoie si de includeuri

M-am asigurat sa vad daca se compileaza. Se compileaza doar ca acolo e aceiasi poveste.. 

E posibil sa trebuiasca si in dialogul de la buycar sa modificat ceva? ... Chiar nu merge, nu am de ce sa va mint. 

Link to comment
Share on other sites

  • 0

Alta modalitate ar fi sa afisezi in dialog direct din mysql dar e mai complicat sa restructurezi comanda cu cache din baza de date si sa nu mai afisezi CarInfo.

Ceva gen /memberoffline doar ca pentru masini

 

    __  ____      __           
   /  |/  (_)____/ /____  _____
  / /|_/ / / ___/ __/ _ \/ ___/
 / /  / / (__  ) /_/  __/ /    
/_/  /_/_/____/\__/\___/_/     
SERVICII SCRIPTING DE CALITATE
Pagina     Scripting     pawn
Link to comment
Share on other sites

  • 0
13 minutes ago, Mister said:

Alta modalitate ar fi sa afisezi in dialog direct din mysql dar e mai complicat sa restructurezi comanda cu cache din baza de date si sa nu mai afisezi CarInfo.

Ceva gen /memberoffline doar ca pentru masini

Ar fi prea complicat.. :(

Link to comment
Share on other sites

  • 0
1 hour ago, WopsS said:

In acea iteratie modifica new i in new i = 0 (doar ca sa fi sigur ca o sa fie 0). Dupa asta nu face Stock[x][...] pentru ca daca tu o sa ai un id lipsa in baza de date o sa-ti dea crash, de exemplu sa zicem ca ai urmatoarele id-uri 1, 2, 3, 6, 8, tu o sa incepti sa accesezi pozitiile 6 si 8, dar ele nu exista in vectorul tau, asa ca foloseste pozitia curenta din vector, adica i-ul.

Am modificat si arata cam asa: 

public IniStock()
{
	new Cache: result1 = mysql_query(handle, "SELECT * FROM `stock` ORDER BY `Price` ASC");

	for ( new i = 0, j = cache_get_row_count ( ); i != j; ++i )
	{
		cache_get_field_content(i, "ID", result); i = strval(result);
		cache_get_field_content(i, "Stock", result);  Stock[i][vStock] = strval(result);
		cache_get_field_content(i, "Price", result);  Stock[i][vPrice] = strval(result);
		cache_get_field_content(i, "Model", result);  Stock[i][vModel] = strval(result);
		cache_get_field_content(i, "Speed", result);  Stock[i][vSpeed] = strval(result);
		cache_get_field_content(i, "Car", result); format(Stock[i][vName], 32, result);

		systemVariables[dsvehicle]++;
	}
	printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
	cache_delete(result1);
	return 1;
}

Masinile s-au pus cum trebuie in /buycar doar ca nu le afiseaza pe toate. 

De ex cand deschid consola apare: [script] 5 ds loaded cand eu defapt am 4 masini in baza de date. 

 

Edit: am sters  cache_get_field_content(i, "ID", result); i = strval(result); si acum apare corect in consola [script] 4 ds loaded doar ca daca dau click pe faggio selecteaza masina de mai jos.

Edited by LeetRomania
Link to comment
Share on other sites

  • 0
22 minutes ago, WopsS said:

Ah, cred ca am inteles ce vrei sa zici. In loc de ++i pune i++ sa il incrementezi dupa ce il folosesti.

Am pus i++ in loc de ++i si este la fel.

Cand dau /buycar, selectez prima masina, se cumpara urmatoarea. 

 

EDIT:

 

Am facut asa:

 

public IniStock()
{
    new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price`");
    for ( new i = 1, j = cache_get_row_count ( ); i <= j; i++)
    {
        cache_get_field_content(i, "Stock", result);  Stock[vStock] = strval(result);
        cache_get_field_content(i, "Price", result);  Stock[vPrice] = strval(result);
        cache_get_field_content(i, "Model", result);  Stock[vModel] = strval(result);
        cache_get_field_content(i, "Speed", result);  Stock[vSpeed] = strval(result);
        cache_get_field_content(i, "Car", result); format(Stock[vName], 32, result);

        systemVariables[dsvehicle]++;
    }
    
    printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
    cache_delete(result1);
    return 1;
}

 

Si faza e ca acum merge corect doar ca sare peste a doua masina din baza de date mereu :| 

Edited by LeetRomania
Link to comment
Share on other sites

  • 0
Acum 29 minute, WopsS a spus:

Ah, cred ca am inteles ce vrei sa zici. In loc de ++i pune i++ sa il incrementezi dupa ce il folosesti.

i++ si ++i e aceiasi chestie.

Acum 21 minute, LeetRomania a spus:

Am pus i++ in loc de ++i si este la fel.

Cand dau /buycar, selectez prima masina, se cumpara urmatoarea. 

 

EDIT:

 

Am facut asa:

 

public IniStock()
{
    new Cache: result1 = mysql_query (handle, "SELECT * FROM `stock` ORDER BY `Price`");
    for ( new i = 1, j = cache_get_row_count ( ); i <= j; i++)
    {
        cache_get_field_content(i, "Stock", result);  Stock[vStock] = strval(result);
        cache_get_field_content(i, "Price", result);  Stock[vPrice] = strval(result);
        cache_get_field_content(i, "Model", result);  Stock[vModel] = strval(result);
        cache_get_field_content(i, "Speed", result);  Stock[vSpeed] = strval(result);
        cache_get_field_content(i, "Car", result); format(Stock[vName], 32, result);

        systemVariables[dsvehicle]++;
    }
    
    printf("[script] %d ds loaded.", systemVariables[dsvehicle]);
    cache_delete(result1);
    return 1;
}

 

Si faza e ca acum merge corect doar ca sare peste a doua masina din baza de date mereu :| 

Ia pune toata comanda buycar aici

si dialogul de la buycar de la ondialogresponse.

                        

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.