How to make these locals variables global?
#1

Hello, i have this command and i want to make these variables ( if pFaction == 0) format(the name )

In this command the names for factions are locals, in this command, and i want to make them globals to use them on another commands. And i dont want to define everytime in every command the names of the factions.

Код:
CMD:stats(playerid, params[])
{
	new string[128], fNume[128];
	SCM(playerid, 0xFFD080FF, "___________________________________");
	SCM(playerid, -1, "");
	if(PlayerInfo[playerid][pFaction] == 0) format(fNume, 128, "Civil");
	if(PlayerInfo[playerid][pFaction] == 1) format(fNume, 128, "Police Departament");
	if(PlayerInfo[playerid][pFaction] == 2) format(fNume, 128, "Paramedic Departament");
	if(PlayerInfo[playerid][pFaction] == 3) format(fNume, 128, "Taxi Company");
	format(string, sizeof(string), "{FFD080}%s{E6E6E6}: Level: {FFD080}%d {E6E6E6}| Faction: {FFD080}%s {E6E6E6}| Ping:{FFD080}%d", GetName(playerid), GetPlayerScore(playerid), fNume, GetPlayerPing(playerid));
	SCM(playerid, 0xFFD080FF, string);
	SCM(playerid, 0xFFD080FF, "___________________________________");
	return 1;
Reply
#2

Quote:
Originally Posted by Fabyx15
Посмотреть сообщение
Hello, i have this command and i want to make these variables ( if pFaction == 0) format(the name )

In this command the names for factions are locals, in this command, and i want to make them globals to use them on another commands. And i dont want to define everytime in every command the names of the factions.

Код:
CMD:stats(playerid, params[])
{
	new string[128], fNume[128];
	SCM(playerid, 0xFFD080FF, "___________________________________");
	SCM(playerid, -1, "");
	if(PlayerInfo[playerid][pFaction] == 0) format(fNume, 128, "Civil");
	if(PlayerInfo[playerid][pFaction] == 1) format(fNume, 128, "Police Departament");
	if(PlayerInfo[playerid][pFaction] == 2) format(fNume, 128, "Paramedic Departament");
	if(PlayerInfo[playerid][pFaction] == 3) format(fNume, 128, "Taxi Company");
	format(string, sizeof(string), "{FFD080}%s{E6E6E6}: Level: {FFD080}%d {E6E6E6}| Faction: {FFD080}%s {E6E6E6}| Ping:{FFD080}%d", GetName(playerid), GetPlayerScore(playerid), fNume, GetPlayerPing(playerid));
	SCM(playerid, 0xFFD080FF, string);
	SCM(playerid, 0xFFD080FF, "___________________________________");
	return 1;
Serves you?
PHP код:
GetFactionName(faction)
{
    new 
string[24];
    switch(
faction)
    {
        case 
0string 'Civil';
        case 
1string 'Police Departament';
        case 
2string 'Paramedic Departament';
        case 
3string 'Taxi Company';
        
//continue
    
}
    return 
string;
}
//Use
new string[128];
format(string128"Faccion: %s"GetFactionName(PlayerData[playerid][faction]); 
Note: it replaces the variable of the player where the faction is stored.
Reply
#3

Better would be something like:

PHP код:
//Globally declared
#define GetFactionName(%0) f_names[%0]
stock const f_names[][] = {"Civil""Police Departament""Paramedic Departament""Taxi Company"};
//Now you can use:
new string[128]; 
format(string128"Faction: %s"GetFactionName(PlayerData[playerid][faction]); 
Even without a function call and it holds your amx small.
Reply
#4

Thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)