SA-MP Forums Archive
How can I do a command with params using YCMD? - 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: How can I do a command with params using YCMD? (/showthread.php?tid=565543)



How can I do a command with params using YCMD? - WhoIsYourDaddy - 28.02.2015

Код:
YCMD:meslek(playerid, params[], help)
{
	new meslekID[3];
	if(isnull(params))
	{
		SendClientMessage(playerid, -1, "<KULLANIM> /meslek [olustur/duzenle/sil/git]");
	}
	return 1;
}
I used like this. If player types the command like "/meslek olustur" it does something but I couldn't do it. Should I use sscanf or what?


Re: How can I do a command with params using YCMD? - AroseKhanNiazi - 28.02.2015

yes use sscanf or strcmp


Re: How can I do a command with params using YCMD? - WhoIsYourDaddy - 28.02.2015

Can you make an example?


Re: How can I do a command with params using YCMD? - CalvinC - 28.02.2015

No need to use sscanf if you just have 1 string parameter, you can just use strcmp.
pawn Код:
YCMD:meslek(playerid, params[], help)
{
    if(isnull(params)) return SendClientMessage(playerid, -1, "<KULLANIM> /meslek [olustur/duzenle/sil/git]");
    if(!strcmp(params, "olustur", true))
    {
        // Code
    }
    else if(!strcmp(params, "duzenle", true))
    {
        // Code
    }
    else if(!strcmp(params, "sil", true))
    {
        // Code
    }
    else if(!strcmp(params, "gil", true))
    {
        // Code
    }
    return 1;
}
Params is the text you write after the cmd, like "/meslek [params]".
So strcmp just compares the "params" with the other text we provide, like "gil", and check if it's the same.
So if "params" is "gil", then it will activate the code below that.

But if you want to have several parameters, like "/meslek [params] [more params]", then you need to use sscanf.


Re: How can I do a command with params using YCMD? - WhoIsYourDaddy - 28.02.2015

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
No need to use sscanf if you just have 1 string parameter, you can just use strcmp.
pawn Код:
YCMD:meslek(playerid, params[], help)
{
    if(isnull(params)) return SendClientMessage(playerid, -1, "<KULLANIM> /meslek [olustur/duzenle/sil/git]");
    if(!strcmp(params, "olustur", true))
    {
        // Code
    }
    else if(!strcmp(params, "duzenle", true))
    {
        // Code
    }
    else if(!strcmp(params, "sil", true))
    {
        // Code
    }
    else if(!strcmp(params, "gil", true))
    {
        // Code
    }
    return 1;
}
Params is the text you write after the cmd, like "/meslek [params]".
So strcmp just compares the "params" with the other text we provide, like "gil", and check if it's the same.
So if "params" is "gil", then it will activate the code below that.

But if you want to have several parameters, like "/meslek [params] [more params]", then you need to use sscanf.
Thank you very much. Rep added.