[HELP] A Few Requests!
#4

[b]
Quote:
Originally Posted by Awaran[Enemy-Plus
; ]
You are going to need strtok functions; strtok and bigstrtok


pawn Код:
stock strtok(const string[], &index,seperator=' ')
{
    new length = strlen(string);
    new offset = index;
    new result[128];
    while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }

    result[index - offset] = EOS;
    if ((index < length) && (string[index] == seperator))
    {
        index++;
    }
    return result;
}

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;
}
Now add these to the top of your OnPlayerCommandText.

pawn Код:
new cmd[128];
    new tmp[128];
    new idx;
    new string[128];
    cmd = strtok(cmdtext,idx);
Now we have done that here is a /pm [id] [message] system that is compatible with SAMP 0.3a

pawn Код:
if (strcmp("/pm", cmdtext, true, 3) == 0)
  {
    new message[128];
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
          SendClientMessage(playerid,CORAL,"USAGE: /pm [playerid] [message]");
          SendClientMessage(playerid,CORAL,"FUNCTION: Sends a message to a player");
          return 1;
        }
        targetid = strval(tmp);
        if(IsPlayerConnected(targetid))
        {
            new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], str[128];
          GetPlayerName(targetid,name,sizeof(name));
          GetPlayerName(playerid,name2,sizeof(name2));
          message = bigstrtok(cmdtext, idx);
          if(!strlen(message)) return SendClientMessage(playerid,CORAL,"USAGE: /pm [playerid] [message]"), SendClientMessage(playerid,CORAL,"You did not enter a message");
          format(string,sizeof(string),"PM from %s(%d): %s",name2, playerid,message);
          SendClientMessage(targetid,YELLOW,string);
            format(str,sizeof(str),"PM sent to %s(%d): %s", name, targetid, message);
            SendClientMessage(playerid,YELLOW,str);
            //printf("[PM] %s[%d] to %s[%d] - %s -",name2, playerid, name, targetid, message);//Un-comment if you want these to be logged into the samp-log.txt
        }
        else if(!IsPlayerConnected(targetid))
        {
            SendClientMessage(playerid,CORAL,"Invalid ID");
            return 1;
        }
    return 1;
    }
I did this:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[128];
	new tmp[128];
	new idx;
	new string[128];
	cmd = strtok(cmdtext,idx);

	if(!strcmp(cmdtext, "/me", true, 3))
  {
    if(!cmdtext[3])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /me [action]");
    new str[128];
    GetPlayerName(playerid, str, sizeof(str));
    format(str, sizeof(str), "* %s %s", str, cmdtext[4]);
    SendClientMessageToAll(0xFFFF00AA, str);
  if (strcmp("/pm", cmdtext, true, 3) == 0)
  {
    new message[128];
	tmp = strtok(cmdtext, idx);
	if(!strlen(tmp))
	{
	SendClientMessage(playerid,CORAL,"USAGE: /pm [playerid] [message]");
  SendClientMessage(playerid,CORAL,"FUNCTION: Sends a message to a player");
  return 1;
	}
	targetid = strval(tmp);
	if(IsPlayerConnected(targetid))
	{
	new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], str[128];
  GetPlayerName(targetid,name,sizeof(name));
  GetPlayerName(playerid,name2,sizeof(name2));
  message = bigstrtok(cmdtext, idx);
  if(!strlen(message)) return SendClientMessage(playerid,CORAL,"USAGE: /pm [playerid] [message]"), SendClientMessage(playerid,CORAL,"You did not enter a message");
  format(string,sizeof(string),"PM from %s(%d): %s",name2, playerid,message);
  SendClientMessage(targetid,YELLOW,string);
	format(str,sizeof(str),"PM sent to %s(%d): %s", name, targetid, message);
	SendClientMessage(playerid,YELLOW,str);
	//printf("[PM] %s[%d] to %s[%d] - %s -",name2, playerid, name, targetid, message);//Un-comment if you want these to be logged into the samp-log.txt
	}
	else if(!IsPlayerConnected(targetid))
	{
	SendClientMessage(playerid,CORAL,"Invalid ID");
	return 1;
	}
[b]and get this error:

Код:
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(136) : error 047: array sizes do not match, or destination array is too small
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(145) : warning 217: loose indentation
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(148) : warning 217: loose indentation
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(148) : error 047: array sizes do not match, or destination array is too small
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(151) : error 017: undefined symbol "CORAL"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(152) : error 017: undefined symbol "CORAL"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(155) : error 017: undefined symbol "targetid"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(156) : error 017: undefined symbol "targetid"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(158) : warning 219: local variable "str" shadows a variable at a preceding level
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(159) : error 017: undefined symbol "targetid"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(161) : error 017: undefined symbol "bigstrtok"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(161) : error 033: array must be indexed (variable "message")
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(162) : error 017: undefined symbol "CORAL"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(164) : error 017: undefined symbol "targetid"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(165) : error 017: undefined symbol "targetid"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(166) : error 017: undefined symbol "YELLOW"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(169) : error 017: undefined symbol "targetid"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(171) : error 017: undefined symbol "CORAL"
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(175) : warning 217: loose indentation
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(175) : error 029: invalid expression, assumed zero
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(175) : error 004: function "OnPlayerEnterVehicle" is not implemented
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(180) : warning 225: unreachable code
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(180) : error 029: invalid expression, assumed zero
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(180) : error 004: function "OnPlayerExitVehicle" is not implemented
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(185) : warning 225: unreachable code
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(185) : error 029: invalid expression, assumed zero
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(185) : error 004: function "OnPlayerStateChange" is not implemented
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(190) : warning 225: unreachable code
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(190) : error 029: invalid expression, assumed zero
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(190) : error 004: function "OnPlayerEnterCheckpoint" is not implemented
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(195) : warning 225: unreachable code
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(195) : error 029: invalid expression, assumed zero
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(195) : error 004: function "OnPlayerLeaveCheckpoint" is not implemented
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(200) : warning 225: unreachable code
C:\DOCUME~1\ADMIN~1.GEO\Desktop\COPYOF~1\GAMEMO~1\Country.pwn(200) : error 029: invalid expression, assumed zero

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


26 Errors.
Reply


Messages In This Thread
[HELP] A Few Requests! - by Camacorn - 02.12.2009, 01:54
Re: [HELP] A Few Requests! - by pagie1111 - 02.12.2009, 04:08
Re: [HELP] A Few Requests! - by Correlli - 02.12.2009, 05:07
Re: [HELP] A Few Requests! - by Camacorn - 02.12.2009, 10:01
Re: [HELP] A Few Requests! - by Zeromanster - 02.12.2009, 10:04
Re: [HELP] A Few Requests! - by pagie1111 - 02.12.2009, 13:08
Re: [HELP] A Few Requests! - by saiberfun - 02.12.2009, 13:12

Forum Jump:


Users browsing this thread: 1 Guest(s)