23.07.2016, 11:29
Hello i tried saving some tree objects in .ini file using YINI. here is the code:
IDK why its not working. i followed a Tutorial of YINI to do it but it didnt work. when i create a tree object, it is creating a file named 0.ini in Trees folder as i wanted but the file is blank. so when i reload my fs, everything gets reset. also a file with some number like 2135313.ini gets created after a reload.
Also i want that in TotalTrees, number of Trees loaded gets shown not 1-MAX_TREES.
Any Advice for me please?
PHP код:
forward SaveTrees(id);
public SaveTrees(id)
{
new inifile[256];
format(inifile, sizeof(inifile), "Trees/%d.ini", id);
new INI:tree = INI_Open(inifile);
INI_WriteInt(tree, "Tree ID", TreeInfo[id][TreeID]);
INI_WriteFloat(tree, "Pos_X", TreeInfo[id][Tree_X]);
INI_WriteFloat(tree, "Pos_Y", TreeInfo[id][Tree_Y]);
INI_WriteFloat(tree, "Pos_Z", TreeInfo[id][Tree_Z]);
INI_WriteFloat(tree, "Rot_X", TreeInfo[id][Tree_RX]);
INI_WriteFloat(tree, "Rot_Y", TreeInfo[id][Tree_RY]);
INI_WriteFloat(tree, "Rot_Z", TreeInfo[id][Tree_RZ]);
INI_WriteInt(tree, "Logs\n", TreeInfo[id][TreeLogs]);
printf("Lumberjack Trees Saved");
return 1;
}
forward LoadTrees();
public LoadTrees()
{
new TotalTrees = 0;
for(new t=0; t < MAX_TREES; t++)
{
new string[256];
format(string,sizeof(string),"Trees/%d.ini",t);
if(fexist(string))
{
TreeInfo[t][treeObjID] = CreateDynamicObject(657, TreeInfo[t][Tree_X], TreeInfo[t][Tree_Y], TreeInfo[t][Tree_Z], TreeInfo[t][Tree_RX], TreeInfo[t][Tree_RY], TreeInfo[t][Tree_RZ]);
new label[96];
if(TreeInfo[t][TreeLogs] > 0)
{
format(label, sizeof(label), "Tree \n Use {0080FF}/takelogfromtree {E74C3C}to Cut down this tree to get Woods.\nLogs Remaining:{80FF80} %s", TreeInfo[t][TreeLogs]);
UpdateDynamic3DTextLabelText(TreeInfo[t][treeLabel], 0xE74C3CFF, label);
}
else
{
TreeInfo[t][treeTimer] = SetTimerEx("RespawnTree", 1000, true, "i", t);
format(label, sizeof(label), "Growing Tree\n\n{FFFFFF}%s", ConvertToMinutes(TreeInfo[t][TreeTime]));
UpdateDynamic3DTextLabelText(TreeInfo[t][treeLabel], 0xE74C3CFF, label);
}
}
TotalTrees = t;
}
//INI_Close("Trees.ini");
printf("No of Trees Loaded from Database: %d", TotalTrees);
return 1;
}
Also i want that in TotalTrees, number of Trees loaded gets shown not 1-MAX_TREES.
Any Advice for me please?