From strcmp to zcmd.
#1

Hi, how can I convert this command into an ZCMD command?
pawn Код:
//PM Command
if(strcmp("/pm", cmd, true) == 0)
    {
        tmp = strtok(cmdtext,idx);

        if(!strlen(tmp) || strlen(tmp) > 5) {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Use: {FFFFFF}/pm [id] [text]");
            return 1;
        }

        new id = strval(tmp);
        gMessage = strrest(cmdtext,idx);

        if(!strlen(gMessage)) {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Use: {FFFFFF}/pm [id] [tetx]");
            return 1;
        }

        if(!IsPlayerConnected(id)) {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Server: {FFFFFF}Wrong 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,PM_OUTGOING_COLOR,Message);
            format(Message,sizeof(Message)," %s(%d): %s",pName,playerid,gMessage);
            SendClientMessage(id,PM_INCOMING_COLOR,Message);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);

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

        }
        else {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Server: {FFFFFF}You can't send MP to yourself.");
        }
        return 1;
    }
Please help me.
Reply
#2

This is directly from my GM. You can edit/add things if you want.

pawn Код:
CMD:pm(playerid, params[])
{
    new iID, szMessage[80];
    if(sscanf(params, "us[79]", iID, szMessage))
        return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /pm [nick/id] [message]");
    if(iID == INVALID_PLAYER_ID)
        return SendClientMessage(playerid, COLOR_RED, "Invalid nickname/ID.");

    new
        szString[128]
    ;
   
    format(szString, sizeof(szString), "PM from %s(%d): %s", getName(playerid), playerid, szMessage);
    SendClientMessage(iID, COLOR_YELLOW, szString);
    format(szString, sizeof(szString), "PM to %s(%d): %s", getName(iID), iID, szMessage);
    SendClientMessage(playerid, COLOR_YELLOW, szString);
    return 1;
}
Reply
#3

read and download ZCMD and SSCANF
Reply
#4

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
This is directly from my GM. You can edit/add things if you want.

pawn Код:
CMD:pm(playerid, params[])
{
    new iID, szMessage[80];
    if(sscanf(params, "us[79]", iID, szMessage))
        return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /pm [nick/id] [message]");
    if(iID == INVALID_PLAYER_ID)
        return SendClientMessage(playerid, COLOR_RED, "Invalid nickname/ID.");

    new
        szString[128]
    ;
   
    format(szString, sizeof(szString), "PM from %s(%d): %s", getName(playerid), playerid, szMessage);
    SendClientMessage(iID, COLOR_YELLOW, szString);
    format(szString, sizeof(szString), "PM to %s(%d): %s", getName(iID), iID, szMessage);
    SendClientMessage(playerid, COLOR_YELLOW, szString);
    return 1;
}
But I don't use scanff. If I put it on my GM, what the possibilities of getting a bug or code-confucion?
Reply
#5

Quote:
Originally Posted by Lauder
Посмотреть сообщение
But I don't use scanff. If I put it on my GM, what the possibilities of getting a bug or code-confucion?
If you don't use it- none.
Reply
#6

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
If you don't use it- none.
Haa? Yeah but IF I USE IT what are the possibilities.
Reply
#7

try this. i havent change anything i just changed the. strcmp to CMD
pawn Код:
CMD:pm(playerid, params[])
    {
        tmp = strtok(cmdtext,idx);

        if(!strlen(tmp) || strlen(tmp) > 5) {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Use: {FFFFFF}/pm [id] [text]");
            return 1;
        }

        new id = strval(tmp);
        gMessage = strrest(cmdtext,idx);

        if(!strlen(gMessage)) {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Use: {FFFFFF}/pm [id] [tetx]");
            return 1;
        }

        if(!IsPlayerConnected(id)) {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Server: {FFFFFF}Wrong 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,PM_OUTGOING_COLOR,Message);
            format(Message,sizeof(Message)," %s(%d): %s",pName,playerid,gMessage);
            SendClientMessage(id,PM_INCOMING_COLOR,Message);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);

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

        }
        else {
            SendClientMessage(playerid,0xFFFFFFAA,"{FF0000}Server: {FFFFFF}You can't send MP to yourself.");
        }
        return 1;
    }
Reply
#8

pawn Код:
CMD:pm(playerid, params[])
{
    #define SCM SendClientMessage
    new id, gMessage[50], iName[MAX_PLAYER_NAME], pName[MAX_PLAYER_NAME], Message[256];
    if(sscanf(params, "is[50]", id,gMessage)) return SCM(playerid, COLOR_GREY, "USAGE: /pm [ID] [Message]");
    if(!IsPlayerConnected(id)) return SCM(playerid,0xFFFFFFAA,"{FF0000}Server: {FFFFFF}Wrong ID.");
    if(playerid != id)
    {
        GetPlayerName(id,iName,sizeof(iName));
        GetPlayerName(playerid,pName,sizeof(pName));
        format(Message,sizeof(Message)," %s(%d): %s",iName,id,gMessage);
        SCM(playerid,COLOR_WHITE,Message);
        format(Message,sizeof(Message)," %s(%d): %s",pName,playerid,gMessage);
        SCM(id,COLOR_WHITE,Message);
        PlayerPlaySound(id,1085,0.0,0.0,0.0);
        printf("PM: %s",Message);
    }
    else
    {
        SCM(playerid,0xFFFFFFAA,"{FF0000}Server: {FFFFFF}You can't send MP to yourself.");
    }
    return 1;
}
Make sure to include the following in your Gamemode.

#include <zcmd>, #include <sscanf2>, #define SCM SendClientMessage

Try that un-tested.
Reply
#9

Quote:
Originally Posted by Lauder
Посмотреть сообщение
Haa? Yeah but IF I USE IT what are the possibilities.
It isn't going to hurt anything if you include sscanf in your game-mode. If you're only using it for a single command, nothing else is going to mess up. Where did you get that idea?
Reply
#10

pawn Код:
stock getName(pid) {
    new pn[MAX_PLAYER_NAME + 1];
    GetPlayerName(pid, pn, sizeof(pn));
    return pn;
};
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)