Help sending a message to a specific player only
#1

fixed
Reply
#2

yes you should do something like strcmp stuff too
Reply
#3

Yes, you're on the right tracks. However, you'll need to use a loop to go through every player to check if their name is Ken.

pawn Код:
CMD:ken(playerid, params[]) {
    new
        szPlayerName[MAX_PLAYER_NAME],
        iKen = INVALID_PLAYER_ID; // We'll assign "INVALID_PLAYER_ID" to this, we know Ken isn't online if INVALID_PLAYER_ID is the value of 'iKen' at the end, otherwise it will change to the actual player ID of Ken while he's online.
       
    for(new i = 0; i < MAX_PLAYERS; i++) { // Looping through every player online
        if(IsPlayerConnected(i)) { // Confirming they're connected
            GetPlayerName(i, szPlayerName, MAX_PLAYER_NAME); // Getting their name and storing it in a variable so we can reference it against "Ken"

            if(!strcmp(szPlayerName, "Ken", true)) { // Referencing the name against "Ken". Is it Ken?
               iKen = i; // If it's Ken, we're getting his player ID here.
            }
        }
    }
   
    if(iKen != INVALID_PLAYER_ID) { // Is Ken online? If 'iKen' is not INVALID_PLAYER_ID then it would appear he is!
        new
            szMessage[128]; // Let's create a string so we can format a message for him

        // Ken is online. Here's a message for Ken!
        GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
        format(szMessage, sizeof(szMessage), "%s sent you a message: %s", szPlayerName, params);
        SendClientMessage(iKen, 0xFFFFFFFF, szMessage);

        SendClientMessage(playerid, 0xFFFFFFFF, "Your message has been sent to Ken.");
    } else SendClientMessage(playerid, 0xFFFFFFFF, "Ken is not online at the moment"); // Unfortunately, he's not online. We'll tell the command executer that.
    return 1;
}
I've written you the command and documented it with comments to explain how I've done it. If you have any questions, comments or concerns, reply.
Reply
#4

PHP код:
if(!strcmp(szPlayerName"Neil"true)) 
^^ This is what I don't get, how come some use true and some use false? (Sorry don't really know much about strcmp)

Or to save time are there any tutorials regarding to a command similar to this? If so, then please post, I really want to learn

(And i'm testing Calgon's code and see if it works)
EDIT: It worked! Ty Calgon and for the Strcmp wiki tutorial link
Reply
#5

If you look at the wiki page for strcmp, the third parameter is 'ignorecase'. You can ignore case sensitivity in the names, so for example, if you logged on with the name "ken" as opposed to "Ken", my code would ignore case sensitivity and it would still know you're Ken, despite the fact that you haven't capitalized the 'K' at the beginning of your name.

The SA-MP wiki has details like this for (almost) every native function.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)