PM HELP
#1

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

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

use dcmd cuz its better
Reply
#4

thats alot of help?
Reply
#5

Roney,

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)