How can I detect the players that used X command?
#1

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...
Reply
#2

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
Reply
#3

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.
Reply
#4

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

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;
}
Reply
#6

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?
Reply
#7

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
Reply
#8

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.
Reply
#9

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?
Reply
#10

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!
Reply
#11

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


Forum Jump:


Users browsing this thread: 1 Guest(s)