Creating player groups
#1

Hi, I'm creating player groups script and I don't know how to do multiple groups for one player, I have this code:
Код:
#define SetPlayerGroup(%0,%1) SetPVarString(%0, "Group", %1)
#define GetPlayerGroup(%0) GetPVarString(%0, "Group", group) return group; 
#define SendMessageToGroup(%0,%1,%2) for(new i=0; i<MAX_PLAYERS; i++) GetPVarString(i, "Group", group); if(!strcmp(%0, group)) SendClientMessage(i, %1, %2)
#define SendFormmatedMessageToGroup(%0,%1,%2,%3) format(formattedMessage, sizeof(formattedMessage), %2, %3); for(new i=0; i<MAX_PLAYERS; i++) GetPVarString(i, "Group", group); if(!strcmp(%0, group)) SendClientMessage(i, %1, formattedMessage)
#define CountOnlineGroupPlayers(%0) new count=0; for(new i=0; i<MAX_PLAYERS; i++) { GetPVarString(i, "Group", group); if(!strcmp(%0, group)) count++; } return count;
#define IsPlayerInAnyGroup(%0) GetPVarString(%0, "Group", group); if(strlen(group) > 0) return true;
Now I can use only one group per player, I asking how to edit this code that I can use 1, 2, 3 etc. groups per player like this:
Код:
SetPlayerGroup(playerid, "Group One");
SetPlayerGroup(playerid, "Group Two");
SetPlayerGroup(playerid, "Group Three");
And some make GetPlayerGroups, who gets maybe array of player groups or some, who can I use for codes like this:
Код:
if(!strcmp(GetPlayerGroups(playerid), "Group One"))
if(!strcmp(GetPlayerGroups(playerid), "Group One") || !strcmp(GetPlayerGroups(playerid), "Group Two"))
if(!strcmp(GetPlayerGroups(playerid), "Group One") && !strcmp(GetPlayerGroups(playerid), "Group Three"))
Reply
#2

You should use integer instead of strings
They are easier to store and to compare
Reply
#3

If you are not a NIH person, you can use y_groups. It has everything you asked for! If not, you can - Get the group name, encrypt it, store it as a PVar, decrypt when you need and so on. Or you can use enums instead, because PVars are not really recommended (so have I heard)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)