dcmd_creategroup(playerid, params[]) { new groupname, g = GetFreeGroupID(); new pName4[MAX_PLAYER_NAME]; GetPlayerName(playerid,pName4,sizeof(pName4)); //if(!IsPlayerAdmin(playerid)) return 0; if(sscanf(params,"u",groupname)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /creategroup [Groupname]"); else { fcreate(GroupFile(g)); format(GroupInfo[g][gName], 35, "%s", groupname); format(GroupInfo[g][gOwner], 25, "%s", pName4); new INI:file = INI_Open(GroupFile(g)); INI_WriteString(file, "GroupName", params); INI_WriteString(file, "GroupOwner", pName4); INI_WriteInt(file, "GroupMoney", 0); INI_WriteInt(file, "GroupScore", 0); INI_WriteInt(file, "GroupKills", 0); INI_WriteInt(file, "GroupDeaths", 0); INI_Close(file); } return 1; }
Loop through all names and compare them with params. If it returns 0, break the loop and the entire function.
|
GroupName = test GroupOwner = INVALID_PLAYER_ID GroupMoney = 0 GroupScore = 0 GroupKills = 0 GroupDeaths = 0
GroupName = test2 GroupOwner = INVALID_PLAYER_ID GroupMoney = 0 GroupScore = 0 GroupKills = 0 GroupDeaths = 0
stock GroupNameExists(name[]) // Lets make a new stock to check if a name exists
{
for(new i = 0; i < MAX_GROUPS; i ++) // Start a loop from 0 till MAX_GROUPS
{
if(!strcmp(GroupInfo[i][GroupName],name,false)) return 1; // If strcmp returns 0, "name" and the group name matches. The loop will break
}
return 0; // If nothing found, return 0.
}
I suppose you load all files on init?
pawn Код:
|
dcmd_creategroup(playerid, params[]) { new groupname ,g = GetFreeGroupID(); new pName4[MAX_PLAYER_NAME]; GetPlayerName(playerid,pName4,sizeof(pName4)); //if(!IsPlayerAdmin(playerid)) return 0; if(sscanf(params,"s",groupname)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /creategroup [Groupname]"); if(strlen(params) > 49 || strlen(params) < 3) return SendClientMessage(playerid, COLOR_RED, "Usage: /groupcreate [Group name 3-50 characters])!"); if(fexist(GroupFile(g))) return SendClientMessage(playerid,COLOR_RED,"This groupname already exist."); else { fcreate(GroupFile(groupname)); format(GroupInfo[g][gName], 35, "%s", groupname); format(GroupInfo[g][gOwner], 25, "%s", pName4); new INI:file = INI_Open(GroupFile(groupname)); INI_WriteString(file, "GroupName", params); INI_WriteString(file, "GroupOwner", pName4); INI_WriteInt(file, "GroupMoney", 0); INI_WriteInt(file, "GroupScore", 0); INI_WriteInt(file, "GroupKills", 0); INI_WriteInt(file, "GroupDeaths", 0); INI_Close(file); } return 1; }
/creategroup test