sendclientmessage getplayername..
#1

Okay, so i'm always getting goddamn confused within those


after i use format(str, sizeof blah blah blah

under it there's sendclientmessage but i never know what do i need to put there - str? -1? i always waste time trying to guess what the fuck i need to put inside there


same with getplayername(playerid, sometimes i need not to put playerid but something else but i never know what
Reply
#2

Always look at the wiki for parameters and formats,
You got to understand what a variable is, its a storage, and you get quite a few kinds of it
Float, integer, string, Boolean and more;

format puts variables(changing values) in a string(a sentience, word, or even a letter);

its used as this
pawn Код:
format(output[], len, const format[], {Float,_}:...)
output is where the formatted string's gonna be, len is the lenth of it, you could use "sizeof(string)" for it, and const format is the words you wanna say with variables, an example should help you

So I want to tell "Jack" how much money I have, I've got to get his name from his ID first
pawn Код:
new name[MAX_PLAYER_NAME]//this is where I'm going to store his name
GetPlayerName(id, name);//id should be Jack's id, since there's alot of ids in game
now I save my money which is 10 to the "mymoney" variable
pawn Код:
new mymoney = GetPlayerMoney(playerid);
Now I want to tell Jack how much money I have, I don't even know how much money I'm going to have right since it changes...that's where format comes in.
pawn Код:
new string[128]//a string with 128 place for letters.
format(string, sizeof(string), "Hi %s, I got %d", name, mymoney);
SendClientMessage(playerid, Color, string);
now you could add 128 instead of "sizeof(string)", also I'm not going to guess the name, cause I might want to tell somebody else my money, so i put the name I got from the id in "%s" which is a string, and pass "name" to it, then put "%d" which is an integer and pass "mymoney" to it, I think you understand a big bit of that, but I have to guess you don't and try to help, hope you understood.
Reply
#3

pawn Код:
// We create an array, we can call it whatever we want.
// This is what we will refer to when we want to get the content of it.
// There are several ways to put content inside of the array, a common way is to 'format'.

new whatever[128];
// If we need to send a client message, it need not to be bigger than 128, since
// a client message cannot display more than 128 chars per row.
// (Yes, there are ways to split the string and send multiple rows, but let's not right now).

// We will now format the string, including the player name of whoever is sending the message.
// To do that, we need to retrieve the players name first.
new myname[MAX_PLAYER_NAME];

// MAX_PLAYER_NAME is already defined, and is currently size '24' So it is the same as [24].
// Should the max limit of playernames change, we will not have to change this through the entire script
// if we use MAX_PLAYER_NAME.

// now we format the array.
format(whatever,sizeof(whatever),"My name: %s",myname);

// Let's send this to the client.
SendClientMessage(playerid,-1,whatever); // SendClientMessage(<ID OF RECEIVER>,<COLOR (-1 will default white)>,<message>);


// If you have created a command, say using ZCMD and sscanf plugin, you can specify the player who will, for example, receive the message.
CMD:myandyourname(playerid,params[])
{
    new otherid,str[128];
    if(sscanf(params,"u",otherid)) // 'u' is the User specifier of sscanf, which will return the ID whether you write the ID or Playername.
    {
        new othername[MAX_PLAYER_NAME],myname[MAX_PLAYER_NAME];
        GetPlayerName(otherid,othername,sizeof(othername)); // Retrieve name of other player
        GetPlayerName(playerid,myname,sizeof(myname));
        format(str,sizeof(str),"Hi, my name is %s and your name is %s ;)",myname,othername);

        SendClientMessage(otherid,-1,str); // otherid is whatever playerid you type in the command, i.e /myandyourname [otherid]
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)