#1

I am trying to make a local /me cmd

pawn Код:
if(strcmp(cmdtext, "/me", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new string[256];
            new sendername[MAX_PLAYER_NAME];
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_RED, "USAGE: /me [action]");
                return 1;
            }
            format(string, sizeof(string), "* %s %s", sendername, result);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            printf("%s", string);
        }
        return 1;
    }
I got some errors after defining something on "idx"
Reply
#2

Why do you do it so difficult? Use sscanf. This in my RP, for example:

pawn Код:
dcmd_me(playerid,params[])
{
    new string[99],Playername[MAX_PLAYER_NAME],action[99],Float:PosX, Float:PosY, Float:PosZ;
    if(sscanf(params,"z",action)) return SendClientMessage(playerid,COLOR_RED,"* Syntax Error: /me [action]");
    else
    {
        for(new i =0; i < MAX_PLAYERS; i++)
        {
            GetPlayerRPName(playerid,Playername,sizeof(Playername));
            GetPlayerPos(playerid,PosX,PosY,PosZ);
            if(IsPlayerInRangeOfPoint(i,20,PosX,PosY,PosZ))
            {
                format(string,sizeof(string),"* %s %s",Playername,action);
                SendClientMessage(i,COLOR_LIGHTGREY,string);
            }
        }
    }
    return 1;
}
Reply
#3

I use zcmd and sscanf so i don't know what ur errors are but 2 things i spotted, the string is 2x to large it should be 128. And,
pawn Код:
if(strcmp(cmdtext, "/me", true) == 0)
should be
pawn Код:
if(!strcmp(cmdtext, "/me", true) == 0)//with a '!'
If you wana show message to all (not rp style) Jochemd' code could be further simplified to,

pawn Код:
dcmd_me(playerid,params[])
{
    new string[128],Playername[MAX_PLAYER_NAME],action[104];
    if(sscanf(params,"s[104]",action)) return SendClientMessage(playerid,COLOR_RED,"* Syntax Error: /me [action]");
    else
    {
        GetPlayerName(playerid,Playername,sizeof(Playername));
        format(string,sizeof(string),"* %s %s",Playername,action);
        SendClientMessageToAll(COLOR_LIGHTGREY,string);
    }
    return 1;
}
Reply
#4

Help me making a normal one. Not with dcmd. It will fuck all the script.
Reply
#5

https://sampwiki.blast.hk/wiki/Using_strcmp%28%29
Quote:
Originally Posted by wiki.sa-mp.com
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/me", true, 3)) // 3 is the length of /me
    {
        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);
        return 1;
    }
    return 0;
}
EDIT: Oops,sorry my bad I've misread,if you want it to be used locally:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/me", true, 3)) // 3 is the length of /me
    {
        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]);
        ProxDetector(30.0, playerid, str, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
        return 1;
    }
    return 0;
}
Reply
#6

C:\Documents and Settings\Home\Рабочий стол\Pawn\gamemodes\EQrp.pwn(257) : error 004: function "ProxDetector" is not implemented
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#7

pawn Код:
if(!strcmp(cmdtext, "/me", true, 3))
{
  new string[128]; GetPlayerName(playerid, string, sizeof string);
  format(string, sizeof string, "** %s %s", string, cmdtext[4]);
  SendClientMessageToAll(COLOR_GREEN, string);
  return 1;
}
Under OnPlayerCommandText.

BTW: What's this ProxDetector crappy function?
Reply
#8

ProxDetector is a really inefficient godfather function which sends messages to players that are in x range of playerid. If the player is very close, the color will be white. The further away the player is, the darker the color will become.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)