SA-MP Forums Archive
dmcd sscanf comand 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: dmcd sscanf comand problem (/showthread.php?tid=478356)



dmcd sscanf comand problem - moof2010 - 29.11.2013

I want to creat and chat for medics and i used this

Код:
dcmd_r(playerid, params[])
{
    if(strcmp(factiune[playerid],"Medic",true) == 0)
		{
		    new text[128];
		    if(sscanf(params,"s", text)) return SendClientMessage(playerid, 0xFFFFFFF,"Comanda gresita. Corect: /r text pentru a transmite ceva colegilor de factiune");
            new strr[128];
		    
			for (new i = 1; i <= MAX_PLAYERS; i++)
		        {
		            new medicnume[128];
		            GetPlayerName(i, medicnume, sizeof(medicnume));
		            if (strcmp(factiune[i],"Medic",true) == 0)
		                {
							format(strr,sizeof(strr),"Mesaj: \"%s\".",text);
		                    SendClientMessage(i, 0xFF00FFFF , strr);
		                }
		        }
		}
	else
	    {
	        SendClientMessage(playerid, 0xFF00FFFF , "Nu esti Medic sau Politist.");
	    }
    return 1;
}
and on OnPlayerCommandText i have

Код:
dcmd(r, 1, cmdtext);
when i write in game
Код:
/r text
the server say me that my comand don't exist and in log appear that
Код:
sscanf warning: Strings without a length are deprecated, please add a destination size.
if i write
Код:
/r
they say me that
Код:
Comanda gresita. Corect: /r text pentru a transmite ceva colegilor de factiune
How i can repair this?

+1rec for good respons


Re: dmcd sscanf comand problem - Konstantinos - 29.11.2013

You'll need to add the size to the "s" specifier. For example:

pawn Код:
if(sscanf(params,"s[128]", text)) return SendClientMessage(playerid, 0xFFFFFFF,"Comanda gresita. Corect: /r text pentru a transmite ceva colegilor de factiune");
But I'd recommend you to use params.

Also, the ID for the players starts from 0, not 1. You also don't use the name at all so there's not point on getting the name and storing it to an array.

pawn Код:
dcmd_r(playerid, params[])
{
    if(strcmp(factiune[playerid],"Medic",true) != 0) return SendClientMessage(playerid, 0xFF00FFFF , "Nu esti Medic sau Politist.");
    if(isnull(params)) return SendClientMessage(playerid, 0xFFFFFFF,"Comanda gresita. Corect: /r text pentru a transmite ceva colegilor de factiune");
    new strr[128];
    format(strr,sizeof(strr),"Mesaj: \"%s\".", params);
    for (new i; i != MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(!strcmp(factiune[i],"Medic",true)) SendClientMessage(i, 0xFF00FFFF , strr);
    }
    return 1;
}



Re: dmcd sscanf comand problem - moof2010 - 29.11.2013

Thank you very much, i used you recomandation