SA-MP Forums Archive
How do I create a stock with optional parameters? - 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 do I create a stock with optional parameters? (/showthread.php?tid=623666)



How do I create a stock with optional parameters? - danielpalade - 03.12.2016

I have this stock:

Код:
stock SS(playerid, color, eng[], ro[])
{
	if(playerVariables[playerid][pLang] == 0) //Ro
	{
		SCM(playerid, color, ro);
	}
	else if(playerVariables[playerid][pLang] == 1) //En
	{
		SCM(playerid, color, eng);
	}
	return 1;
}
If pLang == 0, it send the message ro[], else it sends the message eng[].
How can I make it so when you use: SS(playerid, COLOR_WHITE, "Test message");
it would send a normal message to the user, instead of checking if the variable is 0 or 1?


Re: How do I create a stock with optional parameters? - Stinged - 03.12.2016

You should use y_text or something similar if you want to make a multi-lang system.
But to answer your question, you can try doing this:

Код:
stock SS(playerid, color, eng[], ro[] = "")
{
	if (ro[0] == 0)
		return SCM(playerid, color, eng);
	switch(playerVariables[playerid][pLang])
	{
		case 0: SCM(playerid, color, ro);
		case 1: SCM(playerid, color, eng);
	}
	return 1;
}



Re: How do I create a stock with optional parameters? - SickAttack - 03.12.2016

pawn Код:
stock SS(playerid, color, eng[], ro[] = "")
{
    if (ro[0] == EOS)
        return SCM(playerid, color, eng);
    switch(playerVariables[playerid][pLang])
    {
        case 0: SCM(playerid, color, ro);
        case 1: SCM(playerid, color, eng);
    }
    return 1;
}
Function, not stock.