SA-MP Forums Archive
Problem with sscanf - 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: Problem with sscanf (/showthread.php?tid=618267)



Problem with sscanf - Eoussama - 03.10.2016

Hello guys, so I was making an admin command, but the compiler always gives me this error
Quote:

C:\Users\Oussama\Desktop\test serv - Copy\gamemodes\test.pwn(76) : error 035: argument type mismatch (argument 1)
This is my code
Код:
CMD:setlevel(playerid, params) {
	if(IsPlayerAdmin(playerid))
	{
	    new
			string[36],
			pname[MAX_PLAYER_NAME],
			tname[MAX_PLAYER_NAME];
		new id, level;
	    if(sscanf(params, "u", id, level)) return SendClientMessage(playerid, -1, "USAGE: /makeadmin (playerid) (level)");
		if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000, "[ERROR]: This player is not connected!");
		if(level < 1 || level > 3) return SendClientMessage(playerid, 0xFF0000, "Available levels (1-4)");
		GetPlayerName(playerid, pname, sizeof(pname));
	    GetPlayerName(id, tname, sizeof(tname));
		format(string, sizeof(string), "Administrator %s has promoted %s to level %i admin", pname, tname, level);
	    SendClientMessageToAll(-1, string);
		PlayerInfo[id][AdminLevel] = level;
		new INI:File = INI_Open(AdminPath(id));
		INI_SetTag(File, "AdminData");
		INI_WriteInt(File, "AdminLevel", PlayerInfo[id][AdminLevel]);
		INI_Close(File);
		return 1;
	}
	else {
		SendClientMessage(playerid, 0xFF00008, "[ERROR]: you are not authorized to use this command");
		return 1;
	}
}

the line in GREEN is the problem



Re: Problem with sscanf - Konstantinos - 03.10.2016

Код:
CMD:setlevel(playerid, params[])



Re: Problem with sscanf - Eoussama - 03.10.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Код:
CMD:setlevel(playerid, params[])
OMG, how come didn't I see that,
mate thank you so much


Re: Problem with sscanf - Eoussama - 03.10.2016

There is another problem which happens to me so often,
now the compiler scans the script just fine with no errors, but when I log in game to try these commands, they don't function as they should,
the server loads only ( if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, 0xFF0000, " USAGE: /setlevel (playerid) (level)); ) and every line below this doesn't execute, so no matter I did (whether I typed the command + all the params or not) It gives me the same USAGE message


Re: Problem with sscanf - Konstantinos - 03.10.2016

Looking again at your first post, you have 1 specifier ("u") and 2 arguments (id, level). In the above post, it is fixed but just make sure the number of specifiers is always equal to the number of arguments (excluding quite specifiers).


Re: Problem with sscanf - Eoussama - 03.10.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Looking again at your first post, you have 1 specifier ("u") and 2 arguments (id, level). In the above post, it is fixed but just make sure the number of specifiers is always equal to the number of arguments (excluding quite specifiers).
thanks for the tip;
I just need a solution for the 2nd problem I stated above


Re: Problem with sscanf - Eoussama - 03.10.2016

Even if I do ( /setlevel 5 2 ) to set's the player with the id 5 to level 2 It gives me the Client Message that's assigned to if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, 0xFF0000, "USAGE: /setlevel (playerid)(level)"); )


Re: Problem with sscanf - Eoussama - 03.10.2016

Nvm Problem solved! Thanks everybody