Playerid after command
#1

I am sorry but i have had a few beers, and i forgot where to get/find after a command
there is playerid EX.

Код:
/pm [playerid]
But i want to know what you put in so the playerid actually works.

Say say i am a noob all you want.
Reply
#2

that is an example for /pm u can learn from it :

under OnPlayerCommandText :
Код:
new cmd[256];
	if(strcmp("/pm", cmd, true) == 0)
	{
	  new idx;
	  new iName[MAX_PLAYER_NAME+1];
	  new	tmp[256];
	  new id;
		new Message[256];
		new gMessage[256];
	  new pName[MAX_PLAYER_NAME+1];
		tmp = strtok(cmdtext,idx);

		if(!strlen(tmp) || strlen(tmp) > 5) {
			SendClientMessage(playerid,0xFFFF00AA,"Usage: /pm [id] (Message)");
			return 1;
		}

 		id = strval(tmp);
		gMessage = strrest(cmdtext,idx);

		if(!strlen(gMessage)) {
			SendClientMessage(playerid,0xFFFF00AA,"Usage: /pm [id] [Message]");
			return 1;
		}

		if(!IsPlayerConnected(id)) {
			SendClientMessage(playerid,0xFFFF00AA,"Bad player ID");
			return 1;
		}

		if(playerid != id) {
			GetPlayerName(id,iName,sizeof(iName));
			GetPlayerName(playerid,pName,sizeof(pName));
			format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage);
			SendClientMessage(playerid,0xFFCC2299,Message);
			format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
			SendClientMessage(id,0xFFFF22AA,Message);
			PlayerPlaySound(id,1085,0.0,0.0,0.0);

			printf("PM: %s",Message);

		}
		else {
			SendClientMessage(playerid,0xFFFF00AA,"You cannot PM yourself");
		}
		return 1;
	}
bottom of ur script :
Код:
//------------------------------------------------------------------------------------------------------------
stock strrest(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}
	new offset = index;
	new result[128];
	while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
//------------------------------------------------------------------------------------------------------
stock strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
//------------------------------------------------------------------------------------------------------
Reply
#3

I don't need PM but i just use the

Код:
iName[MAX_PLAYER_NAME+1];
For a command like

/ticket,/cuff, etc
Reply
#4

Go to the SA-MP Wiki and learn about Fast Command Processing (DCMD, SSCANF).

https://sampwiki.blast.hk/wiki/Fast_Commands

Try not to get into strtok, even though it works, it works in the most unefficient way..
Reply
#5

I know that it is, and thanks i have been looking at this, and thinking.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)