22.01.2019, 16:03
While running the new lumberjack job i scripted, I found the following error
[17:25:08] [debug] Run time error 4: "Array index out of bounds"
[17:25:08] [debug] Accessing element at index 10 past array upper bound 9
- The server sometimes lag because of this error ( im not sure ). I did not find any other ingame bugs because of this error.
- Main functions i'm using:
Thanks for helping
[17:25:08] [debug] Run time error 4: "Array index out of bounds"
[17:25:08] [debug] Accessing element at index 10 past array upper bound 9
- The server sometimes lag because of this error ( im not sure ). I did not find any other ingame bugs because of this error.
PHP Code:
public OnGameModeInit()
{
// Lumberjack
loadtrees();
return 1;
}
PHP Code:
#define MAX_TREES 10
enum treeinfo
{
tID,
Float: tX,
Float: tY,
Float: tZ,
tHealth,
bool:tStatus,
bool:woodReady,
tObject,
Text3D:tLabel,
tWood,
Text3D:woodLabel,
tTimer
}
new treeData[MAX_TREES][treeinfo];
PHP Code:
forward loadtrees();
public loadtrees()
{
print("Loading trees");
for(new g = 0; 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;
}
GetNearestTree(playerid)
{
new treeid = -1;
new k=0;
for(new i=0; i<=MAX_TREES;i++)
{
if(k==0)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, treeData[i][tX], treeData[i][tY], treeData[i][tZ] + 3.1117 ))
{
treeData[i][tID] = i;
k++;
treeid = i;
}
}
else break;
}
return treeid;
}
forward destroytrees();
public destroytrees()
{
print("unloading trees");
for(new g = 0; g <= MAX_TREES; g++)
{
new UnloadString[256];
format(UnloadString, sizeof(UnloadString), "/Trees/%d.dini.save", g);
if(dini_Exists(UnloadString))
{
if(treeData[g][tStatus])
{
Delete3DTextLabel( treeData[g][tLabel] );
DestroyObject( treeData[g][tObject] );
}
else
{
if(treeData[g][woodReady])
{
Delete3DTextLabel( treeData[g][woodLabel] );
DestroyObject( treeData[g][tWood] );
}
}
}
}
}
stock freeTreeID()
{
new Trees[64];
for(new g = 0; g <= MAX_TREES; g++)
{
format(Trees, sizeof(Trees), "/Trees/%d.dini.save", g);
if(!dini_Exists(Trees)) return g;
}
return 1;
}