SA-MP Forums Archive
Admin. chat. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Admin. chat. (/showthread.php?tid=93161)



Admin. chat. - RaFsTar - 23.08.2009

Код:
 	
  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 ?




Re: Admin. chat. - Calgon - 23.08.2009

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

Look at the dcmd / sscanf bit.


Re: Admin. chat. - speedruntrainer - 23.08.2009

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


Re: Admin. chat. - RaFsTar - 23.08.2009

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 !


Re: Admin. chat. - ronyx69 - 23.08.2009

Код:
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;
 						}
  					}
	  		    }
			}
	    }



Re: Admin. chat. - UsaBoy91 - 23.08.2009

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

All players will can to use that command


Re: Admin. chat. - ronyx69 - 23.08.2009

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.


Re: Admin. chat. - RaFsTar - 23.08.2009

Thankx Ronyx !!


Re: Admin. chat. - RaFsTar - 23.08.2009

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


Re: Admin. chat. - ronyx69 - 23.08.2009

Код:
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;
	}