SA-MP Forums Archive
MDC System Problem - 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: MDC System Problem (/showthread.php?tid=583055)



Number of arguments does not match definition - Luke_James - 25.07.2015

I've done this MDC thing, but I'm having trouble calling it in the /mdc command. It should, if the player name IS valid, call "OnMDCLookup" but when I compile the script, I get these errors...

Quote:

(39712) : warning 202: number of arguments does not match definition
(39712) : warning 202: number of arguments does not match definition

This is the line throwing the error up...
Код:
IsValidPlayerName(name, "OnMDCLookup", playerid);
pawn Код:
forward OnMDCLookup(playerid, name[]);
public OnMDCLookup(playerid, name[])
{
    new msg[128];
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows < 1)
    {
        SendClientMessage(playerid, COLOR_GREY, "No records found.");
        return 1;
    }
    cache_get_row(0, 0, msg);
    MDCLookup(playerid, strval(msg));
    return 1;
}

MDCLookup(playerid, id)
{
    new msg[256];
    format(msg, sizeof(msg), "SELECT `c1`.`character`,`c1`.`phone`,`c1`.`id` FROM `characters` AS `c1` WHERE `c1`.`id` = %d", id);
    mysql_function_query(g_iHandle, msg, true, "OnMDCRetrieve", "d", playerid);
}

forward OnMDCRetrieve(playerid);
public OnMDCRetrieve(playerid)
{
    new string[128], id_string[128];
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows < 1) return 0;

    SendClientMessage(playerid, COLOR_GREY,"|__________LSPD Mobile Data Computer__________|");
    cache_get_row(0, 0, id_string);

    format(string, sizeof(string), "NAME: %s", id_string);
    SendClientMessage(playerid, COLOR_WHITE, string);
    cache_get_row(0, 1, id_string);

    format(string, sizeof(string), "CONTACT NUMBER: %s", id_string);
    SendClientMessage(playerid, COLOR_WHITE, string);
    cache_get_row(0, 2, id_string);
    return 1;
}
pawn Код:
CMD:mdc(playerid, params[])
{
    if (GetFactionType(playerid) != FACTION_POLICE)
        return SendErrorMessage(playerid, "You must be a police officer.");

    if (!IsACruiser(GetPlayerVehicleID(playerid)))
        return SendErrorMessage(playerid, "You must be inside a police cruiser.");

    new name[MAX_PLAYER_NAME];
    if(!sscanf(params, "s[" #MAX_PLAYER_NAME "]", name)) {
        IsValidPlayerName(name, "OnMDCLookup", playerid);
    }

    else {
        return SendSyntaxMessage(playerid, "/mdc [player name]");
    }
    return 1;
}



AW: MDC System Problem - Macronix - 25.07.2015

Can you show me the "IsValidPlayerName" function?


Re: MDC System Problem - Luke_James - 25.07.2015

Код:
IsValidPlayerName(const str[])
{
	if (!str[0] || str[0] == '\1')
		return 0;

	for (new i = 0, l = strlen(str); i != l; i ++)
	{
	    if ((str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
	        continue;

		if (str[i] == '_' || str[i] == '$' || str[i] == '@' || str[i] == '[' || str[i] == ']')
		    continue;

		else
		    return 0;
	}
	return 1;
}
Oops


AW: MDC System Problem - Macronix - 25.07.2015

Try this:
Код:
if(IsValidPlayerName(name))
{
      OnMDCLookup(playerid, name);
}



Re: MDC System Problem - Luke_James - 25.07.2015

It's now compiling, thank you.

However, when I type in a player's name correctly it says "No records found" (as is supposed to happen if there's no such player) - any ideas?

pawn Код:
CMD:mdc(playerid, params[])
{
    if (GetFactionType(playerid) != FACTION_POLICE)
        return SendErrorMessage(playerid, "You must be a police officer.");

    if (!IsACruiser(GetPlayerVehicleID(playerid)))
        return SendErrorMessage(playerid, "You must be inside a police cruiser.");

    new name[MAX_PLAYER_NAME];
    if(!sscanf(params,"s[" #MAX_PLAYER_NAME "]", name)) {
        if(IsValidPlayerName(name)) {
            OnMDCLookup(playerid, name);
        }
    }
    else {
        return SendSyntaxMessage(playerid, "/mdc [player name]");
    }
    return 1;
}



AW: MDC System Problem - Macronix - 25.07.2015

Do you have a "name" variable in your table "characters"? Then you could try something like that:
Код:
MDCLookup(playerid, name[])
{
	new msg[256];
	format(msg, sizeof(msg), "SELECT `c1`.`character`,`c1`.`phone`,`c1`.`id` FROM `characters` AS `c1` WHERE `c1`.`name` = %s", name); //try to search a record by "name" and not "id"
	mysql_function_query(g_iHandle, msg, true, "OnMDCRetrieve", "d", playerid);
}

forward OnMDCRetrieve(playerid);
public OnMDCRetrieve(playerid)
{
	new string[128], id_string[128];
	new rows, fields;
	cache_get_data(rows, fields);
	if(rows < 1)
	{
		SendClientMessage(playerid, COLOR_GREY, "No records found.");
		return 1;
	}

	SendClientMessage(playerid, COLOR_GREY,"|__________LSPD Mobile Data Computer__________|");
	cache_get_row(0, 0, id_string);

	format(string, sizeof(string), "NAME: %s", id_string);
	SendClientMessage(playerid, COLOR_WHITE, string);
	cache_get_row(0, 1, id_string);

	format(string, sizeof(string), "CONTACT NUMBER: %s", id_string);
	SendClientMessage(playerid, COLOR_WHITE, string);
	cache_get_row(0, 2, id_string);
	return 1;
}

CMD:mdc(playerid, params[])
{
	if (GetFactionType(playerid) != FACTION_POLICE)
	    return SendErrorMessage(playerid, "You must be a police officer.");

	if (!IsACruiser(GetPlayerVehicleID(playerid)))
	    return SendErrorMessage(playerid, "You must be inside a police cruiser.");

	new name[MAX_PLAYER_NAME];
	if(!sscanf(params, "s[" #MAX_PLAYER_NAME "]", name)) {
		if(IsValidPlayerName(name))
		{
		    MDCLookup(playerid, name);
		}
	}

	else {
	    return SendSyntaxMessage(playerid, "/mdc [player name]");
	}
	return 1;
}



Re: MDC System Problem - Luke_James - 25.07.2015

I don't; what would be the need for one?


AW: MDC System Problem - Macronix - 25.07.2015

Because you use it in your command?


Re: AW: MDC System Problem - Luke_James - 25.07.2015

Quote:
Originally Posted by Macronix
Посмотреть сообщение
Because you use it in your command?
The name variable just checks that the name the player types is valid and then looks for that name in the "characters" table; character names are saved under "character".

Quote:
Originally Posted by DarkLored
Посмотреть сообщение
try this

pawn Код:
public OnMDCLookup(playerid, name[])
{
    new msg[128];
    new rows, fields;
        MDCLookup(playerid, strval(msg));
    cache_get_data(rows, fields);
    if(rows < 1)
    {
        SendClientMessage(playerid, COLOR_GREY, "No records found.");
        return 1;
    }
    cache_get_row(0, 0, msg);
    return 1;
}
I'm not sure how your code works but I am pretty sure that you first need to SELECT the data before getting it in rows.
That didn't work :/


Re: AW: MDC System Problem - Luke_James - 25.07.2015

Quote:
Originally Posted by Macronix
Посмотреть сообщение
Do you have a "name" variable in your table "characters"? Then you could try something like that:
Код:
MDCLookup(playerid, name[])
{
	new msg[256];
	format(msg, sizeof(msg), "SELECT `c1`.`character`,`c1`.`phone`,`c1`.`id` FROM `characters` AS `c1` WHERE `c1`.`name` = %s", name); //try to search a record by "name" and not "id"
	mysql_function_query(g_iHandle, msg, true, "OnMDCRetrieve", "d", playerid);
}

forward OnMDCRetrieve(playerid);
public OnMDCRetrieve(playerid)
{
	new string[128], id_string[128];
	new rows, fields;
	cache_get_data(rows, fields);
	if(rows < 1)
	{
		SendClientMessage(playerid, COLOR_GREY, "No records found.");
		return 1;
	}

	SendClientMessage(playerid, COLOR_GREY,"|__________LSPD Mobile Data Computer__________|");
	cache_get_row(0, 0, id_string);

	format(string, sizeof(string), "NAME: %s", id_string);
	SendClientMessage(playerid, COLOR_WHITE, string);
	cache_get_row(0, 1, id_string);

	format(string, sizeof(string), "CONTACT NUMBER: %s", id_string);
	SendClientMessage(playerid, COLOR_WHITE, string);
	cache_get_row(0, 2, id_string);
	return 1;
}

CMD:mdc(playerid, params[])
{
	if (GetFactionType(playerid) != FACTION_POLICE)
	    return SendErrorMessage(playerid, "You must be a police officer.");

	if (!IsACruiser(GetPlayerVehicleID(playerid)))
	    return SendErrorMessage(playerid, "You must be inside a police cruiser.");

	new name[MAX_PLAYER_NAME];
	if(!sscanf(params, "s[" #MAX_PLAYER_NAME "]", name)) {
		if(IsValidPlayerName(name))
		{
		    MDCLookup(playerid, name);
		}
	}

	else {
	    return SendSyntaxMessage(playerid, "/mdc [player name]");
	}
	return 1;
}
When I use that code, using /mdc does nothing, I don't even get the "No records found" error