SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/06/2020, 10:22 AM   #1
MarianImmortalGod
Big Clucker
 
Join Date: Mar 2018
Posts: 115
Reputation: 1
Default Vehicle wont show correctly

Hello.

I want to do a /v cmd that show's your vehicles that you own.

Code:
CMD:v(playerid)
{
	new string[128], count;
	mysql_format(handle, string, sizeof(string), "SELECT * FROM `cars` WHERE `Owner` = '%s' ORDER BY `ID` DESC", GetName(playerid));
	new Cache:result = mysql_query(handle, string);

	format(string, sizeof(string), "ID\tModel\n");
	for(new i = 1; i <= cache_num_rows(); i++)
	{
		format(string, sizeof string, "%s%d\t%s\n", string, i, CarInfo[i][CarOwner]);
		count++;
	}
	if(count == 0) return SCM(playerid, -1, "You don't own any cars.");
	
	cache_delete(result);
	ShowPlayerDialog(playerid, DIALOG_CARS, DIALOG_STYLE_TABLIST_HEADERS, "Cars:", string, "Select", "Quit");
	return 1;
}
It shows the correct number like 2 vehicles but the problem is that i get someone else vehicle.
If in the database the car number 1 is mine then car number 2 is someone else car and my seccond car is the car with id 3, i will get first two cars 1 and 2 not 1 and 3.

Any ideas ?

EDIT: solved, i added.

Code:
cache_get_value_int(i, "ID", carid);
		format(string, sizeof(string), "%s%d\t%s\n", string, i, CarInfo[carid][CarOwner]);
But now i have the problem that if i sellect car 2 it give's me someone else car from db, is like i am selecting car database id not the menu car id.
MarianImmortalGod is offline   Reply With Quote
Old 28/06/2020, 10:32 AM   #2
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 219
Reputation: 43
Default Re: Vehicle wont show correctly

Quote:
Originally Posted by MarianImmortalGod View Post
PHP Code:
mysql_format(handlestringsizeof(string), "SELECT * FROM `cars` WHERE `Owner` = '%s' ORDER BY `ID` DESC"GetName(playerid)); 
First of all, you should be doing this MySQL check when a player spawns, storing the content in an Enumerator.
that way players are not directly looking in the MySQL Database, no chance for abuse and it's faster.
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is online now   Reply With Quote
Old 28/06/2020, 10:36 AM   #3
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,735
Reputation: 1686
Default Re: Vehicle wont show correctly

Quote:
But now i have the problem that if i sellect car 2 it give's me someone else car from db, is like i am selecting car database id not the menu car id.
What's the code under OnDialogResponse()?

Also:
Code:
for(new i = 1; i <= cache_num_rows(); i++)
I suggest you to use:
Code:
for (new i, rows = cache_num_rows(); i < rows; i++)
//Or, even better yet:
new rows;
cache_get_row_count(rows);
for (new i; i < rows; i++)
(Or, i = 1 and i <= rows. However, 0 is always the first row so this piece of code skips the first result).
When you use cache_num_rows() in the statement part of the for() loop, it gets called every loop. When you assign it the way I did, cache_num_rows() is called once.
Also: https://forum.sa-mp.com/showpost.php...4&postcount=12

Also also, I highly recommend you to use threaded queries.
If your MySQL server would be lagging somehow, your entire server will freeze for everyone after using /v untill the results come in and are handled.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 28/06/2020, 10:41 AM   #4
MarianImmortalGod
Big Clucker
 
Join Date: Mar 2018
Posts: 115
Reputation: 1
Default Re: Vehicle wont show correctly

Quote:
Originally Posted by Kwarde View Post
What's the code under OnDialogResponse()?

Also:
Code:
for(new i = 1; i <= cache_num_rows(); i++)
I suggest you to use:
Code:
for (new i, rows = cache_num_rows(); i < rows; i++)
//Or, even better yet:
new rows;
cache_get_row_count(rows);
for (new i; i < rows; i++)
(Or, i = 1 and i <= rows. However, 0 is always the first row so this piece of code skips the first result).
When you use cache_num_rows() in the statement part of the for() loop, it gets called every loop. When you assign it the way I did, cache_num_rows() is called once.
Also: https://forum.sa-mp.com/showpost.php...4&postcount=12

Also also, I highly recommend you to use threaded queries.
If your MySQL server would be lagging somehow, your entire server will freeze for everyone after using /v untill the results come in and are handled.
Oh thanks man, that is better.

Code:
case DIALOG_CARS:
    	{
    		new string[64], carid = listitem;

    		format(string, sizeof(string), "Selected: %d - PosX: %f", carid, CarInfo[carid][CarPosX]);
    		SCM(playerid, -1, string);
    	}
This code i use to check theyr coords if it matches my cars and not someone else.
MarianImmortalGod is offline   Reply With Quote
Old 28/06/2020, 10:47 AM   #5
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,735
Reputation: 1686
Default Re: Vehicle wont show correctly

I thought so. listitem is not the same as the carid.
Let's say you have three results:

* Infernus (carid 5)[listitem = 0]
* Turismo (carid 9)[listitem = 1]
* NRG (carid 12)[listitem = 2]

I think that says enough . You would either have to create some PVars to store the carid to the right listitem, or run the SQL code again to run the same code as in /v. If no data was altered, the listitem would be the same as the row number.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 28/06/2020, 10:55 AM   #6
MarianImmortalGod
Big Clucker
 
Join Date: Mar 2018
Posts: 115
Reputation: 1
Default Re: Vehicle wont show correctly

Quote:
Originally Posted by Kwarde View Post
I thought so. listitem is not the same as the carid.
Let's say you have three results:

* Infernus (carid 5)[listitem = 0]
* Turismo (carid 9)[listitem = 1]
* NRG (carid 12)[listitem = 2]

I think that says enough . You would either have to create some PVars to store the carid to the right listitem, or run the SQL code again to run the same code as in /v. If no data was altered, the listitem would be the same as the row number.
Thanks verry much my friend, you are the best.
Everything works fine now.

Solved:

I added in my cmd.

Code:
new count = 0;
Selected[playerid][count] = carid;
count++;
and in the dialog i used

Code:
Selected[playerid][listitem]
Thanks @Kwarde
MarianImmortalGod is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dialog doesn't show correctly ShadowBlack Scripting Help 0 23/04/2018 03:16 PM
IP won't show correctly Youssef214 Scripting Help 2 04/07/2014 11:30 PM
This wont get the armour correctly. Dokins Scripting Help 2 26/11/2012 12:36 AM
Airlines wont load correctly Luis- Scripting Help 4 11/04/2012 11:13 PM
IP doesnt show correctly HydraX Help Archive 15 18/01/2010 07:42 PM


All times are GMT. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.