30.11.2016, 18:45
Quote:
No, this is not how it works. There are basically two ways for a function to return; either by value or by reference. You can ****** the detailed difference, but to return more than one value, the function must return them by reference; meaning that whatever variables passed to this function are modified internally, they are modified where you called it and passed them too.
A fixed code of yours may look like: Code:
dcmd_totalteams(playerid, params[]) { #pragma unused params new Totalteam1, Totalteam2 ; GetteamPlayers(Totalteam1, Totalteam2); new String[500]; format(String, sizeof(String), "{FFFFFF}Players team 1:%d\n\ {FFFFFF}Players team 2: %d", Totalteam1, Totalteam2); ShowPlayerDialog(playerid, 96251, DIALOG_STYLE_MSGBOX, "Total Players dos teams", String, "Ok", ""); return 1; } GetteamPlayers(Totalteam1, Totalteam2) { for (new i, g = GetMaxPlayers(); i < g; i++) { if (IsPlayerConnected(i)) { if (Player[i][pteam1] == 1) Totalteam1++; if (Player[i][pteam2] == 1) Totalteam2++; } } } That would be something like: Code:
#define NoTeam (-1) #define Team1 (0) #define Team2 (1) #define Team3 (2) new PlayerTeam[MAX_PLAYERS]; dcmd_totalteams(playerid, params[]) { #pragma unused params new Totalteam1, Totalteam2 ; GetteamPlayers(Totalteam1, Totalteam2); new String[500]; format(String, sizeof(String), "{FFFFFF}Players team 1:%d\n\ {FFFFFF}Players team 2: %d", Totalteam1, Totalteam2); ShowPlayerDialog(playerid, 96251, DIALOG_STYLE_MSGBOX, "Total Players dos teams", String, "Ok", ""); return 1; } GetteamPlayers(Totalteam1, Totalteam2) { for (new i, g = GetMaxPlayers(); i < g; i++) { if (!IsPlayerConnected(i)) continue; switch (PlayerTeam[i]) { case Team1: Totalteam1++; case Team2: Totalteam2++; // ... } } } Resetting would be: PlayerTeam[playerid] = NoTeam; |
I used all the Codes and did not work and also I set the player with the variable pteam1 and PlayerTeam and it did not work
Result: http://i.imgur.com/FllXcYz.png