How to convert this function to macro (#define bla bla ) - 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: How to convert this function to macro (#define bla bla ) (
/showthread.php?tid=555240)
How to convert this function to macro (#define bla bla ) -
RaeF - 07.01.2015
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;
}
Re: How to convert this function to macro (#define bla bla ) -
Threshold - 07.01.2015
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]);
Re: How to convert this function to macro (#define bla bla ) -
RaeF - 07.01.2015
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() {}
Re: How to convert this function to macro (#define bla bla ) -
Threshold - 07.01.2015
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;
}