05.11.2017, 11:28
Hi All,
I am trying to make a cmd to check if the person in the group rank had permission or is the group owner.
Both the Ifs work individually but not working together with a || function.
It is checking if both are valid instead of anyone.
I am trying to make a cmd to check if the person in the group rank had permission or is the group owner.
Both the Ifs work individually but not working together with a || function.
It is checking if both are valid instead of anyone.
Код:
if((!IsGroupPermValid(playerid, gname, "gcreaterank")) || (!IsGroupOwner(playerid, gname))) return SystemMsg(playerid, "You do not have permission to use this command");
Код:
stock IsGroupPermValid(playerid, gname[64], cmd[24]) { new PlayerName[24]; GetPlayerName(playerid, PlayerName, 24); new query[200]; format(query,sizeof(query),"SELECT rank FROM gmembers WHERE gname = '%s' AND name = '%s' LIMIT 1" , gname, PlayerName); mysql_query(query); mysql_store_result(); if(mysql_num_rows() == 0) { mysql_free_result(); SystemMsg(playerid,"[ERROR] You are not part of this group."); return false; } new resultline[200], rank; if(mysql_fetch_row_format(resultline)) { //you can now use sscanf, explode, split or strtok to split result //AdminMsg(resultline); sscanf(resultline,"p<|>d",rank); } mysql_free_result(); //AdminMsg(resultline); //new test[24]; format(test, 24, "Rank %d", rank); //SystemMsg(playerid, test); new query1[200]; format(query1,sizeof(query1),"SELECT * FROM gperms WHERE gname = '%s' AND rank = '%d' AND cmd = '%s' LIMIT 1" , gname, rank, cmd); mysql_query(query1); mysql_store_result(); if(mysql_num_rows() == 0) { mysql_free_result(); SystemMsg(playerid,"[ERROR] You do not have group permission for this command."); return false; } else return true, SystemMsg(playerid, "Perm True"), mysql_free_result(); } stock IsGroupOwner(playerid, gname[64]) { new PlayerName[24]; GetPlayerName(playerid, PlayerName, 24); new query[200]; format(query,sizeof(query),"SELECT * FROM groups WHERE name = '%s' AND owner = '%s' LIMIT 1" , gname, PlayerName); mysql_query(query); mysql_store_result(); if(mysql_num_rows() == 0) { mysql_free_result(); SystemMsg(playerid,"[ERROR] You are not the group owner."); return false; } else return true, SystemMsg(playerid, "Owner True"), mysql_free_result(); } CMD:gcreaterank(playerid, params[]) { new PlayerName[24]; GetPlayerName(playerid, PlayerName, 24); if(AccountGetInt(PlayerName, "LoggedIn") == 0) return 1; new idx, gname[64], rname[64]; if(sscanf(params, "s[64]ds[64]", gname, idx, rname)) return SystemMsg(playerid, "/gcreaterank [Group Name] [Rank#] [Rank Name]"); // !IsGroupPermValid(playerid, gname, "gcreaterank") if((!IsGroupPermValid(playerid, gname, "gcreaterank")) || (!IsGroupOwner(playerid, gname))) return SystemMsg(playerid, "You do not have permission to use this command"); new string[128], query[128], query2[128], query3[128], query4[128]; format(string, sizeof(string), "Cmd Group Create Rank Used with Rank#: %d, Rank Name: %s for Group Name: %s", idx, rname, gname); AdminMsg(string); format(query3,sizeof(query3),"SELECT * FROM groups WHERE name = '%s' LIMIT 1" , gname); mysql_query(query3); mysql_store_result(); if(mysql_num_rows() == 0) { mysql_free_result(); SystemMsg(playerid,"[ERROR] This group does not exists."); return 1; } mysql_free_result(); format(query4,sizeof(query4),"SELECT * FROM granks WHERE rank = '%d' AND gname = '%s' LIMIT 1" , idx, gname); mysql_query(query4); mysql_store_result(); if(mysql_num_rows() != 0) { mysql_free_result(); SystemMsg(playerid,"[ERROR] This rank number already exists in this group"); return 1; } mysql_free_result(); format(query,sizeof(query),"SELECT * FROM granks WHERE rankname = '%s' AND gname = '%s' LIMIT 1" ,rname, gname); mysql_query(query); mysql_store_result(); if(mysql_num_rows() != 0) { mysql_free_result(); SystemMsg(playerid,"[ERROR] This rank name already exists in this group"); return 1; } mysql_free_result(); new TargetName[24]; GetPlayerName(idx, TargetName, 24); format(query2, sizeof(query2), "INSERT INTO `granks` (gname, rank, rankname) VALUES ('%s', '%d', '%s');", gname, idx, rname); mysql_query(query2, -1); return 1; }