public loadtrees()
{
print("Loading trees");
for(new g = 1; g < MAX_TREES; g++)
{
new LoadString[256];
format(LoadString, sizeof(LoadString), "/Trees/%d.dini.save", g);
if(dini_Exists(LoadString))
{
treeData[g][tID] = g;
treeData[g][tX] = dini_Float(LoadString,"tX");
treeData[g][tY] = dini_Float(LoadString,"tY");
treeData[g][tZ] = dini_Float(LoadString,"tZ");
treeData[g][tObject] = CreateObject(617, treeData[g][tX], treeData[g][tY], treeData[g][tZ], 0.0000, 0.0000, 0.0000); // tree
treeData[g][woodReady] = false;
treeData[g][tHealth] = 100;
new string2[80];
format(string2, sizeof(string2), "{ffff00}Tree\n/cuttree\nHealth: %i", treeData[g][tHealth]);
treeData[g][tLabel] = Create3DTextLabel(string2, COLOR_YELLOW, treeData[g][tX], treeData[g][tY], treeData[g][tZ] + 0.2 + 3.1117, 7.5, 0, 0);
treeData[g][tStatus] = true;
}
}
return 1;
}
forward loadtrees();
public loadtrees()
{
print("Loading trees");
for(new g = 1; g < MAX_TREES; g++)
{
new LoadString[256];
format(LoadString, sizeof(LoadString), "/Trees/%d.dini.save", g);
if(dini_Exists(LoadString))
{
treeData[g][tID] = g;
treeData[g][tX] = dini_Float(LoadString,"tX");
treeData[g][tY] = dini_Float(LoadString,"tY");
treeData[g][tZ] = dini_Float(LoadString,"tZ");
treeData[g][tObject] = CreateObject(617, treeData[g][tX], treeData[g][tY], treeData[g][tZ], 0.0000, 0.0000, 0.0000); // tree
treeData[g][woodReady] = false;
treeData[g][tHealth] = 100;
new string2[40];
format(string2, sizeof(string2), "{ffff00}Tree\n/cuttree\nHealth: %i", treeData[g][tHealth]);
treeData[g][tLabel] = Create3DTextLabel(string2, COLOR_YELLOW, treeData[g][tX], treeData[g][tY], treeData[g][tZ] + 0.2 + 3.1117, 7.5, 0, 0);
treeData[g][tStatus] = true;
}
}
new str[40];
format(str, sizeof(str), "{ffff00}Tree\n/cuttree\nHealth: %i", treeData[1][tHealth]);
treeData[1][tLabel] = Create3DTextLabel(str, COLOR_YELLOW, treeData[1][tX], treeData[1][tY], treeData[1][tZ] + 0.2 + 3.1117, 7.5, 0, 0);
return 1;
}
for(new g = 1; g < MAX_TREES; g++) |
COMMAND:createtree(playerid, params[])
{
if(pInfo[playerid][Level] >= 4)
{
new Float: x, Float: y, Float: z;
GetPlayerPos(playerid, x, y, z);
new treeid = freeTreeID();
new string[260];
format(string, sizeof(string), "/Trees/%d.dini.save", treeid);
if(!dini_Exists(string))
{
treeData[treeid][tX] = x;
treeData[treeid][tY] = y;
treeData[treeid][tZ] = z - 3.1117; // remove this value to fix object bug
treeData[treeid][tObject] = CreateObject(617, treeData[treeid][tX], treeData[treeid][tY], treeData[treeid][tZ], 0.0000, 0.0000, 0.0000); // tree
treeData[treeid][woodReady] = false;
treeData[treeid][tHealth] = 100;
new string2[80];
format(string2, sizeof(string2), "{ffff00}Tree\n/cuttree\nHealth: %i", treeData[treeid][tHealth]);
treeData[treeid][tLabel] = Create3DTextLabel(string2, COLOR_YELLOW, treeData[treeid][tX], treeData[treeid][tY], treeData[treeid][tZ] + (0.2 + 3.1117) , 7.5, 0, 0);
treeData[treeid][tStatus] = true;
dini_Create(string);
dini_FloatSet(string, "tX", x);
dini_FloatSet(string, "tY", y);
dini_FloatSet(string, "tZ", z - 3.1117);
SSM(playerid, "You have successfully created a tree.");
}
}
else return 0;
return 1;
}
stock freeTreeID()
{
new Trees[64];
for(new g = 1; g < MAX_TREES; g++)
{
format(Trees, sizeof(Trees), "/Trees/%d.dini.save", g);
if(!dini_Exists(Trees)) return g;
}
return 1;
}
#include <Dini2>
//will keep your ids in correct order, finds first empty id slot and so are file ids also correct
#include <YSI_Data\y_iterate>
#define max_trees 100
new Iterator:fTrees<max_trees>;
treeFile(i){
new s[50];
format(s,50,"Trees/%d.ini",i);
return s;
}
treeExsists(i){
return dini_Exists(treeFile(i));
}
loadTrees(){
for(new i; i < max_trees; i++){
if(!treeExsists(i))continue;
Iter_Add(fTrees,i);
//loading data
}
return 1;
}
//other systems
CMD:createtree(playerid, params[])
{
if(pInfo[playerid][Level] < 4)return 1;
new i=Iter_Free(fTrees);
if(i==INVALID_ITERATOR_SLOT)return 1;
Iter_Add(fTrees,i);
new s[50];
strmid(s,treeFile(i),0,50,50);
dini_Create(s);
dini_FloatSet(s, "tX", 0.0);
dini_FloatSet(s, "tY", 0.0);
dini_FloatSet(s, "tZ", 0.0);
dini_Timeout(s);
return 1;
}