How to convert this function to macro (#define bla bla )
#1

i want change it to #define GetPlayerNameEx(%0, %1) (What should i do here)

i wont to use value variable and strcpy is it possible?
Код:
GetPlayerNameEx(playerid, bool:underscore=true)
{
	new
		value[MAX_PLAYER_NAME];

	if (!underscore)
	{
        strcpy(value, PlayerData[playerid][pNickname], sizeof(value));
	}
	else
	{
 		strcpy(value, PlayerData[playerid][pUsername], sizeof(value));
	}
	return value;
}
Reply
#2

You can't really use #define, otherwise you get:
Код:
warning 206: redundant test: constant expression is non-zero
But you can use:
pawn Код:
GetPlayerNameEx(playerid, bool:underscore = true) return (underscore) ? (PlayerData[playerid][pUsername]) : (PlayerData[playerid][pNickname]);
Reply
#3

I known about that code, the main reason is when i do it, it just output 1 of first character

if you don't know what i mean, when i do this test, the output is
R
R
pawn Код:
#include <a_samp>
#include <YSI_Core\y_utils>

enum e_enum
{
    pName[MAX_PLAYER_NAME],
    pUsername[MAX_PLAYER_NAME]
};
new PlayerData[1][e_enum];

public OnGameModeInit()
{
    new playerid = 0;
   
    strcpy(PlayerData[playerid][pName], "Raefaldhi Amartya", 24);
    strcpy(PlayerData[playerid][pUsername], "Raefaldhi_Amartya", 24);
    printf("%s", GetPlayerNameEx(playerid, true));
    printf("%s", GetPlayerNameEx(playerid, false));
    return 1;
}

GetPlayerNameEx(playerid, bool:underscore = true)
    return (underscore) ? (PlayerData[playerid][pUsername]) : (PlayerData[playerid][pName]);

main() {}
Reply
#4

EDIT:
Strangely enough... only this seems to work:
pawn Код:
GetPlayerNameEx(playerid, bool:underscore = true)
{
    new str[MAX_PLAYER_NAME];
    format(str, sizeof(str), "%s", (underscore) ? (PlayerData[playerid][pUsername]) : (PlayerData[playerid][pNickname]));
    return str;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)