10.03.2015, 16:06
It's a good idea but I don't like the design here are my reasons.
1.) There is no saving of objectid's which means you lose all reference of objects!
2.) Too many parameters in the function.
3.) There should be pools of objects this will fix the first two issues.
You need to think dynamic design when it comes to SAMP it's almost always the same refer to this link and specifically the hearts concept.
http://forum.sa-mp.com/showpost.php?...4&postcount=14
So I will just give you an idea here none of this code has been tested.
1.) There is no saving of objectid's which means you lose all reference of objects!
2.) Too many parameters in the function.
3.) There should be pools of objects this will fix the first two issues.
You need to think dynamic design when it comes to SAMP it's almost always the same refer to this link and specifically the hearts concept.
http://forum.sa-mp.com/showpost.php?...4&postcount=14
So I will just give you an idea here none of this code has been tested.
pawn Код:
#define OBJ_DBG_MSG
#define MAX_SURFACE_GROUPS 10
#define MAX_SURFACE_OBJECTS 200
enum OBJECTSURFACEGROUPINFO
{
// Parameter settings
Float:gSI_object_model,
Float:gSI_x_off,
Float:gSI_y_off,
Float:gSI_height,
Float:gSI_x_start,
Float:gSI_y_start,
Float:gSI_x_end,
Float:gSI_y_end,
gSI_world,
gSI_interior,
gSI_player,
Float:gSI_d_stream,
Float:gSI_d_draw,
// Saved object data
gSI_ObjectID[MAX_SURFACE_OBJECTS],
Float:gSI_OX[MAX_SURFACE_OBJECTS],
Float:gSI_OY[MAX_SURFACE_OBJECTS],
// Internal data
bool:gSI_Used,
gSI_Count,
}
static g_ObjectSurfaceGroups[MAX_SURFACE_GROUPS][OBJECTSURFACEGROUPINFO];
stock CreateObjectSurface(object_model, Float:x_off, Float:y_off, Float:height, Float:x_start, Float:y_start, Float:x_end = 0.0, Float:y_end = 0.0, Float:x_rot = 0.0, Float:y_rot = 0.0, Float:z_rot = 0.0, world = -1, interior = -1, player = -1, Float:d_stream = 200.0, Float:d_draw = 0.0)
{
for(new i = 0; i < MAX_SURFACE_GROUPS; i++)
{
if(g_ObjectSurfaceGroups[i][gSI_Used] == false)
{
if(!x_end)
{
if(x_start < 0.0) x_end = floatabs(x_start);
else x_end = -x_start;
}
if(!y_end)
{
if(y_start < 0.0) y_end = floatabs(y_start);
else y_end = -y_start;
}
if(x_start == x_end || y_start == y_end)
{
printf("Error at \"CreateObjectSurface\" function for model %i - one of the starting and ending positions (X: %0.2f, Y: %0.2f) is the same.",
object_model,
x_start,
y_start
);
return -1;
}
// Save all parameter data
g_ObjectSurfaceGroups[i][gSI_object_model] = object_model;
g_ObjectSurfaceGroups[i][gSI_x_off] = x_off;
g_ObjectSurfaceGroups[i][gSI_y_off] = y_off;
g_ObjectSurfaceGroups[i][gSI_height] = height;
g_ObjectSurfaceGroups[i][gSI_x_start] = x_start;
g_ObjectSurfaceGroups[i][gSI_y_start] = y_start;
g_ObjectSurfaceGroups[i][gSI_x_end] = x_end;
g_ObjectSurfaceGroups[i][gSI_y_end] = y_end;
g_ObjectSurfaceGroups[i][gSI_world] = world;
g_ObjectSurfaceGroups[i][gSI_interior] = interior;
g_ObjectSurfaceGroups[i][gSI_player] = player;
g_ObjectSurfaceGroups[i][gSI_d_stream] = d_stream;
g_ObjectSurfaceGroups[i][gSI_d_draw] = d_draw;
g_ObjectSurfaceGroups[i][gSI_Used] = true;
new
Float:coord[2], bool:calculate[2], loop[2], object;
if(x_start < 0.0)
{
// -3000.0, -4000.0 -> 1000.0
// -4000.0, -3000.0 -> 1000.0
if(x_end < 0.0)
{
if(x_start > x_end)
calculate[0] = true;
coord[0] = floatabs(x_start + floatabs(x_end));
}
// -3000.0, 4000.0 -> 7000.0
else
coord[0] = floatabs(x_start) + x_end;
}
else
{
// 3000.0, -4000.0 -> 7000.0
if(x_end < 0.0)
{
calculate[0] = true;
coord[0] = x_start + floatabs(x_end);
}
// 3000.0, 4000.0 -> 1000.0
// 4000.0, 3000.0 -> 1000.0
else
{
if(x_start > x_end)
calculate[0] = true;
coord[0] = floatabs(x_start - x_end);
}
}
if(y_start < 0.0)
{
// -3000.0, -4000.0 -> 1000.0
// -4000.0, -3000.0 -> 1000.0
if(y_end < 0.0)
{
if(y_start > y_end)
calculate[1] = true;
coord[1] = floatabs(y_start + floatabs(y_end));
}
// -3000.0, 4000.0 -> 7000.0
else
coord[1] = floatabs(y_start) + y_end;
}
else
{
// 3000.0, -4000.0 -> 7000.0
if(y_end < 0.0)
{
calculate[1] = true;
coord[1] = y_start + floatabs(y_end);
}
// 3000.0, 4000.0 -> 1000.0
// 4000.0, 3000.0 -> 1000.0
else
{
if(y_start > y_end)
calculate[1] = true;
coord[1] = floatabs(y_start - y_end);
}
}
loop[0] = floatround(coord[0] / x_off, floatround_ceil);
loop[1] = floatround(coord[1] / y_off, floatround_ceil);
g_Count = 0;
for(new a = 0; a < loop[0]; a++)
{
for(new b = 0; b < loop[1]; b++)
{
if(calculate[0]) coord[0] = x_start - (x_off * a);
else coord[0] = x_start + (x_off * a);
if(calculate[1]) coord[1] = y_start - (y_off * b);
else coord[1] = y_start + (y_off * b);
// Save object id
g_ObjectSurfaceGroups[i][gSI_ObjectID][g_Count] = CreateDynamicObject(
object_model,
coord[0],
coord[1],
height,
x_rot,
y_rot,
z_rot,
world,
interior,
player,
d_stream,
d_draw
);
// Save position data
g_ObjectSurfaceGroups[i][gSI_OX][g_Count] = coord[0];
g_ObjectSurfaceGroups[i][gSI_OY][g_Count] = coord[1];
g_Count++;
}
}
#if defined OBJ_DBG_MSG
printf("Created %i objects at \"CreateObjectSurface\" function for model %i.",
g_Count,
object_model
);
#endif
g_ObjectSurfaceGroups[i][gSI_Count] = g_Count;
// Return surface group index
return i;
}
}
printf("ERROR::CreateObjectSurface()::Too many surfaces");
return -1;
}
stock SetObjectSurfaceMaterial(index, m_index = 0, txd_model = 0, txd_name[] = "", texture_name[] = "", m_color = 0)
{
if(index < 0 || index >= MAX_SURFACE_GROUPS)
{
printf("ERROR::SetObjectSurfaceMaterial()::Index out of bounds");
return -1;
}
else
{
if(g_ObjectSurfaceGroups[index][gSI_Used])
{
for(new i = 0; i < g_ObjectSurfaceGroups[index][gSI_Count]; i++)
{
SetDynamicObjectMaterial(object, m_index, txd_model, txd_name, texture_name, m_color);
}
g_ObjectSurfaceGroups[index][gSI_Used] = false;
return 1;
}
}
printf("ERROR::SetObjectSurfaceMaterial()::Index does not exist");
return -1;
}
stock DestroyObjectSurface(index)
{
if(index < 0 || index >= MAX_SURFACE_GROUPS)
{
printf("ERROR::CreateObjectSurface()::Index out of bounds");
return -1;
}
else
{
if(g_ObjectSurfaceGroups[index][gSI_Used])
{
for(new i = 0; i < g_ObjectSurfaceGroups[index][gSI_Count]; i++)
{
DestroyDynamicObject(g_ObjectSurfaceGroups[index][i];
}
g_ObjectSurfaceGroups[index][gSI_Used] = false;
return 1;
}
}
printf("ERROR::CreateObjectSurface()::Index does not exist");
return -1;
}