Learning Format ?
#1

Hi , i find this in a lot of Scripts :

pawn Код:
format(string, sizeof(string), "%s Says(Phone): %s", sendername, text);
What is Format ? how to use it ? and why we do %s and not %d , thanks.
Reply
#2

https://sampwiki.blast.hk/wiki/Format
Reply
#3

IDK but it is not good Explained
Reply
#4

What you don't understand?
Reply
#5

all thing , What is String ?
Reply
#6

https://sampwiki.blast.hk/wiki/Scripting_Basics#Strings
https://sampforum.blast.hk/showthread.php?tid=284112
Reply
#7

It formats a string, size of that string, with text inbetween the double quotes.

%s means string, %d integer, format will replace those with the variables you specify after.

For example:
pawn Код:
format(myStr, sizeof(myStr), "Hello %s, please count to %d.", strName, intNumber);
The infinite variables you pass at the end, are used from left to right (as they appear between the double quotes).
Reply
#8

So , if i want to get the Player's ID :
Ex : In Chat , i want to see ID of Each Player
pawn Код:
new text
new string
format(string, sizeof(string), "X[id:%d]:%s, GetPlayerId,text");
? or what ?
Reply
#9

pawn Код:
new pName[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, pName, sizeof(pName));
        format(string, sizeof(string), "%s says: %s", pName, text);
        SendClientMessage(playerid,0xFFFFFAA,string);
Will work. new text isn't needed. That's already at OnPlayerText.
Reply
#10

Quote:
Originally Posted by ServerScripter
Посмотреть сообщение
So , if i want to get the Player's ID :
Ex : In Chat , i want to see ID of Each Player
pawn Код:
new text
new string
format(string, sizeof(string), "X[id:%d]:%s, GetPlayerId,text");
? or what ?
pawn Код:
public OnPlayerText(playerid, text[])
{
    // Create a new string of length 128 characters
    new string[128];
    // Create the line to send (put the value of "playerid" at the "%i", then insert the given text at the "%s"
    format(string, sizeof(string), "X[id: %i]: %s", playerid, text);
    // Send this to all players
    SendClientMessageToAll(0xFFFFFFFF, string);

    // block the normal text to be written to the chatbox, as the SendClientMessageToAll line sends the required text already
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)