SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 08/11/2019, 10:04 AM   #21
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: /wantedcars list Command is bugging

Well, my command should delete one car of the list out of the database, so that the list ingame is deleting it too, you know?

So if i have car 1, i want to delete car 1 from the database, and the ingame list
ImTobi is offline   Reply With Quote
Old 08/11/2019, 10:36 AM   #22
RoboN1X
Huge Clucker
 
RoboN1X's Avatar
 
Join Date: Feb 2011
Location: Indonesia
Posts: 445
Reputation: 128
Default Re: /wantedcars list Command is bugging

Quote:
Originally Posted by ImTobi View Post
Well, my command should delete one car of the list out of the database, so that the list ingame is deleting it too, you know?

So if i have car 1, i want to delete car 1 from the database, and the ingame list
Alright then show the code for the delete command, the dialog, and the callback too, just like how everything you did in the first post for /wantedcars list
__________________
Need Help? Use Search, WIKI, and FAQ
RoboN1X is offline   Reply With Quote
Old 08/11/2019, 12:33 PM   #23
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: /wantedcars list Command is bugging

Delete Command

Code:
CMD:delsucar(playerid,params[])
{
	if(!eingeloggt[playerid])return NOT_LOGGEDIN(playerid);
	if(!IsPlayerInFraktion(playerid,1) && !IsPlayerInFraktion(playerid,4))return SendClientMessage(playerid, COLOR_RED, "Du bist kein Mitglied vom SFPD oder LSPD.");
	if(pInfo[playerid][duty] != 1)return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
	new carid;
	if(sscanf(params,"i",carid))return SendClientMessage(playerid, COLOR_RED, "INFO: /delsucar [ID]");
	new query[128];
	new query3[128];
	format(query3,sizeof(query3),"SELECT * FROM wantedcars");
	mysql_function_query(dbhandle,query3,true,"LoadWantedCars","");
	for(new i=0; i<sizeof(wInfo); i++)
	{
		if(!strlen(wInfo[i][CarModel]))continue;
		if(carid != wInfo[i][db_id])return SendClientMessage(playerid, COLOR_RED, "Nicht existierende ID angegeben.");
		format(query,sizeof(query),"DELETE FROM wantedcars WHERE id='%i'",wInfo[i][db_id]);
		SendFormatMessage(playerid,COLOR_YELLOW,"Du hast den Eintrag mit der ID %i gelöscht (%s)",wInfo[i][db_id],wInfo[i][CarModel]);
		strcpy(wInfo[i][CarModel],"",128);
		break;
	}
	mysql_query(dbhandle, query, false);
	return 1;
}
Dialog:

Code:
case 2:
				{
					if(!eingeloggt[playerid])return NOT_LOGGEDIN(playerid);
					if(!IsPlayerInFraktion(playerid,1) && !IsPlayerInFraktion(playerid,4))return SendClientMessage(playerid, COLOR_RED, "Du bist kein Mitglied vom SFPD oder LSPD.");
					if(pInfo[playerid][duty] != 1)return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
					new string[4096];
					new query3[128];
					format(query3,sizeof(query3),"SELECT * FROM wantedcars");
					mysql_function_query(dbhandle,query3,true,"LoadWantedCars","");
					format(string,sizeof(string),"ID\tBeschreibung\tKennzeichen\tGrund\n");
					for(new i=0; i<sizeof(wInfo); i++)
					{
						if (strlen(wInfo[i][CarModel]))
						{
						 	format(string,sizeof(string),"%s%i\t%s\t%s\t%s\n",string,wInfo[i][db_id],wInfo[i][CarModel],wInfo[i][WantedKennzeichen],wInfo[i][WantedGrund]);   
						 	ShowPlayerDialog(playerid, WANTEDCARSDIALOG, DIALOG_STYLE_TABLIST_HEADERS,"Gesuchte Fahrzeuge - SFPD | LSPD", string, "Okay", "");
						}
					}
					//ShowPlayerDialog(playerid, WANTEDCARSDIALOG, DIALOG_STYLE_TABLIST_HEADERS,"Gesuchte Fahrzeuge - SFPD | LSPD", string, "Okay", "");
				}
ImTobi is offline   Reply With Quote
Old 08/11/2019, 01:42 PM   #24
RoboN1X
Huge Clucker
 
RoboN1X's Avatar
 
Join Date: Feb 2011
Location: Indonesia
Posts: 445
Reputation: 128
Default Re: /wantedcars list Command is bugging

You wanted to delete it but why you run query to load it?
pawn Code:
CMD:delsucar(playerid, params[])
{
    if (!eingeloggt[playerid]) return NOT_LOGGEDIN(playerid);
    if (!IsPlayerInFraktion(playerid, 1) && !IsPlayerInFraktion(playerid, 4)) return SendClientMessage(playerid, COLOR_RED, "Du bist kein Mitglied vom SFPD oder LSPD.");
    if (pInfo[playerid][duty] != 1) return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
    new carid;
    if (sscanf(params, "i", carid)) return SendClientMessage(playerid, COLOR_RED, "INFO: /delsucar [ID]");
    new bool:idfound = false;
    for (new i = 0; i < sizeof (wInfo); i++)
    {
        if (carid == wInfo[i][db_id])
        {
            found = true;
            new query[128];
            format(query, sizeof (query), "DELETE FROM wantedcars WHERE id=%i", wInfo[i][db_id]);
            if (mysql_function_query(dbhandle, query, false))
            {
                SendFormatMessage(playerid, COLOR_YELLOW, "Du hast den Eintrag mit der ID %i gelöscht (%s)", wInfo[i][db_id], wInfo[i][CarModel]);
                new clearWInfo[WantedCarsEnum]; // empty record
                wInfo[i] = clearWInfo; // set all to zero
            }
            break;
        }
    }
    if (!idfound) return SendClientMessage(playerid, COLOR_RED, "Nicht existierende ID angegeben.");
    return 1;
}

You cannot list the dialog when you just send the query, it should be done after the callback is processed. Because it is not in same thread.

So I don't understand why you need this?
pawn Code:
format(query3, sizeof (query3), "SELECT * FROM wantedcars");
mysql_function_query(dbhandle, query3, true, "LoadWantedCars", "");
You will need to create another callback if you want to continue loading wanted cars before showing the dialog.

If it is not needed then just read the current records..
pawn Code:
case 2:
{
    if (!eingeloggt[playerid]) return NOT_LOGGEDIN(playerid);
    if (!IsPlayerInFraktion(playerid, 1) && !IsPlayerInFraktion(playerid, 4)) return SendClientMessage(playerid, COLOR_RED, "Du bist kein Mitglied vom SFPD oder LSPD.");
    if (pInfo[playerid][duty] != 1) return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
    new string[4096]; // prepare dialog string
    string = "ID\tBeschreibung\tKennzeichen\tGrund"; // set header
    for (new i = 0; i < sizeof (wInfo); i++) // loop through items
    {
        if (strlen(wInfo[i][CarModel])) // car model exist
        {
            format(string, sizeof (string), "%s\n%i\t%s\t%s\t%s", string, wInfo[i][db_id], wInfo[i][CarModel], wInfo[i][WantedKennzeichen], wInfo[i][WantedGrund]); // add it to the line
        }
    }
    ShowPlayerDialog(playerid, WANTEDCARSDIALOG, DIALOG_STYLE_TABLIST_HEADERS, "Gesuchte Fahrzeuge - SFPD | LSPD", string, "Okay", ""); // show the dialog list
}
Most likely you only need this as the dialog is asynchronous anyway, even if you code to show the list after loading from database, theres still chance the item got updated (e.g. by another police) during looking at the dialog.
__________________
Need Help? Use Search, WIKI, and FAQ
RoboN1X is offline   Reply With Quote
Old 08/11/2019, 01:50 PM   #25
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: /wantedcars list Command is bugging

Thanks for your help, will try your code later REP+ i'm gonna reply when i'm done
ImTobi is offline   Reply With Quote
Old 08/11/2019, 03:06 PM   #26
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: /wantedcars list Command is bugging

Code:
if (mysql_query(dbhandle, query, false))
            {
                SendFormatMessage(playerid, COLOR_YELLOW, "Du hast den Eintrag mit der ID %i gelöscht (%s)", wInfo[i][db_id], wInfo[i][CarModel]);
                new clearWInfo[WantedCarsEnum]; // empty record
                wInfo[i] = clearWInfo; // set all to zero
            }
the if(mysql_function_query)) is not working it says "D:\Users\Tobias\Desktop\SAMPServer\gamemodes\Real life.pwn(7745) : error 017: undefined symbol "mysql_function_query"" because thee are arguments missing, and with mysql_query its not working
ImTobi is offline   Reply With Quote
Old 08/11/2019, 04:31 PM   #27
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: /wantedcars list Command is bugging

Quote:
Originally Posted by RoboN1X View Post
You wanted to delete it but why you run query to load it?
pawn Code:
CMD:delsucar(playerid, params[])
{
    if (!eingeloggt[playerid]) return NOT_LOGGEDIN(playerid);
    if (!IsPlayerInFraktion(playerid, 1) && !IsPlayerInFraktion(playerid, 4)) return SendClientMessage(playerid, COLOR_RED, "Du bist kein Mitglied vom SFPD oder LSPD.");
    if (pInfo[playerid][duty] != 1) return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
    new carid;
    if (sscanf(params, "i", carid)) return SendClientMessage(playerid, COLOR_RED, "INFO: /delsucar [ID]");
    new bool:idfound = false;
    for (new i = 0; i < sizeof (wInfo); i++)
    {
        if (carid == wInfo[i][db_id])
        {
            found = true;
            new query[128];
            format(query, sizeof (query), "DELETE FROM wantedcars WHERE id=%i", wInfo[i][db_id]);
            if (mysql_function_query(dbhandle, query, false))
            {
                SendFormatMessage(playerid, COLOR_YELLOW, "Du hast den Eintrag mit der ID %i gelöscht (%s)", wInfo[i][db_id], wInfo[i][CarModel]);
                new clearWInfo[WantedCarsEnum]; // empty record
                wInfo[i] = clearWInfo; // set all to zero
            }
            break;
        }
    }
    if (!idfound) return SendClientMessage(playerid, COLOR_RED, "Nicht existierende ID angegeben.");
    return 1;
}

You cannot list the dialog when you just send the query, it should be done after the callback is processed. Because it is not in same thread.

So I don't understand why you need this?
pawn Code:
format(query3, sizeof (query3), "SELECT * FROM wantedcars");
mysql_function_query(dbhandle, query3, true, "LoadWantedCars", "");
You will need to create another callback if you want to continue loading wanted cars before showing the dialog.

If it is not needed then just read the current records..
pawn Code:
case 2:
{
    if (!eingeloggt[playerid]) return NOT_LOGGEDIN(playerid);
    if (!IsPlayerInFraktion(playerid, 1) && !IsPlayerInFraktion(playerid, 4)) return SendClientMessage(playerid, COLOR_RED, "Du bist kein Mitglied vom SFPD oder LSPD.");
    if (pInfo[playerid][duty] != 1) return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
    new string[4096]; // prepare dialog string
    string = "ID\tBeschreibung\tKennzeichen\tGrund"; // set header
    for (new i = 0; i < sizeof (wInfo); i++) // loop through items
    {
        if (strlen(wInfo[i][CarModel])) // car model exist
        {
            format(string, sizeof (string), "%s\n%i\t%s\t%s\t%s", string, wInfo[i][db_id], wInfo[i][CarModel], wInfo[i][WantedKennzeichen], wInfo[i][WantedGrund]); // add it to the line
        }
    }
    ShowPlayerDialog(playerid, WANTEDCARSDIALOG, DIALOG_STYLE_TABLIST_HEADERS, "Gesuchte Fahrzeuge - SFPD | LSPD", string, "Okay", ""); // show the dialog list
}
Most likely you only need this as the dialog is asynchronous anyway, even if you code to show the list after loading from database, theres still chance the item got updated (e.g. by another police) during looking at the dialog.

OMG THANK YOU, IT NOW WORKS! You are the best!
ImTobi 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
Bug List Command Keyhead Scripting Help 0 13/03/2014 03:19 AM
2 in 1 Command List kbalor Scripting Help 6 16/07/2012 03:18 PM
command debugging/bugging/halting(not crashing) the server. The_Gangstas Help Archive 3 27/12/2010 08:21 PM
Command list [asg]davo Help Archive 4 26/05/2010 12:16 PM
list command Schock Help Archive 0 01/03/2009 02:54 PM


All times are GMT. The time now is 03:18 PM.


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