function should return a value? But i use return..
#1

Ahoy friends.

Thats my function to check if there is only one team left in my gamemode.
I love to use recursive functions so thats it!

Код:
stock TeamsAlive(bool:value)
{
	new i=0,count=0;
	while(i<TEAMSIZE)
	{
		if(GetTeamCount(i) > 0)
		{
			count++;
		}
		i++;	
	}
	if(bool:value == false)
	switch(count)
	{
		case 1:
		{
			switch(TeamsAlive(true))
			{
				case FIRST_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);
					}	
				}
				case SECOND_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
					}	
				}
				#if defined TEAMSIZE
				#if TEAMSIZE >= 3
				case THIRD_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",THIRD_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE >= 4
				case FOURTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FOURTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE >= 5
				case FIFTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIFTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE == 6
				case SIXTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SIXTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
			}
		}
	}
	if(bool:value == true && count == 1)//Returns the ID of the remaining team
	return i;
	
}
But the compiler says: warning 209: function "TeamsAlive" should return a value
Where is the problem?
Reply
#2

because compiler doesn't know what should that function return if the false statement of last if is executed. In general a function can't be a void and returning one at same time.
Reply
#3

Ah so what do i have to do in my case to fix this problem?

I never worked with bool before

And btw. which way is better?
I wrote 3 blocks for the same problem


Код:
stock TeamsAlive(bool:value)
{
	new i=0,count=0;
	while(i<TEAMSIZE)
	{
		if(GetTeamCount(i) > 0)
		{
			count++;
		}
		i++;	
	}
	if(bool:value == false)
	switch(count)
	{
		case 1:
		{
			switch(TeamsAlive(true))
			{
				case FIRST_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);
					}	
				}
				case SECOND_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
					}	
				}
				#if defined TEAMSIZE
				#if TEAMSIZE >= 3
				case THIRD_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",THIRD_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE >= 4
				case FOURTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FOURTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE >= 5
				case FIFTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIFTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE == 6
				case SIXTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SIXTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
			}
		}
	}
	if(bool:value == true && count == 1)//Returns the ID of the remaining team
	return i;
	
}
isEnd() function to call TeamsAlive

Код:
stock TeamsAlive(bool:value)
{
	new i=0,count=0;
	while(i<TEAMSIZE)
	{
		if(GetTeamCount(i) > 0)
		{
			count++;
		}
		i++;	
	}
	if(bool:value == false)//Returns the amount of remaining teams
	return count;
	if(bool:value == true && count == 1)//Returns the ID of the remaining team
	return i;
	
}


stock isEnd()
{
	switch(TeamsAlive(false))
	{
	case 0:
		{
			SendClientMessageToAll(COLOR_WHITE,"SERVER: All teams have been wiped. No one has won the game!");
		}
	case 1:
		{
			switch(TeamsAlive(true))
			{
			case FIRST_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);
					}	
				}
			case SECOND_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
					}	
				}
				#if defined TEAMSIZE
				#if TEAMSIZE >= 3
			case THIRD_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",THIRD_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE >= 4
			case FOURTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FOURTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE >= 5
			case FIFTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIFTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
				#if defined TEAMSIZE
				#if TEAMSIZE == 6
			case SIXTH_TEAM:
				{
					for(new i;i<MAX_PLAYERS;i++)
					{
						SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SIXTH_TEAM_COLOR_TAG);
					}	
				}
				#endif
				#endif
			}
			printf("Total game time: %d",totaltime);
			SendRconCommand("gmx");
		}
	default:
		{
			
		}
		
	}
	
}
Or massive if statements
Код:
#if defined TEAMSIZE
	#if TEAMSIZE == 2
	if(GetTeamCount(FIRST_TEAM) > 0 && GetTeamCount(SECOND_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) > 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	#endif
	#endif
	
	#if defined TEAMSIZE
	#if TEAMSIZE == 3
	if(GetTeamCount(FIRST_TEAM) > 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);
		}	
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) > 0 && GetTeamCount(THIRD_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) > 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",THIRD_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	#endif
	#endif
	#if defined TEAMSIZE
	#if TEAMSIZE == 4
	if(GetTeamCount(FIRST_TEAM) > 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");		
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) > 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) > 0 && GetTeamCount(FOURTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",THIRD_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) > 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FOURTH_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	#endif
	#endif
	
	#if defined TEAMSIZE
	#if TEAMSIZE == 5
	if(GetTeamCount(FIRST_TEAM) > 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM)== 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) > 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM)== 0)
	{	
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) > 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM)== 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",THIRD_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) > 0 && GetTeamCount(FIFTH_TEAM)== 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FOURTH_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM) > 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIFTH_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	#endif
	#endif
	
	#if defined TEAMSIZE
	#if TEAMSIZE == 6
	if(GetTeamCount(FIRST_TEAM) > 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM) == 0 && GetTeamCount(SIXTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIRST_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) > 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM)== 0 && GetTeamCount(SIXTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SECOND_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) > 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM)== 0 && GetTeamCount(SIXTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",THIRD_TEAM_COLOR_TAG);
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) > 0 && GetTeamCount(FIFTH_TEAM)== 0 && GetTeamCount(SIXTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FOURTH_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM) > 0 && GetTeamCount(SIXTH_TEAM) == 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",FIFTH_TEAM_COLOR_TAG);	
		}
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	if(GetTeamCount(FIRST_TEAM) == 0 && GetTeamCount(SECOND_TEAM) == 0 && GetTeamCount(THIRD_TEAM) == 0 && GetTeamCount(FOURTH_TEAM) == 0 && GetTeamCount(FIFTH_TEAM) == 0 && GetTeamCount(SIXTH_TEAM) > 0)
	{
		for(new i;i<MAX_PLAYERS;i++)
		{
			SendClientMessageEx(i,COLOR_WHITE,"SERVER: All remaining teams have been wiped. Team %s {FFFFFF}has won the game!",SIXTH_TEAM_COLOR_TAG);
		}	
		printf("Total game time: %d",totaltime);
		SendRconCommand("gmx");
	}
	#endif
	#endif
Reply
#4

depends upon on your intentions but I wont recommend last one as in case you want to work in that code after 2 months or later the readability can be a pain.
Reply
#5

Quote:
Originally Posted by faxxe
Посмотреть сообщение
Код:
	if(bool:value == true && count == 1)//Returns the ID of the remaining team
	return i;
}
means:

Код:
	if(bool:value == true && count == 1)
	{
		return i;
	}
	// no return if false
}
if value is false or count is not 1 there is no return
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)