Group System
#1

How to make Group System saving with Dini & dudb ?

I'v /groupcreate cmds

CMD :
Код:
COMMAND:groupcreate(playerid, params[])
{
  	if(group[playerid][gid] != -1) return SendClientMessage(playerid, 0xFF0000, "Leave your group with {FFFFFF}/groupleave{FF0000} before creating a new one!");
  	if(strlen(params) > 49 || strlen(params) < 3) return SendClientMessage(playerid, 0xFF0000, "Usage: {FFFFFF}/groupcreate{FF0000} (Group name 3-50 characters)!");
	if(IsGroupTaken(params)) return SendClientMessage(playerid, 0xFF0000, "Group name is already in use!");
	CreateGroup(params, playerid);
  	return 1;
}
Stock CreateGroup :
Код:
stock CreateGroup(grpname[], owner)
{
	new slotid = FindNextSlot();
	groupinfo[slotid][leader] = owner;
	format(groupinfo[slotid][grname], 75, "%s", grpname);
	groupinfo[slotid][active] = 1;
	group[owner][gid] = slotid;
	group[owner][order] = 1;
	new string[120];
	format(string, sizeof(string), "You have created the group %s(ID:%d)", grpname, slotid);
	SendClientMessage(owner, 0xFFCC66, string);
	return slotid;
}
How to make it Saving when Server Down / Restart ?

*SorryForMyBadEnglish :P , Rewards : +REP :P
Reply
#2

show CreateGroup function/stock
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
show CreateGroup function/stock
Added
Reply
#4

Use Y_INI. Its much faster than dini
pawn Код:
#define PATH "/Group/%d.ini" //Path where your Group will be saved

stock CreateGroup(grpname[], owner)
{
    new slotid = FindNextSlot();
    groupinfo[slotid][leader] = owner;
    format(groupinfo[slotid][grname], 75, "%s", grpname);
    groupinfo[slotid][active] = 1;
    group[owner][gid] = slotid;
    group[owner][order] = 1;
    new string[120];
    format(string, sizeof(string), "You have created the group %s(ID:%d)", grpname, slotid);
    SendClientMessage(owner, 0xFFCC66, string);

    new file[40];
    format(file, sizeof(file), PATH, id);
    new INI:File = INI_Open(file); //Open the file
    INI_SetTag(File, "data"); //Write tag
    INI_WriteInt(File, "GroupID", group[owner][gid]); //Write data
    INI_WriteString(File, "GroupName", groupinfo[slotid][grname]); //Write data
    //Write another data, you know what to do (Func: INI_WriteString, INI_WriteInt, INI_WriteFloat)
    INI_Close(File); //Close current opened file after you done writing the data
    return slotid;
}

forward LoadGroup_data(playerid, name[], value[]);
public LoadGroup_data(playerid, name[], valie[])
{
    INI_Int("GroupID", GChatInfo[playerid][gid]); //Store the data to a variable
    //Store another data (Func: INI_Int, INI_String, INI_Float)
    return 1;
}

forward SaveGroup(playerid);
public SaveGroup(playerid)
{
    new file[40];
    format(file, sizeof(file), PATH, id);
    new INI:File = INI_Open(file); //Open the file
    INI_SetTag(File, "data"); //Write tag
    INI_WriteInt(File, "GroupID", GChatInfo[playerid][Exist]); //Write data
    //Write another data, you know what to do (Func: INI_WriteString, INI_WriteInt, INI_WriteFloat)
    INI_Close(File); //Close current opened file after you done writing data
    return 1;
}

public OnPlayerConnect(playerid)
{
    new string[40];
    format(string, sizeof(string), PATH, i);
    INI_ParseFile(string, "LoadGC_%s", .bExtra = true, .extra = playerid); //Call function LoadGroup_data and load playerid's Group
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    SaveGroup(playerid);
    return 1;
}
Reply
#5

Quote:
Originally Posted by RenovanZ
Посмотреть сообщение
Use Y_INI. Its much faster than dini
pawn Код:
#define PATH "/Group/%d.ini" //Path where your Group will be saved

stock CreateGroup(grpname[], owner)
{
    new slotid = FindNextSlot();
    groupinfo[slotid][leader] = owner;
    format(groupinfo[slotid][grname], 75, "%s", grpname);
    groupinfo[slotid][active] = 1;
    group[owner][gid] = slotid;
    group[owner][order] = 1;
    new string[120];
    format(string, sizeof(string), "You have created the group %s(ID:%d)", grpname, slotid);
    SendClientMessage(owner, 0xFFCC66, string);

    new file[40];
    format(file, sizeof(file), PATH, id);
    new INI:File = INI_Open(file); //Open the file
    INI_SetTag(File, "data"); //Write tag
    INI_WriteInt(File, "GroupID", group[owner][gid]); //Write data
    INI_WriteString(File, "GroupName", groupinfo[slotid][grname]); //Write data
    //Write another data, you know what to do (Func: INI_WriteString, INI_WriteInt, INI_WriteFloat)
    INI_Close(File); //Close current opened file after you done writing the data
    return slotid;
}

forward LoadGroup_data(playerid, name[], value[]);
public LoadGroup_data(playerid, name[], valie[])
{
    INI_Int("GroupID", GChatInfo[playerid][gid]); //Store the data to a variable
    //Store another data (Func: INI_Int, INI_String, INI_Float)
    return 1;
}

forward SaveGroup(playerid);
public SaveGroup(playerid)
{
    new file[40];
    format(file, sizeof(file), PATH, id);
    new INI:File = INI_Open(file); //Open the file
    INI_SetTag(File, "data"); //Write tag
    INI_WriteInt(File, "GroupID", GChatInfo[playerid][Exist]); //Write data
    //Write another data, you know what to do (Func: INI_WriteString, INI_WriteInt, INI_WriteFloat)
    INI_Close(File); //Close current opened file after you done writing data
    return 1;
}

public OnPlayerConnect(playerid)
{
    new string[40];
    format(string, sizeof(string), PATH, i);
    INI_ParseFile(string, "LoadGC_%s", .bExtra = true, .extra = playerid); //Call function LoadGroup_data and load playerid's Group
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    SaveGroup(playerid);
    return 1;
}
but i'm using Dini
Reply
#6

Help me please
Reply


Forum Jump:


Users browsing this thread: