SA-MP Forums Archive
PM HELP - 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: PM HELP (/showthread.php?tid=129958)



PM HELP - RoneyRemington - 24.02.2010

Код:
if(strcmp("/pm", cmd, true) == 0)
		{
		tmp = strtok(cmdtext,idx);

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

 		id = strval(tmp);

		tmp = strtok(cmdtext,idx);
 		if(!strlen(tmp)) {
			SendClientMessage(playerid,COLOR_GREEN,"Usage: /pm [id] [Message]");
			return 1;
		}

		if(!IsPlayerConnected(id)) {
			SendClientMessage(playerid,COLOR_RED,"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,COLOR_PURPLE,Message);
			format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
			SendClientMessage(id,COLOR_ORANGE,Message);
			PlayerPlaySound(id,1085,0.0,0.0,0.0);

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

		}
		else {
			SendClientMessage(playerid,YELLOW,"You cannot PM yourself");
		}
		return 1;
	}
  return 0;
}

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;
}
k iahve that code and for some reason i get 10 errors saying that "id" is not defined??


Re: PM HELP - RoneyRemington - 24.02.2010

do i just put "new id(.."sumthin here"..)


Re: PM HELP - [cA]Unforseen - 24.02.2010

use dcmd cuz its better


Re: PM HELP - RoneyRemington - 24.02.2010

thats alot of help?


Re: PM HELP - VonLeeuwen - 24.02.2010

Roney,

http://pawn.pastebin.com/LtkBYnue
Check that thing out.


Re: PM HELP - GaGlets(R) - 24.02.2010

Quote:
Originally Posted by RoneyRemington
Код:
if(strcmp("/pm", cmd, true) == 0)
		{
		tmp = strtok(cmdtext,idx);

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

 		id = strval(tmp);

		tmp = strtok(cmdtext,idx);
 		if(!strlen(tmp)) {
			SendClientMessage(playerid,COLOR_GREEN,"Usage: /pm [id] [Message]");
			return 1;
		}

		if(!IsPlayerConnected(id)) {
			SendClientMessage(playerid,COLOR_RED,"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,COLOR_PURPLE,Message);
			format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
			SendClientMessage(id,COLOR_ORANGE,Message);
			PlayerPlaySound(id,1085,0.0,0.0,0.0);

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

		}
		else {
			SendClientMessage(playerid,YELLOW,"You cannot PM yourself");
		}
		return 1;
	}
  return 0;
}

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;
}
k iahve that code and for some reason i get 10 errors saying that "id" is not defined??
Mybe stop stealing? :

Then it should work


Re: PM HELP - gotenks918 - 24.02.2010

Quote:
Originally Posted by [cA
Unforseen ]
use dcmd cuz its better
ZCMD.


Re: PM HELP - GaGlets(R) - 24.02.2010

Quote:
Originally Posted by gotenks918
Quote:
Originally Posted by [cA
Unforseen ]
use dcmd cuz its better
ZCMD.
DCMD !


Re: PM HELP - Doppeyy - 24.02.2010

Quote:
Originally Posted by GaGlets®
Quote:
Originally Posted by gotenks918
Quote:
Originally Posted by [cA
Unforseen ]
use dcmd cuz its better
ZCMD.
DCMD !
This flaming eachother isnt really helping him is it ?

[Doppeyy


Re: PM HELP - Joe Staff - 24.02.2010

You have to add
pawn Код:
new id = strval(tmp);
underneath
pawn Код:
tmp = strtok(cmdtext,idx);
so you should get this

pawn Код:
if(strcmp("/pm", cmd, true) == 0)
{
  tmp = strtok(cmdtext,idx);
  new id=strval(tmp);
  if(!strlen(tmp) || strlen(tmp) > 5) {
    SendClientMessage(playerid,COLOR_GREEN,"Usage: /pm [id] (Message)");
    return 1;
  }


[Off-Topic]
DCMD is just the strcmp method but slightly different.
ZCMD truly is a completely different method (doesn't even use strcmp) so it only needs to be called once per OnPlayerCommandText, where as DCMD is checked and called for each command (until found that is)

Although I must say that ZCMD could easily be made to go faster

ZCMD -> http://zeex.pastebin.ca/1650602 (119 lines)

My version (11 lines)
pawn Код:
#define Command(%1) forward CMD_%1(playerid,params[]);\
public CMD_%1(playerid,params[])
public OnPlayerCommandText(playerid,cmdtext[])
{
  new tmp[128];
  new space = strfind(cmdtext," ");
  new cell;
  format(tmp,space-1,cmdtext[1]);
  while(tmp[cell])tmp[cell]=tolower(tmp[cell]),cell++;
  format(tmp,128,"CMD_%s",tmp);
  return CallLocalFunction(tmp,"is",playerid,cmdtext[space+1]);
}
example command
pawn Код:
Command(test) //playerid and params[] are assumed
{
    SendClientMessage(playerid,0xFFFFFFFF,"This is a test.");
    return 1;
}