[INI]Groupname detect?
#1

Heey all,

How can i detect if a groupname alreay is choosen?
I made a command like creategroup:
Код:
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;
}
How can i detect if a groupname already is choosen?

Admigo
Reply
#2

Loop through all names and compare them with params. If it returns 0, break the loop and the entire function.
Reply
#3

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Loop through all names and compare them with params. If it returns 0, break the loop and the entire function.
How i can do that?
I have files like:
0.ini
Код:
GroupName = test
GroupOwner = INVALID_PLAYER_ID
GroupMoney = 0
GroupScore = 0
GroupKills = 0
GroupDeaths = 0
1.ini
Код:
GroupName = test2
GroupOwner = INVALID_PLAYER_ID
GroupMoney = 0
GroupScore = 0
GroupKills = 0
GroupDeaths = 0
Reply
#4

I suppose you load all files on init?

pawn Код:
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.
}
Btw: Are you using my group system, or just inspired? Or doesn't it have to do with it?
Reply
#5

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
I suppose you load all files on init?

pawn Код:
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.
}
Btw: Are you using my group system, or just inspired? Or doesn't it have to do with it?
I am using GarHouse filterscript. I changed everything to group. This code will detect the groups into the files or can you edit my command and add if the group already exist?
Reply
#6

This code will check the enum if there is already a group with that name, not the files.
Reply
#7

I made this now:
Код:
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;
}
How can i save groupname as the file like if i do:
Код:
/creategroup test
The file will be named test.ini
I tested this code but then the file appears in numbers like :116.ini
And when i do /creategroup test2 there dont will be made a new file.
How can i fix those problems?

Thanks Admigo
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)