Need help in syntax
#1

here an string returns...
how can i compare the string?
Code:
if(GetPlayerClanRank(playerid)=="Owner")
{

   return 1;
}
PHP Code:
stock GetPlayerClanRank(playerid)
{
    new 
player_name[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,player_name,sizeof(player_name));
    new 
rank[100];
    new 
clanquery[100];
    new 
Cache:count;
    
mysql_format(gSQL,clanquerysizeof(clanquery), "SELECT playerclanrank FROM Clan_Members WHERE playername = '%s'"player_name);
    
count mysql_query(gSQL,clanquery);
    
cache_get_value_name(0,"playerclanrank",rank);
    
cache_delete(count);
    return 
rank;

plz help me to check the return string value
Reply
#2

PHP Code:
if(!strcmp(GetPlayerClanRank(playerid), "Owner"true)) //False to matchcase (O != o), True to ignore case (O == o)
{
//match
}
else
{
//doesn't match

Reply
#3

Thanks ++rep
Reply
#4

If i want to check possible matches.. more than one.

if(!strcmp(GetPlayerClanRank(playerid), "Owner","Leader", true)) is it correct ?
Reply
#5

Quote:
Originally Posted by Jokers98s
View Post
If i want to check possible matches.. more than one.

if(!strcmp(GetPlayerClanRank(playerid), "Owner","Leader", true)) is it correct ?
Nope you just use the strcmp again with the "Leader" instead of "Owner".

And by the way this is bad coding practice, You should avoid comparing strings whenever possible for more optimization.

So, Instead of comparing the ranks names, Assign an integer to each rank (Use #define) to define the integer name.
Example:
PHP Code:
//OnTop
#define CLAN_OWNER 6
#define CLAN_LEADER 5
//Now when comparing/assigning the rank you simply use the define name
//Such as
Rank[playerid] = CLAN_OWNER//Assigning (Could be different variable but just for clarifying)
if(Rank[playerid] == CLAN_OWNER//Comparing
{
//Do something

Just think of the define as the define name will be replaced with whatever near it on compilation. so it is legit.
Reply
#6

got 3 places like Owner, Co-owner, Leader all three can invite player to clan. So how will be the if condition.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)