SA-MP Forums Archive
Learning Format ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Learning Format ? (/showthread.php?tid=287331)



Learning Format ? - ServerScripter - 02.10.2011

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.


Re: Learning Format ? - =WoR=Varth - 02.10.2011

https://sampwiki.blast.hk/wiki/Format


Re: Learning Format ? - ServerScripter - 02.10.2011

IDK but it is not good Explained


Re: Learning Format ? - Kingunit - 02.10.2011

What you don't understand?


Re: Learning Format ? - ServerScripter - 02.10.2011

all thing , What is String ?


Re: Learning Format ? - Jafet_Macario - 02.10.2011

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


Re: Learning Format ? - GrimR - 02.10.2011

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).


Re: Learning Format ? - ServerScripter - 02.10.2011

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 ?


Re: Learning Format ? - Kingunit - 02.10.2011

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.


Re: Learning Format ? - PowerPC603 - 02.10.2011

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;
}