SA-MP Forums Archive
How can I detect the players that used X command? - 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 detect the players that used X command? (/showthread.php?tid=635373)



How can I detect the players that used X command? - Dragonic - 06.06.2017

How can I get the info that someone used X command? Let's say I use X command, then I'll be detected as first, then another player use the same command and then he is recognized as second.

Couldn't find a way to do this by looking at Arrays examples on the Wiki and on this forums, if it is even doable with arrays...


Re: How can I detect the players that used X command? - NealPeteros - 06.06.2017

Try adding a "print" function inside that command. For example:
PHP Code:
CMD:test(playeridparams[])
{
    
printf("[DETECTED CMD:] %s has just used /test"GetPlayerName(playerid));
    
/*Code here */

Not sure if that's what you need


Re: How can I detect the players that used X command? - Dragonic - 06.06.2017

Nope. I have a Racing system, everything works but I want players that type /Race to be put in different places, so like the first to type is send to position Z, the second to Y and on.


Re: How can I detect the players that used X command? - NealPeteros - 06.06.2017

Ah, so race to first for whoever types the command first? I apologize for misunderstanding your request.


Re: How can I detect the players that used X command? - lackmail - 06.06.2017

Code:
enum cInfo
{
    UsedCmdX1[MAX_PLAYER_NAME],
    UsedCmdX2[MAX_PLAYER_NAME],
    UsedCmdX3[MAX_PLAYER_NAME],
    UsedCmdX4[MAX_PLAYER_NAME],
    UsedCmdX5[MAX_PLAYER_NAME],
    TimesCmdXUsed,
};
new CommandInfo[cInfo];

CMD:x(playerid, parmas[])
{
	switch(CommandInfo[TimesCmdXUsed])
	{
	    case 0:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX1], sizeof(CommandInfo[UsedCmdX1]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 1:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX2], sizeof(CommandInfo[UsedCmdX2]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 2:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX3], sizeof(CommandInfo[UsedCmdX3]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 3:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX4], sizeof(CommandInfo[UsedCmdX4]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 4:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX5], sizeof(CommandInfo[UsedCmdX5]), "%s", GetName(playerid));
	        return 1;
	    }
	}
	return 1;
}

CMD:names(playerid, parmas[])
{
	new string[128];
	switch(CommandInfo[TimesCmdXUsed])
	{
	    case 0:
	    {
			SendClientMessage(playerid, -1, "   No one used command X !");
	        return 1;
	    }
	    case 1:
	    {
	        format(string, sizeof(string), "1- %s", CommandInfo[UsedCmdX1]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 2:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 3:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s\n3- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2], CommandInfo[UsedCmdX3]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 4:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s\n3- %s\n4- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2], CommandInfo[UsedCmdX3], CommandInfo[UsedCmdX4]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 5:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s\n3- %s\n4- %s\n5- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2], CommandInfo[UsedCmdX3], CommandInfo[UsedCmdX4], CommandInfo[UsedCmdX5]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	}
	return 1;
}

stock GetName(playerid);
{
    new szName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, szName, sizeof(szName));
    return szName;
}



Re: How can I detect the players that used X command? - Dragonic - 06.06.2017

Quote:
Originally Posted by lackmail
View Post
Code:
enum cInfo
{
    UsedCmdX1[MAX_PLAYER_NAME],
    UsedCmdX2[MAX_PLAYER_NAME],
    UsedCmdX3[MAX_PLAYER_NAME],
    UsedCmdX4[MAX_PLAYER_NAME],
    UsedCmdX5[MAX_PLAYER_NAME],
    TimesCmdXUsed,
};
new CommandInfo[cInfo];

CMD:x(playerid, parmas[])
{
	switch(CommandInfo[TimesCmdXUsed])
	{
	    case 0:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX1], sizeof(CommandInfo[UsedCmdX1]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 1:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX2], sizeof(CommandInfo[UsedCmdX2]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 2:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX3], sizeof(CommandInfo[UsedCmdX3]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 3:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX4], sizeof(CommandInfo[UsedCmdX4]), "%s", GetName(playerid));
	        return 1;
	    }
	    case 4:
	    {
	        CommandInfo[TimesCmdXUsed]++;
	        format(CommandInfo[UsedCmdX5], sizeof(CommandInfo[UsedCmdX5]), "%s", GetName(playerid));
	        return 1;
	    }
	}
	return 1;
}

CMD:names(playerid, parmas[])
{
	new string[128];
	switch(CommandInfo[TimesCmdXUsed])
	{
	    case 0:
	    {
			SendClientMessage(playerid, -1, "   No one used command X !");
	        return 1;
	    }
	    case 1:
	    {
	        format(string, sizeof(string), "1- %s", CommandInfo[UsedCmdX1]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 2:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 3:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s\n3- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2], CommandInfo[UsedCmdX3]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 4:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s\n3- %s\n4- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2], CommandInfo[UsedCmdX3], CommandInfo[UsedCmdX4]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	    case 5:
	    {
	        format(string, sizeof(string), "1- %s\n2- %s\n3- %s\n4- %s\n5- %s", CommandInfo[UsedCmdX1], CommandInfo[UsedCmdX2], CommandInfo[UsedCmdX3], CommandInfo[UsedCmdX4], CommandInfo[UsedCmdX5]);
	        ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Players used command X", string, "Close", "");
	        return 1;
	    }
	}
	return 1;
}

stock GetName(playerid);
{
    new szName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, szName, sizeof(szName));
    return szName;
}
And to reset that counting after let's say 5, so that the 6th player will be the 1st again?


Re: How can I detect the players that used X command? - lackmail - 06.06.2017

Quote:
Originally Posted by Dragonic
View Post
And to reset that counting after let's say 5, so that the 6th player will be the 1st again?
No my example code will stop storing names once TimesCmdXUsed equals 5


Re: How can I detect the players that used X command? - SyS - 06.06.2017

make use of OnPlayerCommandText or use a global variable to store number of times executed
Or use OnPlayerCommandReceived callback of zcmd when the limit is reached you can return 0 to block the command itself.


Re: How can I detect the players that used X command? - Beckett - 06.06.2017

Code:
new CommandCount;

CMD:thecommand(playerid,params[])
{
	new string[60];
 	CommandCount++;
	format(string,sizeof(string),"You are number %i in the queue.",CommandCount);
	SendClientMessage(playerid,-1,string);

	switch(CommandCount)
	{
	    case 0:
	    {
		   // do X
	    }
	    case 1:
	    {
		  // do Y
	    }
	    case 2:
	    {
			// do Z
		}
	}
	return 1;
}
Are you looking for something like this?


Re: How can I detect the players that used X command? - Dragonic - 06.06.2017

Quote:
Originally Posted by DaniceMcHarley
View Post
Code:
new CommandCount;

CMD:thecommand(playerid,params[])
{
	new string[60];
 	CommandCount++;
	format(string,sizeof(string),"You are number %i in the queue.",CommandCount);
	SendClientMessage(playerid,-1,string);

	switch(CommandCount)
	{
	    case 0:
	    {
		   // do X
	    }
	    case 1:
	    {
		  // do Y
	    }
	    case 2:
	    {
			// do Z
		}
	}
	return 1;
}
Are you looking for something like this?
Hey that works, thank you so much!


Re: How can I detect the players that used X command? - Beckett - 06.06.2017

Make sure to reset that variable when the race ends, or whatever it is that you're doing.