SA-MP Forums Archive
Need help in syntax - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help in syntax (/showthread.php?tid=648280)



Need help in syntax - Jokers98s - 19.01.2018

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


Re: Need help in syntax - FailerZ - 19.01.2018

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




Re: Need help in syntax - Jokers98s - 19.01.2018

Thanks ++rep


Re: Need help in syntax - Jokers98s - 19.01.2018

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

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


Re: Need help in syntax - FailerZ - 19.01.2018

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.


Re: Need help in syntax - Jokers98s - 19.01.2018

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