Y_INI factions
#1

Hey guys, I am having trouble with saving/loading data..

I've made this:
Код:
enum E_PLAYER_DATA
{
    Faction,
    Rank
};
new PlayerInfo[MAX_PLAYERS][E_PLAYER_DATA];


// make leader cmds, doesn't write the data down into INI files
CMD:makeleader(playerid, params[])
{
	new targetid, factionid, string[128], targetname[24], playername[24];
	if(sscanf(params, "ui", targetid, factionid)) return SendClientMessage(playerid, -1, "Usage: /makeleader [playerid][factionid]"); 
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not an admin"); 
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); 
	if(0 < factionid < 6) 
	{
		GetPlayerName(playerid, playername, sizeof(playername)); 
		GetPlayerName(targetid, targetname, sizeof(targetname)); 
	    format(string, sizeof(string), "You made %s leader of faction id %i!", targetname, factionid); 
		SendClientMessage(playerid, -1, string); 
		format(string, sizeof(string), "You were made leader of faction id %i by %s", factionid, playername);
	    SendClientMessage(playerid, -1, string);
		new INI:file = INI_Open(UserPath(playerid));
        INI_SetTag(file, "Factions");
        INI_WriteInt(file, "Faction", PlayerInfo[playerid][Faction] == factionid);
		INI_WriteInt(file, "Rank" , PlayerInfo[playerid][Rank] == 6);
		INI_Close(file); 
	}
	else return SendClientMessage(playerid, -1, "Invalid factionid.  Factionid's: 1-6"); 
	return 1;
}

//then this:
CMD:setrank(playerid, params[])
{
	new targetid, rank, targetname[24], playername[24], string[128];
	if(sscanf(params, "ui", targetid, rank)) return SendClientMessage(playerid, -1, "Usage: /setrank [playerid/partofname][rank]"); 
	if(PlayerInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not the leader of a faction!"); 
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "That player is not connected!"); 
	if(PlayerInfo[targetid][Faction] != PlayerInfo[playerid][Faction]) return SendClientMessage(playerid, -1, "That player is not in your faction!");
	if(0 < rank < 7) 
	{ 
	    GetPlayerName(playerid, playername, sizeof(playername));
	    GetPlayerName(targetid, targetname, sizeof(targetname));
		if(PlayerInfo[targetid][Rank] < rank) 
		{ 
		    format(string, sizeof(string), "You have been promoted to rank %i by %s!", rank, playername);
		    SendClientMessage(targetid, -1, string);
		    format(string, sizeof(string), "You promoted %s to rank %i", targetname, rank); 
		    SendClientMessage(playerid, -1, string); 
		} 
		else 
		{ 
		    format(string, sizeof(string), "You have been demoted to rank %i by %s!", rank, playername); 
		    SendClientMessage(targetid, -1, string); 
		    format(string, sizeof(string), "You demoted %s to rank %i", targetname, rank);
		    SendClientMessage(playerid, -1, string);
		}
	}
	return 1;
}

// cant demote or promote cause I am not a leader, after I use /makeleader on myself. Gives me this :



and for the last part of it, my userfile looks like this:



P.S. - It doesn't save any of the data into this file, I was using this tutorial to create it:https://sampforum.blast.hk/showthread.php?tid=597639 But it doesn't save the data (with other users i have money on hand, and it still writes down '0' into the scriptfiles.)

I've made this cmd to check if I was assigned to id 1 faction, didn't work either..

CMD:cop(playerid, params[])
{
    if(PlayerInfo[playerid][Faction] == 1)
    {
        SendClientMessage(playerid, COLOR_RED, "YOU ARE A POPO");
		new Float:x, Float:y, Float:z;
		GetPlayerPos(playerid, x, y, z);
		SetPlayerPos(playerid, x, y, z+10);
	}
 	return SendClientMessage(playerid, COLOR_WHITE, "YOU ARE NO POPO");
}
thanks to anyone who could solve this
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)