[Include] H_Format - Format option in functions
#1

H_Format
H_Format is a simple include that makes your coding simpler and faster.
H_Format changes this functions
  • SendClientMessage(playerid, color, text[])
  • SendClientMessageToAll(color, text[])
  • SetGameModeText(text[])
  • UpdatePlayer3DTextLabelText(playerid, 3dTextLabel, color, text[])
  • Update3DTextLabelText(3dTextLabel, color, text[])
  • TextDrawSetString(textdraw, text[])
  • SetPVarString(playerid,"varname",text[])
into format-functions.
So the formate options are pre-implemented and you dont need to use format(...).
You know it from functions like printf(...)

Functions:
  • SendClientMessagef
    pawn Код:
    SendClientMessagef(playerid, color, format, { Float , _ } : ... );
  • SendClientMessageToAllf
    pawn Код:
    SendClientMessageToAllf(color, format, { Float , _ } : ... );
  • SetGameModeTextf
    pawn Код:
    SetGameModeTextf(format, { Float , _ } : ... );
  • UpdatePlayer3DTextLabelTextf
    pawn Код:
    UpdatePlayer3DTextLabelTextf(playerid, 3dTextLabel, color, format, { Float , _ } : ... );
  • Update3DTextLabelTextf
    pawn Код:
    Update3DTextLabelTextf(3dTextLabel, color, format, { Float , _ } : ... );
  • TextDrawSetStringf
    pawn Код:
    TextDrawSetStringf(textdraw, format, { Float , _ } : ... );
  • SetPVarStringf
    pawn Код:
    SetPVarStringf(playerid,"varname", format, { Float , _ } : ... );
Examples:
Welcome message
pawn Код:
public OnPlayerSpawn(playerid)
{
    new Playername[ MAX_PLAYER_NAME ];
    GetPlayerName(playerid, Playername, MAX_PLAYER_NAME);
    SendClientMessagef(playerid,0xFFFFFFFF,"Hello %s!.", Playername);
}
Change gamemode name
pawn Код:
#define VERSION "v.1.0.1.2"

public OnGameModeInit(){
    SetGameModeTextf("XYZ-Reallife %s",VERSION);
}
Message when player connected
pawn Код:
public OnPlayerSpawn(playerid)
{
    new Playername[ MAX_PLAYER_NAME ];
    GetPlayerName(playerid, Playername, MAX_PLAYER_NAME);
    SendClientMessageToAllf(0xFFFFFFFF,"%s logged in.", Playername);
}
Placeholders:
This placeholders are implemented in the h_format include:
  • %s = String
  • %d = Integer
  • %i = Integer
  • %f = Float
Installation:
  1. Move h_format.inc in your include folder
  2. Write #include <h_format.inc> on top of your script under #include <a_samp>
  3. Now youґre ready!
Download:
Reply
#2

Do this:

pawn Код:
#define MAX_STRING                                  1000

new FormatString[MAX_STRING];

#define Format(%0)                                  (format(FormatString, MAX_STRING, %0), FormatString)

#define SendClientMessagef(%0,%1,%2)                SendClientMessage(%0, %1, Format(%2))
#define SendClientMessageToAllf(%0,%1)              SendClientMessageToAll(%0, Format(%1))
#define SetGameModeTextf(%0)                        SetGameModeText(Format(%0))
#define UpdatePlayer3DTextLabelTextf(%0,%1,%2,%3)   UpdatePlayer3DTextLabelText(%0, %1, %2, Format(%3))
#define Update3DTextLabelTextUpdatef(%0,%1,%2)      3DTextLabelText(%0, %1, Format(%2))
#define TextDrawSetStringf(%0,%1)                   TextDrawSetString(%0, Format(%1))
#define SetPVarStringf(%0,%1,%2)                    SetPVarString(%0, %1, Format(%2))
Alot simpler.
Reply
#3

I love it. Thanks for the release. Good job mate.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Could I suggest you look up y_va? That allows you to do this much simpler, while allowing the full range of format options, things like "%02d", which is valid and not supported by your code:

pawn Код:
#include <YSI\y_va>

stock SendClientMessageEx(playerid, color, format[], va_args<>)
{
    // Format destination.
    new
        str[145];
    // 3 for "playerid, color, format"
    va_format(str, sizeof (str), format, va_start<3>);
    // Send the message.
    return SendClientMessage(playerid, color, str);
}
I've also changed the "f" to "Ex" - that's a minor change and you could have used "F" instead of "Ex", but "SendClientMessage" is a camel-case function, and appending "f" to the end looks like part of the previous word, not a new word.

Alternatively, if you do want to implement the whole of the format function from scratch then look up "AMXModX", their "format" function is based on the Quake one, and also happens to be the function that the SA:MP "format" function is based on so you can see how things like widths and precisions are implemented.
yea right, the only different thing is, his works and yours doesn't work.
Well I maybe works but only if you have a clean gamemode. As soon you are going to script your own lines into it, suddenly everyhing seems to get fucked. I like other includes of you. But this one fails.
Reply
#5

Quote:
Originally Posted by Roel
Посмотреть сообщение
yea right, the only different thing is, his works and yours doesn't work.
Well I maybe works but only if you have a clean gamemode. As soon you are going to script your own lines into it, suddenly everyhing seems to get fucked. I like other includes of you. But this one fails.
Or meybe you don't know what you're doing?

******'s includes ALL work and if one doesn't, he posts that it isn't functioning properly.
Reply
#6

Sure
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)