Help with file functions.
#1

Hi there.So i while making /createfaction cmd i made a way in which the name of faction will be stores in a file with its name and the faction id in front of it. So see while making deletefaction cmd. I've set up everything even have a fdelete stock. What i want to do is that is there any way. for ex. /deletefaction [faction id]. the command executed and the faction got deleted but i need to remove that faction from that file too. So is there any way in which it will read that file and matched the [faction id] with the data stored in it and if the [faction id] matches with some string then that string would be deleted?
Reply
#2

BUMP!
Reply
#3

Bump!
Reply
#4

if you use faction name for files and use faction id on parameter of cmd the you have to get the name of faction with corresponding id and then use Fremove to delete that file storing data of faction.
You can use name arguement in Fremove as the same name as the name of faction you got from id.
Код:
YOUR CMD:
{
 //sscanf -> get faction id
 //process id to get name
 Fremove(name_of_faction.format);
//return 1; 
}
TIP: Use SQL systems instead of these file systems.
Reply
#5

Any idea?
Код:
CMD:deletefaction(playerid, params[])
{
	if(pInfo[playerid][pLevel] >= 5)
	{
		new slot,fac = FacCount,string[120];
		if(sscanf(params,"i",slot)) return SCM(playerid,COLOR_ORANGE,"USAGE: /deletefaction (faction id)");
		if(slot == 0) return SCM(playerid,COLOR_RED,"Invalid ID!");
		for(new i=0; i<MAX_FACTIONS; i++) if(slot == FactionInfo[i][FacSlots])
		{
			FacCount--;
			format(hf,sizeof(hf),"Factions/%i.ini",fac);
			if(fexist(hf))
			{
			fremove(hf);
			}
			format(string,sizeof(string),"You have deleted %s faction.",FactionInfo[i][FacName]);
			SCM(playerid,COLOR_RED,string);
			format(FactionInfo[i][FacName], 50,"NONE");
		}
		fdeleteline("Factions/Names.ini", slot);
	}
	return 1;
}
CMD:factions(playerid, params[])
{
		new strings[128],File: file = fopen("Factions/Names.ini", io_read);
	    while(fread(file, strings))
	    {
	        format(strings, sizeof(strings), "[%d] %s.", fa, strings);
	        SendClientMessage(playerid, COLOR_YELLOW, strings);
	    }
    	fclose(file);
    	return 1;
}
CMD:createfaction(playerid, params[])
{
	if(pInfo[playerid][pLevel] >= 5)
	{

			new id,name[50],fac = FacCount,File: file = fopen("Factions/Names.ini", io_append);
			if(sscanf(params,"us[50]",id,name)) return SCM(playerid,COLOR_ORANGE,"USAGE: /createfaction (playerid) (faction name)");
			if(fac >= MAX_FACTIONS) return SCM(playerid,COLOR_RED,"Max faction limit reached!");
			if(pInfo[id][flevel] == 0)
			{
    		format(FactionInfo[fac][FacName], 50, "%s", name);
			format(FactionInfo[fac][FacOwner], 20, "%s", PN(id));
			FactionInfo[fac][FacRanks] = 5;
			FactionInfo[fac][FacLevels] = 10;
			FactionInfo[fac][FacSlots] = FacCount;
			pInfo[id][flevel] = 10;
			pInfo[id][frank] = 5;
			pInfo[id][fname] = name;
			pInfo[id][pfacno] = FacCount;
			SaveStatus(id);
			new string2[120];
			format(string2,sizeof(string2),"[%d.] %s.\r\n",fac,name);
   			fwrite(file, string2);
   			fclose(file);
	  		format(hf,sizeof(hf),"Factions/%i.ini",fac);
			new INI:fac2 = INI_Open(hf);
			INI_WriteString(fac2,"Name",FactionInfo[fac][FacName]);
			INI_WriteString(fac2,"Owner",FactionInfo[fac][FacOwner]);
			INI_WriteInt(fac2,"Slot",FactionInfo[fac][FacSlots]);
			INI_WriteInt(fac2,"Taken",FactionInfo[fac][FacTaken]);
			INI_WriteInt(fac2,"Ranks",FactionInfo[fac][FacRanks]);
			INI_WriteInt(fac2,"Levels",FactionInfo[fac][FacLevels]);
			INI_Close(fac2);
			new string[120];
			format(string,sizeof(string),"You created a faction for %s with name %s.",PN(id),name);
			SCM(playerid,COLOR_YELLOW,string);
			format(string,sizeof(string),"Administrator %s has created a faction for you with name %s.",PN(playerid),name);
			SCM(id,COLOR_YELLOW,string);
			FacCount++;
			}
	}
	return 1;
}
Reply
#6

BUMP!
Reply
#7

You should know already, 24 hour bumps only. As said though, SQL is a good thing. Gammix made an SQL include which is quite awesome.
Reply
#8

I don't know how to save with sql and watched the tutorials but its quite hard
Reply
#9

It's not hard, and as I said, check out Gammixs include as that makes it even simpler.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)