Saving datas to mysql
#1

I have a faction system but it won't save in mysql. You need to create it everytime you log in, and it members needs to be invited again. I want to make it to be saved.

This is my faction script.


Code:
#define MAX_factionS 750
new factionCount;

enum factionstats
{
	factionOwner[24],
	factionMembers,
	factionName[16],
	factionID
}

new factions[MAX_factionS][factionstats];

CMD:makefaction(playerid,params[])
{
	new factionnamecmd[16];
	if(sscanf(params, "s[16]", factionnamecmd)) return SendClientMessage(playerid,-1,"*"COL_RED" /makefaction [faction name] [16 Characters]");

	if(gettime() - 480 < pInfo[playerid][pfactionSpam]) return SendClientMessage(playerid,-1,"*"COL_RED" Wait eight minutes to create an faction again!");
	{
  if(pInfo[playerid][Leader] == 1)
		{
		    if(pInfo[playerid][IsPlayerInfaction] == 0)
		    {
				if(strlen(params) > 16)
				{
					SendClientMessage(playerid,-1,"*"COL_RED" faction name is to long (MAX CHARACTERS 16)");
				}
				else
				{
					DayZSA_Createfaction(playerid,factionnamecmd,PlayerName(playerid));
					pInfo[playerid][pfactionSpam] = gettime();
				}
			}
			else return SendClientMessage(playerid,-1,"*"COL_RED" You are already in a faction/made one!");
		}
		else return SendClientMessage(playerid,-1,"*"COL_RED" You need approve from an Admin!");
	}
	return 1;
}

CMD:invitefaction(playerid,params[])
{
	new targetid;
	if(sscanf(params, "u", targetid)) return SendClientMessage(playerid,-1,"*"COL_RED" /invitefaction [playerid]");

	if(pInfo[targetid][IsPlayerInfaction] == 0)
	{
		if(pInfo[playerid][IsPlayerInfaction] == 1)
		{
		    if(pInfo[playerid][IsPlayerfactionOwner] == 1)
		    {
				new str[256],str2[128];
				format(str,sizeof(str),"*"COL_YELLOW" %s(%i) has invited you to faction %s(%i) /acceptfaction, to join the faction to deny /denyfaction!",PlayerName(playerid),playerid,GetPlayerfactionName(playerid),pInfo[playerid][IsPlayerInfactionID]);
				SendClientMessage(targetid,-1,str);
				format(str2,sizeof(str2),"*"COL_YELLOW" You have sent an invite to %s(%i) to join your faction!",PlayerName(targetid),targetid);
				SendClientMessage(playerid,-1,str2);
				pInfo[targetid][IsPlayerInvitedfactionID] = pInfo[playerid][IsPlayerInfactionID];
				pInfo[targetid][IsPlayerInvited] = 1;
			}
			else return SendClientMessage(playerid,-1,"*"COL_RED" You must be the faction owner to use this command!");
		}
		else return SendClientMessage(playerid,-1,"*"COL_RED" You must be in a faction to use this command!");
	}
	else return SendClientMessage(playerid,-1,"*"COL_RED" The player you are trying to invite is already in a faction.");
	return 1;
}

CMD:acceptfaction(playerid)
{
	if(pInfo[playerid][IsPlayerInvited] == 1)
	{
		new str[230];
		pInfo[playerid][IsPlayerInvited] = 0;
		pInfo[playerid][IsPlayerInfaction] = 1;
		pInfo[playerid][IsPlayerInfactionID] = pInfo[playerid][IsPlayerInvitedfactionID];
		pInfo[playerid][IsPlayerInvitedfactionID] = 0;
		factions[pInfo[playerid][IsPlayerInfactionID]][factionMembers]++;

		format(str,sizeof(str),"*"COL_YELLOW" Player %s(%i) has joined the faction %s(%i)",PlayerName(playerid), playerid, factions[pInfo[playerid][IsPlayerInfactionID]][factionName], pInfo[playerid][IsPlayerInfactionID]);
		SendMessageToAllfactions(factions[pInfo[playerid][IsPlayerInfactionID]][factionID], str, -1);
	}
	else return SendClientMessage(playerid,-1,"*"COL_RED" You have not been invited to join any factions!");
	return 1;
}


CMD:denyfaction(playerid)
{
	if(pInfo[playerid][IsPlayerInvited] == 1)
	{
		pInfo[playerid][IsPlayerInvited] = 0;
		pInfo[playerid][IsPlayerInfaction] = -1;
		pInfo[playerid][IsPlayerInvitedfactionID] = 0;
		SendClientMessage(playerid,-1,"*"COL_YELLOW" You denied to join the faction!");
	}
	else return SendClientMessage(playerid,-1,"*"COL_RED" You have not been invited to join any factions!");
	return 1;
}

CMD:kickfaction(playerid,params[])
{
	new targetid;
	if(sscanf(params, "u", targetid)) return SendClientMessage(playerid,-1,"*"COL_RED" /kickfaction [playerid]");

	if(pInfo[playerid][IsPlayerInfaction] == 1)
	{
	    if(pInfo[playerid][IsPlayerfactionOwner] == 1)
	    {
			if(pInfo[targetid][IsPlayerInfactionID] == pInfo[playerid][IsPlayerInfactionID])
			{
				new str[180],str2[128];
				format(str,sizeof(str),"*"COL_RED" You were kicked from faction %s(%i)",GetPlayerfactionName(targetid),pInfo[targetid][IsPlayerInfactionID]);
				SendClientMessage(targetid,-1,str);
				format(str2,sizeof(str2),"*"COL_RED" You have kicked %s(%i) from your faction!",PlayerName(targetid),targetid);
				SendClientMessage(playerid,-1,str2);
			    factions[pInfo[targetid][IsPlayerInfactionID]][factionMembers]--;

			    pInfo[targetid][IsPlayerInfaction] = 0;
			    pInfo[targetid][IsPlayerInfactionID] = 0;
			}
			else return SendClientMessage(playerid,-1,"*"COL_RED" That player is not in your faction!");
		}
		else return SendClientMessage(playerid,-1,"*"COL_RED" You must be the faction owner to use this command!");
	}
	else return SendClientMessage(playerid,-1,"*"COL_RED" You must be in a faction to use this command!");
	return 1;
}

CMD:factionfind(playerid,params[])
{
	new targetid;
	if(sscanf(params, "u", targetid)) return SendClientMessage(playerid,-1,"*"COL_RED" /factionfind [playerid]");

	if(pInfo[playerid][IsPlayerInfaction] == 1)
	{
		if(pInfo[targetid][IsPlayerInfactionID] == pInfo[playerid][IsPlayerInfactionID])
		{
			new str[250];
			GetPlayer2DZone(targetid, zonegps, MAX_ZONE_NAME);
			format(stringgps,sizeof(stringgps),"%s", zonegps);
			format(str,sizeof(str),"*"COL_YELLOW" faction member %s(%i) is at %s",PlayerName(targetid),targetid,stringgps);
			SendClientMessage(playerid,-1,str);
		}
		else return SendClientMessage(playerid,-1,"*"COL_RED" The player you are trying to find isn't in your faction!");
	}
	else return SendClientMessage(playerid,-1,"*"COL_RED" You must be in a faction to use this command!");
	return 1;
}

CMD:leavefaction(playerid)
{
	if(pInfo[playerid][IsPlayerInfaction] == 1)
	{
	    new str[180];
	    format(str,sizeof(str),"*"COL_YELLOW" %s(%i) has left the faction!",PlayerName(playerid),playerid);
	    SendMessageToAllfactions(factions[pInfo[playerid][IsPlayerInfactionID]][factionID], str, -1);
	    factions[pInfo[playerid][IsPlayerInfactionID]][factionMembers]--;
	    pInfo[playerid][IsPlayerInfaction] = 0;
	    pInfo[playerid][IsPlayerInfactionID] = 0;
	}
	else return SendClientMessage(playerid,-1,"*"COL_RED" You must be in a faction to use this command!");
	return 1;
}

CMD:destroyfaction(playerid,params[])
{
	new reason[105];
	if(sscanf(params, "s[105]", reason)) return SendClientMessage(playerid,-1,"*"COL_RED" /destroyfaction [reason]");

	if(pInfo[playerid][IsPlayerInfaction] == 1)
	{
	    if(pInfo[playerid][IsPlayerfactionOwner] == 1)
	    {
			new str[24],gname[16],msg[280];

			format(str,sizeof(str),"Destroyed");
			format(gname,sizeof(gname),"Destroyed");
			format(msg,sizeof(msg),"*"COL_YELLOW" %s(%i) has disbanded the faction %s [Reason: %s]",PlayerName(playerid),playerid, GetPlayerfactionName(playerid), reason);
			SendClientMessageToAll(-1,msg);

			factions[pInfo[playerid][IsPlayerInfactionID]][factionOwner] = str;
			factions[pInfo[playerid][IsPlayerInfactionID]][factionName] = gname;
			factions[pInfo[playerid][IsPlayerInfactionID]][factionMembers] = 0;

			foreach(Player,i)
			{
			    if(pInfo[i][IsPlayerInfactionID] == pInfo[playerid][IsPlayerInfactionID])
			    {
    				pInfo[i][IsPlayerInfaction] = 0;
					pInfo[i][IsPlayerInfactionID] = 0;

				}
			}

			pInfo[playerid][IsPlayerInfaction] = 0;
			pInfo[playerid][IsPlayerfactionOwner] = 0;
			pInfo[playerid][IsPlayerInfactionID] = 0;

		}
		else return SendClientMessage(playerid,-1,"*"COL_RED" That player is not in your faction!");
	}
	else return SendClientMessage(playerid,-1,"*"COL_RED" You must be the faction owner to use this command!");
	return 1;
}

CMD:f(playerid,params[])
{
	new adminstring[280];
	if(pInfo[playerid][IsPlayerInfaction] == 1)
	{
	    if(!strlen(params))
	    {
	        SendClientMessage(playerid, -1, "*"COL_GREEN" /f [message]");
	        return 1;
		}
		format(adminstring, sizeof(adminstring), ""COL_LIGHTBLUE"(( [ Faction Chat] %s(%d) "COL_LIGHTBLUE": %s ))",PlayerName(playerid), playerid, params);
		SendMessageToAllfactions(factions[pInfo[playerid][IsPlayerInfactionID]][factionID], adminstring, -1);
	}
	else {
		SendClientMessage(playerid,-1,"*"COL_RED" You need to be in a faction to use this command!");
	}
	return 1;
}


stock ResetVars(playerid)
pInfo[playerid][IsPlayerInfaction] = 0;
pInfo[playerid][IsPlayerInfactionID] = 0;


stock DisconnectVars(playerid)
{
 	SaveInventory(playerid);
   	if(IsPlayerAttachedObjectSlotUsed(playerid, 1)) RemovePlayerAttachedObject(playerid, 0);

if(pInfo[playerid][IsPlayerfactionOwner] == 1)
    {
		new str[24],gname[16];

		format(str,sizeof(str),"Destroyed");
		format(gname,sizeof(gname),"Destroyed");

		factions[pInfo[playerid][IsPlayerInfactionID]][factionID] = 0;
		factions[pInfo[playerid][IsPlayerInfactionID]][factionOwner] = str;
		factions[pInfo[playerid][IsPlayerInfactionID]][factionName] = gname;
		factions[pInfo[playerid][IsPlayerInfactionID]][factionMembers] = 0;

		foreach(Player,i)
		{
			if(pInfo[i][IsPlayerInfactionID] == pInfo[playerid][IsPlayerInfactionID])
			{
				pInfo[i][IsPlayerInfaction] = 0;
				pInfo[i][IsPlayerInfactionID] = 0;

			}
		}

		pInfo[playerid][IsPlayerInfaction] = 0;
		pInfo[playerid][IsPlayerfactionOwner] = 0;
		pInfo[playerid][IsPlayerInfactionID] = 0;
	}
    return 1;
}
How can i Add to mysql so a faction, it members and it leader would be saved ? Thank youu

I will create a new table named FACTIONS and columns will be named " Leader" , "FactionID", "Members (playername) right?


(you can explain, and i will ask more help if I can't make it)
Reply
#2

Not quite correct. If a player can be a member of only ONE faction at a time then you need a column (factionId) in your player table that is a reference to the faction table (id column). The 'leader' column in the faction table goes in the opposite direction and is a reference to the player table.

If a player can be a member of multiple factions at the same time, consult my association table tutorial, linked in my signature.
Reply
#3

Quote:
Originally Posted by Vince
View Post
Not quite correct. If a player can be a member of only ONE faction at a time then you need a column (factionId) in your player table that is a reference to the faction table (id column). The 'leader' column in the faction table goes in the opposite direction and is a reference to the player table.

If a player can be a member of multiple factions at the same time, consult my association table tutorial, linked in my signature.

Only one faction per member & leader.

And how can I add to pawno the new table and the code? where and how


And how to save factionID's at /makefaction?
Reply
#4

help
Reply
#5

bump...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)