[Include] dini2.inc - Improved dini file processor with amazing benchmarks (aka. gini)!

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Then the timer will close the file, its optional; "dini_Timeout" is just for efficiency.
But, If you are writing new code with dini2, you should use this function after Setting/Getting data, its just like any other INI_Close function.
Ok I'll add it then, thanks man.
Reply

My script uses dini, i compiled my script with dini2.inc, placed it all correctly but this is what i get.

Код:
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(13663) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(13698) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(13733) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(13768) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(13803) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(13842) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(13877) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(15738) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(23007) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(23855) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(23898) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(23906) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(23909) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(23955) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(24010) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(24018) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(24021) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(32970) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(33008) : error 017: undefined symbol "DINI_frenametextfile"
C:\Users\Miki\Desktop\V\gamemodes\Vault1.pwn(33195) : error 017: undefined symbol "DINI_frenametextfile"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


20 Errors.
Reply

@Mike861: "DINI_frenametextfile" wasn't there in original dini.inc, but i made it anyway in the new update, get v3.1 and it will compile without errors.

Update v3.1:
- New function added: DINI_frenametextfile
- Improved DINI_fcopytextfile
Reply

Quote:
Originally Posted by Gammix
Посмотреть сообщение
@Mike861: "DINI_frenametextfile" wasn't there in original dini.inc, but i made it anyway in the new update, get v3.1 and it will compile without errors.

Update v3.1:
- New function added: DINI_frenametextfile
- Improved DINI_fcopytextfile
But i saw it in original Dini.inc, it was literally in the bottom of the code.
Reply

Quote:
Originally Posted by Gammix
Посмотреть сообщение
@Mike861: "DINI_frenametextfile" wasn't there in original dini.inc, but i made it anyway in the new update, get v3.1 and it will compile without errors.

Update v3.1:
- New function added: DINI_frenametextfile
- Improved DINI_fcopytextfile
It works but some stuff that should save is broken.Like faction vehicles, skins etc..They don't load
Reply

I don't understand how some stuff stop working for some of you when the basic functionality works the same as original one

Show me a sample code of the part which isn't loading/saving properly.
Reply

They don't save, even when i relog they aren't there.And all other commands for organization that save stuff like weapons, cars, ranks, territories etc don't save..

Код:
CMD:addorgv(playerid, params[])
{
	new orgid, col1, col2, moneys1, tmp[256], tmp2[256], string[256], giveplayer[25], giveplayerid;
	if (adlvl[playerid] < 5) return 0;
	if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} You must be in a vehicle.");
	if (sscanf(params, "dddd", orgid, col1, col2)) return SendClientMessage2(playerid, COLOR_WHITE, "Usage: /addorgv [orgid] [color1] [color2]");
	format(string, 10, "org%d", orgid);
	if (!dini_Exists(AddDirFile(dir_orgfiles, string))) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} Invalid organization id.");
	if (col1 < -1 || col1 > 255 || col2 < -1 || col2 > 255) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} Invalid color id! (-1 - 255)");
	for (new ovs = MAX_ORG_VEHICLES; ovs > 0; ovs--)
	{
		format(giveplayer, 12, "ocmodel_%d", ovs);
		if (dini_Int(AddDirFile(dir_orgfiles, string), giveplayer) == 0) giveplayerid = ovs;
		else moneys1 ++;
	}
	if (moneys1 == MAX_ORG_VEHICLES)
	{
		format(tmp2, sizeof(tmp2), "This organization has reached the max of %d vehicles.", MAX_ORG_VEHICLES);
		SendClientMessage2(playerid, COLOR_RED, tmp2);
		return 1;
	}
	new pvid = GetPlayerVehicleID(playerid);
	if (vorgo[pvid] != 0) return SendClientMessage2(playerid, COLOR_RED, "This vehicle already belongs to an organization.");
	new Float:x, Float:y, Float:z, Float:a;
	GetVehiclePos(pvid, x, y, z);
	GetVehicleZAngle(pvid, a);
	new model = GetVehicleModel(pvid);
	format(giveplayer, 12, "ocmodel_%d", giveplayerid);
	dini_IntSet(AddDirFile(dir_orgfiles, string), giveplayer, model);
	format(giveplayer, 12, "ocx_%d", giveplayerid);
	dini_FloatSet(AddDirFile(dir_orgfiles, string), giveplayer, x);
	format(giveplayer, 12, "ocy_%d", giveplayerid);
	dini_FloatSet(AddDirFile(dir_orgfiles, string), giveplayer, y);
	format(giveplayer, 12, "ocz_%d", giveplayerid);
	dini_FloatSet(AddDirFile(dir_orgfiles, string), giveplayer, z);
	format(giveplayer, 12, "oca_%d", giveplayerid);
	dini_FloatSet(AddDirFile(dir_orgfiles, string), giveplayer, a);
	format(giveplayer, 12, "occ1_%d", giveplayerid);
	dini_IntSet(AddDirFile(dir_orgfiles, string), giveplayer, col1);
	format(giveplayer, 12, "occ2_%d", giveplayerid);
	dini_IntSet(AddDirFile(dir_orgfiles, string), giveplayer, col2);
	SetVehicleToRespawn(pvid);
	if (col1 == -1 || col2 == -1) orgvid[orgid-1][giveplayerid-1] = CreateVehicle(model, x, y, z, a, -1, -1, 900);
	else
	{
		orgvid[orgid-1][giveplayerid-1] = CreateVehicle(model, x, y, z, a, col1, col2, 900);
		vmodelused[model-400] ++;
		if (vmodelused[model-400] == 1) vehiclemodels ++;
	}
	if (dini_Isset(AddDirFile(dir_orgfiles, string), "lplate"))
	{
		format(tmp, 24, "%s %d", dini_Get(AddDirFile(dir_orgfiles, string), "lplate"), giveplayerid);
		SetVehicleNumberPlate2(orgvid[orgid-1][giveplayerid-1], tmp);
		SetVehicleToRespawn(orgvid[orgid-1][giveplayerid-1]);
	}
	vorgo[orgvid[orgid-1][giveplayerid-1]] = orgid;
	vorgid[orgvid[orgid-1][giveplayerid-1]] = giveplayerid;
	SendPlayerFormattedText(playerid, COLOR_SILVER, "Vehicle '%s' has been added to '%s'.", vehName[model-400], dini_Get(AddDirFile(dir_orgfiles, string), "name"));
	return 1;
}
Weapons aswell.
Код:
CMD:orgweaps(playerid, params[])
{
	new giveplayerid, weap1, ammo1, weap2, ammo2, weap3, ammo3, string[256];
	if (adlvl[playerid] < 5) return 0;
	if(sscanf(params, "ddd", giveplayerid, weap1, ammo1)) return SendClientMessage2(playerid, COLOR_WHITE, "Usage: /orgweaps [orgid] [weap1] [ammo1] [weap2] [ammo2] [weap3] [ammo3]");
	sscanf(params, "ddddd", giveplayerid, weap1, ammo1, weap2, ammo2);
	sscanf(params, "ddddddd", giveplayerid, weap1, ammo1, weap2, ammo2, weap3, ammo3);
	format(string, 10, "org%d", giveplayerid);
	if (!dini_Exists(AddDirFile(dir_orgfiles, string))) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} Invalid organization id.");
	if (weap1 == 17 || weap2 == 17 || weap3 == 17) return SendClientMessage2(playerid, COLOR_SILVER, "This weapon has been disabled and cannot be used!");
	if ((weap1 < 0 || weap1 == 19 || weap1 == 20 || weap1 == 21 || (weap1 > 34 && weap1 < 41) || weap1 > 46) || (weap2 < 0 || weap2 == 19 || weap2 == 20 || weap2 == 21 || (weap2 > 34 && weap2 < 41) || weap2 > 46)|| (weap3 < 0 || weap3 == 19 || weap3 == 20 || weap3 == 21 || (weap3 > 34 && weap3 < 41) || weap3 > 46) || (weap1 == 0 && ammo1 != 0) || (weap2 == 0 && ammo2 != 0) || (weap3 == 0 && ammo3 != 0) || (weap1 == 0 && (weap2 != 0 || weap3 != 0)) || (weap2 == 0 && weap3 != 0))
		return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} Invalid weapon id.");
	if ((ammo1 < 0 || ammo1 > 9999) || (ammo2 < 0 || ammo2 > 9999) || (ammo3 < 0 || ammo3 > 9999) || (ammo1 == 0 && weap1 != 0) || (ammo2 == 0 && weap2 != 0) || (ammo3 == 0 && weap3 != 0)) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} Invalid ammo amount.");
	dini_IntSet(AddDirFile(dir_orgfiles, string), "weap1", weap1);
	dini_IntSet(AddDirFile(dir_orgfiles, string), "ammo1", ammo1);
	dini_IntSet(AddDirFile(dir_orgfiles, string), "weap2", weap2);
	dini_IntSet(AddDirFile(dir_orgfiles, string), "ammo2", ammo2);
	dini_IntSet(AddDirFile(dir_orgfiles, string), "weap3", weap3);
	dini_IntSet(AddDirFile(dir_orgfiles, string), "ammo3", ammo3);
	for (new i = 0; i < PLAYERS; i++)
	{
		if (IsPlayerConnected2(i) && GetPVarInt(i, "playerorg") == giveplayerid && orcl[i][0] == 0 && jailedtime[i] == 0)
		{
			ResetPlayerWeapons(i);
			if (weap1 != 0)
			{
				GivePlayerWeapon2(i, weap1, ammo1);
				if (weap2 != 0)
				{
					GivePlayerWeapon2(i, weap2, ammo2);
					if (weap3 != 0) GivePlayerWeapon2(i, weap3, ammo3);
				}
			}
		}
	}
	if (weap1 == 0) format(string, sizeof(string), "%s's weapons removed.", dini_Get(AddDirFile(dir_orgfiles, string), "name"));
	else if (weap2 == 0) format(string, sizeof(string), "%s's weapons changed to %s with %d ammo.", dini_Get(AddDirFile(dir_orgfiles, string), "name"), WeaponName[weap1], ammo1);
	else if (weap3 == 0) format(string, sizeof(string), "%s's weapons changed to %s with %d ammo and %s with %d ammo.", dini_Get(AddDirFile(dir_orgfiles, string), "name"), WeaponName[weap1], ammo1, WeaponName[weap2], ammo2);
	else format(string, sizeof(string), "%s's weapons changed to %s with %d ammo, %s with %d ammo and %s with %d ammo.", dini_Get(AddDirFile(dir_orgfiles, string), "name"), WeaponName[weap1], ammo1, WeaponName[weap2], ammo2, WeaponName[weap3], ammo3);
	SendClientMessage2(playerid, COLOR_SILVER, string);
	return 1;
}
Reply

Wait, how many fields does your Organisation file have?
Max limit by default is 64.

If you want to increase this, you have the pre define this:
PHP код:
#define DINI_MAX_FIELDS n // n = your limit 
Define this before inclusion of dini2.
Reply

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Wait, how many fields does your Organisation file have?
Max limit by default is 64.

If you want to increase this, you have the pre define this:
PHP код:
#define DINI_MAX_FIELDS n // n = your limit 
Define this before inclusion of dini2.
I don't even have that defined in the gamemode.Ok let me try.
Reply

Quote:
Originally Posted by Mike861
Посмотреть сообщение
I don't even have that defined in the gamemode.Ok let me try.
By default if you don't have it defined, it will be 64. But i think your system have more than that in org file.
This may also increase your compile time and memory usage. I might make another update using pawn-memory plugin.
Reply

It saves vehicles and other stuff, but ranks i save actually save but won't load.
Код:
CMD:addranks(playerid, params[])
{
	new giveplayerid, rank, string[256], strings[256], tmp[256], giveplayers[256];
	if (orgleader[playerid] == 0) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} You aren't the (co)leader of an organization.");
	if(sscanf(params, "d",rank)) return SendClientMessage(playerid, COLOR_WHITE,"USAGE: /addranks [rank]");
	if(rank > 12) return SendClientMessage(playerid, COLOR_WHITE,"Error:{FFFFFF} You can add only 12 ranks to your Orginization!");
	if(rank < 1) return SendClientMessage(playerid, COLOR_WHITE,"Error:{FFFFFF} Ranks must be greater then 1 rank!");
	giveplayerid = GetPVarInt(playerid, "playerorg");
	format(string, 10, "org%d", giveplayerid);
	new temp = dini_Int(AddDirFile(dir_orgfiles, string), "AmountRanks");
	if(temp != 0) return SendClientMessage(playerid, COLOR_RED, "Error:{FFFFFF} You have already set ranks to this Orginization!");
	for(new i = 1; i<= rank; i++)
	{
	    format(giveplayers, 12, "rank%d", i);
	    format(tmp, 12, "rankcolor%d", i);
	    dini_Set(AddDirFile(dir_orgfiles, string), giveplayers, "none");
	    dini_IntSet(AddDirFile(dir_orgfiles, string), "AmountRanks", i);
	}
	format(strings, sizeof(strings), "You have created %d ranks for your organization", rank);
	SendClientMessage(playerid,COLOR_LBLUE, strings);
	return 1;
}
CMD:dranks(playerid, params[])
{
	new giveplayerid, string[256], tmp[256], giveplayers[256], tmps[256], tmp2[256];
    if (orgleader[playerid] == 0) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} You aren't the (co)leader of an organization.");
	giveplayerid = GetPVarInt(playerid, "playerorg");
	format(string, 10, "org%d", giveplayerid);
	new temp = dini_Int(AddDirFile(dir_orgfiles, string), "AmountRanks");
	if(temp == 0) return SendClientMessage(playerid, COLOR_RED, "Error:{FFFFFF} You have already delete ranks to this Orginization!");
	else if(temp != 0)
	{
	    new temp1 = dini_Int(AddDirFile(dir_orgfiles, string), "maxmembers");
		for(new j = 1; j <= temp1; j++)
		{
		    format(tmps, 12, "member%d", j);
			tmp2 = dini_Get(AddDirFile(dir_orgfiles, string), tmps);
			if(strcmp(tmp2, "server", false) != 0)
			{
				dini_Unset(AddDirFile(dir_orgfiles, tmp2), "RankName");
				dini_Unset(AddDirFile(dir_orgfiles, tmp2), "Rank");
				dini_Unset(AddDirFile(dir_orgfiles, tmp2), "RankColor");
			}
		}
		for(new i = 1; i <= temp; i++)
		{
			format(giveplayers, 12, "rank%d", i);
			format(tmp, 12, "rankcolor%d",i);
			dini_Unset(AddDirFile(dir_orgfiles, string), giveplayers);
			dini_Unset(AddDirFile(dir_orgfiles, string), tmp);
			dini_IntSet(AddDirFile(dir_orgfiles, string), "AmountRanks", 0);
		}
	}
    SendClientMessage(playerid, COLOR_RED, "You have deleted all created ranks from your Organization!");
	return 1;
}
CMD:rankname(playerid, params[])
{
    new tmp2[256], tmp[20], tmp3[20],number, string[20], str[120], color[128],giveplayer[256],tmp7[256];
    if (orgleader[playerid] != 1) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} You aren't the leader of an organization.");
    if (sscanf(params, "ds[128]s[128]", number, color,tmp2)) return SendClientMessage2(playerid, COLOR_WHITE, "Usage: /rankname [rank number] [rank color] [rank name]");
    new giveplayerid = GetPVarInt(playerid, "playerorg");
    format(string, 10, "org%d", giveplayerid);

    new temp4 = dini_Int(AddDirFile(dir_orgfiles, string), "maxmembers");

    for (new c = 1; c <= number; c++)
    {
    	format(tmp, 12, "rank%d", number);
    	format(tmp3, 12, "rankcolor%d", number);
        if (!dini_Isset(AddDirFile(dir_orgfiles, string), tmp))
		{
		 SendClientMessage2(playerid, COLOR_RED, "Rank on this spot is not created yet.");
		 return 1;
		}
		dini_Set(AddDirFile(dir_orgfiles, string), tmp, tmp2);
		dini_Set(AddDirFile(dir_orgfiles, string), tmp3, color);
		if (temp4 != 0)
		{
				for (new i = 1; i <= temp4; i++)
				{
					format(giveplayer, 12, "member%d", i);
	                tmp7 = dini_Get(AddDirFile(dir_orgfiles, string), giveplayer);
					if (dini_Isset(AddDirFile(dir_userfiles, tmp7), "RankName") && dini_Int(AddDirFile(dir_userfiles, tmp7), "Rank") == number)
			        {
						dini_Set(AddDirFile(dir_userfiles, tmp7), "RankName", tmp2);
						dini_Set(AddDirFile(dir_userfiles, tmp7), "RankColor", color);
					}
				}
		}
	}
	format(str, sizeof(str), "You have set rank %d name to %s with color {%s}%s", number, tmp2, color, color);
	SendClientMessage(playerid, COLOR_WHITE, str);
	return 1;
}
CMD:setrank(playerid, params[])
{
	new giveplayerid, rank, pname[64], str[150], string[10], tmp[10], tmp2[15], tmp6[256];
    new giveplayerids = GetPVarInt(playerid, "playerorg");
    if (sscanf(params, "ud", giveplayerid, rank)) return SendClientMessage2(playerid, COLOR_WHITE, "Usage: /setrank [playerid] [rank]");
    if (!IsPlayerConnected2(giveplayerid)) return SendClientMessage2(playerid, COLOR_RED, "Error:{FFFFFF} Inactive player id!");
    format(string, 10, "org%d", giveplayerids);
    GetPlayerName(giveplayerid,pname, MAX_PLAYER_NAME);
    new maxranks = dini_Int(AddDirFile(dir_orgfiles, string), "Amountranks");
    new currrank = dini_Int(AddDirFile(dir_userfiles, pname), "Rank");
	if (maxranks == 0) return SendClientMessage2(playerid, COLOR_RED, "There is no ranks created in your organization.");
	if(rank > maxranks || rank < 1) return SendClientMessage2(playerid, COLOR_RED, "Invalid rank!");
	if(rank == currrank) return SendPlayerFormattedText(playerid, COLOR_RED, "%s is already have that rank!", pname, "");
	if(rank > maxranks) return SendClientMessage2(playerid, COLOR_RED, "No rank found!");
    if (GetPVarInt(giveplayerid, "playerorg") != GetPVarInt(playerid, "playerorg")) return SendPlayerFormattedText(playerid, COLOR_RED, "%s is not in your organization!", pname, "");
    for (new c = 1; c <= rank; c++)
    {
    	format(tmp, 12, "rank%d", rank);
    	format(tmp2, 12, "rankcolor%d", rank);
	}
	tmp6 = dini_Get(AddDirFile(dir_orgfiles, string), tmp);
	if (strcmp(tmp6, "None", false) == 0) return SendClientMessage(playerid,COLOR_RED,"Choose a name for this rank first.");

	if (giveplayerid != playerid)
	{
    	    format(str,sizeof(str),"You have set %s rank to {%s}%s", pname,dini_Get(AddDirFile(dir_orgfiles, string), tmp2),dini_Get(AddDirFile(dir_orgfiles, string), tmp));
	        SendClientMessage(playerid, COLOR_YELLOW,str);

			format(str,sizeof(str),"Your leader has set your to rank {%s}%s", dini_Get(AddDirFile(dir_orgfiles, string), tmp2), dini_Get(AddDirFile(dir_orgfiles, string), tmp));
	        SendClientMessage(giveplayerid, COLOR_YELLOW,str);
	}
	else
	{
		 	format(str,sizeof(str),"You have set your rank to {%s}%s", dini_Get(AddDirFile(dir_orgfiles, string), tmp2), dini_Get(AddDirFile(dir_orgfiles, string), tmp));
	        SendClientMessage(playerid, COLOR_YELLOW,str);
	}
	dini_IntSet(AddDirFile(dir_userfiles, pname), "Rank", rank);
	dini_Set(AddDirFile(dir_userfiles, pname), "RankName", dini_Get(AddDirFile(dir_orgfiles, string), tmp));
	dini_Set(AddDirFile(dir_userfiles, pname), "RankColor", dini_Get(AddDirFile(dir_orgfiles, string), tmp2));
	return 1;
}
Reply

Too much code here, which line actually isn't working?
Reply

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Too much code here, which line actually isn't working?
setrank one, i added ranks but it says theres no ranks.
Reply

bump?
Reply

EDIT: Sorry, I'm Mike's partner and I've fixed the issue. It wasn't an issue with your include. Great Job!
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)