Admin. chat.
#1

Код:
 	
  if(strcmp(cmd, "/ac", true, 3) == 0)// 3 is the length of /me
  {
  if(!strlen(cmdtext[3])) return SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /ac [action]");
  GetPlayerName(playerid, Aname, sizeof(Aname));
	for(new i=0; i < MAX_PLAYERS; i++)
		{
			if(GetPlayerAdminLvl(i) >= 1)
				{
 				if(IsPlayerConnected(i))
					{
				  format(string, sizeof(string), "[ ADMIN ] %s : %s",Aname,cmdtext[4]);
	  			printf(string);
					SendClientMessage(i,COLOR_LIGHTFLASHRED, string);
  				}
  			}
  	}
	return 1;
  }
How can i make this without using cmdtext ?

Reply
#2

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

Look at the dcmd / sscanf bit.
Reply
#3

Hmm, look to another admin scripts.
Do at the top of your script:

pawn Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
I don't work with dcmd, but you should give it a try
Reply
#4

Quote:
Originally Posted by speedruntrainer
Hmm, look to another admin scripts.
Do at the top of your script:

pawn Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
I don't work with dcmd, but you should give it a try
I made my own admi script, and i don't use dcmd. And i know there is a way to do what i want without that !
Reply
#5

Код:
if(strcmp(cmd, "/ac", true, 3) == 0)
  	    {
  	    tmp=strtok(cmdtext, idx);
  	    if(!strlen(tmp))
  	        {
			SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /ac [action]");
			return 1;
			}
		else if(strlen(tmp))
		    {
	  	    GetPlayerName(playerid, Aname, sizeof(Aname));
			for(new i=0; i < MAX_PLAYERS; i++)
				{
				if(GetPlayerAdminLvl(i) >= 1)
					{
	 				if(IsPlayerConnected(i))
						{
					    format(string, sizeof(string), "[ADMIN]%s: %s",Aname,tmp);
		  			    printf(string);
						SendClientMessage(i,COLOR_LIGHTFLASHRED, string);
                        return 1;
 						}
  					}
	  		    }
			}
	    }
Reply
#6

this is wrong : if(GetPlayerAdminLvl(i) >= 1)

All players will can to use that command
Reply
#7

Quote:
Originally Posted by Angel φ
this is wrong : if(GetPlayerAdminLvl(i) >= 1)

All players will can to use that command
No. Because usually your admin level is 0 if you're not an admin.
But >= means that left is larger or equal to right.
Reply
#8

Thankx Ronyx !!
Reply
#9

In fact it's just appearing the first word i write ..
Reply
#10

Код:
if(strcmp(cmd, "/ac", true, 3) == 0)
  	    {
  	    tmp=strtok(cmdtext, idx);
  	    if(!strlen(tmp))
  	        {
			SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /ac [action]");
			return 1;
			}
		else if(strlen(tmp))
		    {
	  	    GetPlayerName(playerid, Aname, sizeof(Aname));
			for(new i=0; i < MAX_PLAYERS; i++)
				{
				if(GetPlayerAdminLvl(i) >= 1)
					{
	 				if(IsPlayerConnected(i))
						{
					    format(string, sizeof(string), "[ADMIN]%s: %s",Aname,tmp);
		  			    printf(string);
						SendClientMessage(i,COLOR_LIGHTFLASHRED, string);
                        return 1;
 						}
  					}
	  		    }
			}
	    }
Change:
Код:
tmp=strtok(cmdtext, idx);
To
Код:
tmp=bigstrtok(cmdtext, idx);
If you don't have, this is the bigstrtok function. Place anywhere in your script since it's not in a callback.
Код:
stock bigstrtok(const string[], &idx)
	{
  new length = strlen(string);
	while ((idx < length) && (string[idx] <= ' '))
		{
		idx++;
		}
	new offset = idx;
	new result[128];
	while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
		{
		result[idx - offset] = string[idx];
		idx++;
		}
	result[idx - offset] = EOS;
	return result;
	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)