Going back to his original post, as OciXCrom just pointed out, the problem is he has the same variable 'team' defined as both an array and a single cell variable. Within the function, copy() is using the cell version of the variable 'team' instead of the array 'team[]' in the parameter list; this results in error 035: argument type mismatch (argument 1) since copy() expects an array.
Code:
new team
[32];
get_opposite_team
(idattacker, team
);
stock get_opposite_team(index, team[])
{
new CsTeams:team = cs_get_user_team(index);
if(team == CS_TEAM_T
)
{
copy(team, charsmax
(team
),
"TERRORIST");
// line 549;
}
else
{
copy(team, charsmax
(team
),
"CT");
// line 553;
}
return 0;
} // line 557;
In addition to that, you cannot use charsmax() on an unsized array in the function parameter list. So yes, specifying the array size in the parameter list will allow charsmax to be used. But it is more common to leave the array size open and require the user to specify the maximum chars of the array/string being passed.
PHP Code:
public Test( id )
{
new szTeam[ 10 ];
get_opposite_team( id , szTeam , charsmax( szTeam ) );
get_opposite_team2( id , szTeam );
}
stock get_opposite_team( index , szTeam[] , maxchars )
{
return copy( szTeam , maxchars , cs_get_user_team( index ) == CS_TEAM_T ? "CT" : "TERRORIST" );
}
stock get_opposite_team2( index , szTeam[ 10 ] )
{
return copy( szTeam , charsmax( szTeam ) , cs_get_user_team( index ) == CS_TEAM_T ? "CT" : "TERRORIST" );
}
Both versions still have a flaw because if the user is a spectator or unassigned, it will always return TERRORIST.
Here is another version that will do the following:
- Only return a value if the source player is T or CT
- Allow you to get both the string team name and integer team value CS_TEAM_T or CS_TEAM_CT. The string/size parameters are optional. If specified, it will populate with team name. The function will always return integer opposite team value.
PHP Code:
public Test( id )
{
//Use function to get string team name.
new szTeam[ 10 ];
if ( get_opposite_team( id , szTeam , charsmax( szTeam ) ) )
{
//Successfully found opposite T or CT team
//szTeam holds opposite team name.
}
else
{
//Source player was unassigned or spectator.
//szTeam holds nothing (remains unchanged).
}
//============================================================
//Use function to get integer team value (CS_TEAM_T , CS_TEAM_CT)
new CsTeams:iOppositeTeam = get_opposite_team( id );
if ( iOppositeTeam )
{
//Successfully found opposite T or CT team
}
else
{
//Source player was unassigned or spectator.
}
}
stock CsTeams:get_opposite_team( index , szTeam[]="" , iMaxChars=0 )
{
new CsTeams:iOppositeTeam;
new CsTeams:iTeam = cs_get_user_team( index );
new const szTeamNames[ CsTeams ][] = { "" , "TERRORIST" , "CT" , "" };
if ( CS_TEAM_T <= iTeam <= CS_TEAM_CT )
{
iOppositeTeam = CsTeams:abs( _:( iTeam - CS_TEAM_SPECTATOR ) );
if ( iMaxChars )
copy( szTeam , iMaxChars , szTeamNames[ iOppositeTeam ] );
}
return iOppositeTeam;
}
__________________