[HELP] A Few Requests!
#2

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