|
Member
|

11-07-2013
, 12:07
loading bug(updated)
|
#1
|
hi when i try to make moving blocks save it saves everything but when i reload the map moving blocks is not saved what could be the problem?
Code:
SaveBlocks(id)
{
if ( !g_admin[id] )
{
console_print(id, "Error: You dont have access to that command!");
return PLUGIN_HANDLED;
}
new ent;
new file;
new data[256];
new block_count;
new tele_count;
new light_count;
new block_type;
new size;
new property1[13], property2[5], property3[5], property4[5];
new tele;
new Float:origin[3];
new Float:angles[3];
new Float:tele_start[3];
new Float:tele_end[3];
new Float:max_size;
new Float:size_max[3];
new Float:RGB[3], Float:RenderAmt, RenderFX, RenderMode;
file = fopen(g_file, "wt");
block_count = 0;
tele_count = 0;
ent = -1;
while ( ( ent = find_ent_by_class(ent, g_block_classname) ) )
{
block_type = entity_get_int(ent, EV_INT_body);
entity_get_vector(ent, EV_VEC_angles, angles);
entity_get_vector(ent, EV_VEC_maxs, size_max);
// Moving blocks
if (g_fVelocityFactor[ent])
origin = g_vOrigin[ent];
else
entity_get_vector(ent, EV_VEC_origin, origin);
//rendering
if(task_exists(ent + TASK_SOLID))
{
RenderMode = pev(ent, pev_euser2);
RenderFX = pev(ent, pev_euser1);
pev( ent, pev_speed, RenderAmt );
pev( ent, pev_oldorigin, RGB );
}
else
{
RenderMode = entity_get_int(ent, EV_INT_rendermode);
RenderFX = entity_get_int(ent, EV_INT_renderfx);
pev( ent, pev_renderamt, RenderAmt );
pev( ent, pev_rendercolor, RGB );
}
GetProperty(ent, 1, property1);
GetProperty(ent, 2, property2);
GetProperty(ent, 3, property3);
GetProperty(ent, 4, property4);
if ( !property1[0] ) copy(property1, charsmax(property1), "/");
if ( !property2[0] ) copy(property2, charsmax(property2), "/");
if ( !property3[0] ) copy(property3, charsmax(property3), "/");
if ( !property4[0] ) copy(property4, charsmax(property4), "/");
max_size = size_max[0] + size_max[1] + size_max[2];
if ( max_size > 128.0 ) size = LARGE;
else if ( max_size > 64.0 ) size = NORMAL;
else if ( max_size > 32.0 ) size = POLE;
else size = TINY;
formatex(data, charsmax(data), "%c %f %f %f %f %f %f %d %s %s %s %s %f %f %f %f %d %d %f %f %f %f %f^n",\
g_block_save_ids[block_type], origin[0], origin[1], origin[2], angles[0],angles[1],angles[2],size,property1,property2,property3, property4,
RGB[0],RGB[1],RGB[2],RenderAmt,RenderFX,RenderMode, g_fVelocityFactor[ent], g_fStopDelay[ent], g_vDestination[ent][0], g_vDestination[ent][1], g_vDestination[ent][2]);
console_print(id, "Saving: %s", data);
++block_count;
}
ent = -1;
while ( ( ent = find_ent_by_class(ent, g_destination_classname) ) )
{
tele = entity_get_int(ent, EV_INT_iuser1);
if ( tele )
{
entity_get_vector(tele, EV_VEC_origin, tele_start);
entity_get_vector(ent, EV_VEC_origin, tele_end);
formatex(data, charsmax(data), "* %f %f %f %f %f %f^n",\
tele_start[0],\
tele_start[1],\
tele_start[2],\
tele_end[0],\
tele_end[1],\
tele_end[2]
);
fputs(file, data);
++tele_count;
}
}
ent = -1;
while ( ( ent = find_ent_by_class(ent, g_light_classname) ) )
{
entity_get_vector(ent, EV_VEC_origin, origin);
GetProperty(ent, 1, property1);
GetProperty(ent, 2, property2);
GetProperty(ent, 3, property3);
GetProperty(ent, 4, property4);
formatex(data, charsmax(data), "! %f %f %f / / / / %s %s %s %s^n",\
origin[0],\
origin[1],\
origin[2],\
property1,\
property2,\
property3,\
property4
);
fputs(file, data);
++light_count;
}
static name[32];
get_user_name(id, name, charsmax(name));
for ( new i = 1; i <= g_max_players; ++i )
{
if ( g_connected[i]
&& ( g_admin[i] || g_gived_access[i] ) )
{
BCM_Print(i, "^1%s^3 Saved^1 %d block%s^3,^1 %d teleport%s^3 and^1 %d Light%s^3! Total entities in map:^1 %d", name, block_count, block_count == 1 ? g_blank : "s", tele_count, tele_count == 1 ? g_blank : "s", light_count, light_count == 1 ? g_blank : "s", entity_count());
}
}
fclose(file);
return PLUGIN_HANDLED;
}
Code:
LoadBlocks(id)
{
if ( id != 0 && !g_admin[id] )
{
console_print(id, "Error: You dont have access to that command!");
return PLUGIN_HANDLED;
}
else if ( !file_exists(g_file)
&& 1 <= id <= g_max_players )
{
BCM_Print(id, "Error: Couldn't find file:^1 %s", g_file);
return PLUGIN_HANDLED;
}
if ( 1 <= id <= g_max_players )
{
DeleteAll(id, false);
}
new file;
new data[256];
new block_count;
new tele_count;
new light_count;
new type[2];
new block_size[17];
new origin_x[17];
new origin_y[17];
new origin_z[17];
new angel_x[17];
new angel_y[17];
new angel_z[17];
new block_type;
new axis;
new size;
new property1[13], property2[5], property3[5], property4[5];
new Float:origin[3];
new Float:angles[3];
new CreatedEnt;
//rendering
new szRGB[3][17], szRenderFX[17], szRenderMode[17], szRenderAmt[17];
new Float:RGB[3], Float:RenderAmt, RenderFX, RenderMode;
// Moving blocks
new sVelocityFactor[17], sStopDelay[17], sDest_x[17], sDest_y[17], sDest_z[17];
file = fopen(g_file, "rt");
block_count = 0;
tele_count = 0;
while ( !feof(file) )
{
type = g_blank;
fgets(file, data, charsmax(data));
parse(data, type, charsmax(type), origin_x, charsmax(origin_x), origin_y, charsmax(origin_y), origin_z, charsmax(origin_z), angel_x, charsmax(angel_x), angel_y, charsmax(angel_y), angel_z, charsmax(angel_z),
block_size, charsmax(block_size), property1, charsmax(property1), property2, charsmax(property2), property3, charsmax(property3), property4, charsmax(property4), szRGB[0], 16,szRGB[1], 16, szRGB[2], 16,
szRenderAmt, 16, szRenderFX, 16, szRenderMode, 16, sVelocityFactor, charsmax(sVelocityFactor), sStopDelay, charsmax(sStopDelay), sDest_x, charsmax(sDest_x), sDest_y, charsmax(sDest_y), sDest_z, charsmax(sDest_z));
origin[0] = str_to_float(origin_x);
origin[1] = str_to_float(origin_y);
origin[2] = str_to_float(origin_z);
angles[0] = str_to_float(angel_x);
angles[1] = str_to_float(angel_y);
angles[2] = str_to_float(angel_z);
size = str_to_num(block_size);
RGB[0] = str_to_float(szRGB[0]);
RGB[1] = str_to_float(szRGB[1]);
RGB[2] = str_to_float(szRGB[2]);
RenderAmt = str_to_float(szRenderAmt);
RenderFX = str_to_num(szRenderFX);
RenderMode = str_to_num(szRenderMode);
if ( strlen(type) > 0 )
{
if ( type[0] != '*' )
{
if ( angles[0] == 90.0 && angles[1] == 0.0 && angles[2] == 0.0 )
{
axis = X;
}
else if ( angles[0] == 90.0 && angles[1] == 0.0 && angles[2] == 90.0 )
{
axis = Y;
}
else
{
axis = Z;
}
}
switch ( type[0] )
{
case 'A': block_type = PLATFORM;
case 'B': block_type = BUNNYHOP;
case 'C': block_type = DAMAGE;
case 'D': block_type = HEALER;
case 'E': block_type = NO_FALL_DAMAGE;
case 'F': block_type = ICE;
case 'G': block_type = TRAMPOLINE;
case 'H': block_type = SPEED_BOOST;
case 'I': block_type = DEATH;
case 'J': block_type = HONEY;
case 'K': block_type = CT_BARRIER;
case 'L': block_type = T_BARRIER;
case 'M': block_type = GLASS;
case 'O': block_type = DELAYED_BUNNYHOP;
case 'P': block_type = INVINCIBILITY;
case 'Q': block_type = STEALTH;
case 'R': block_type = BOOTS_OF_SPEED;
case 'S': block_type = CAMOUFLAGE;
case 'T': block_type = WEAPON;
case 'U': block_type = SPAMDUCK;
case 'V': block_type = GRENADES;
case 'X': block_type = MUSIC;
case 'Y': block_type = HE;
case 'Z': block_type = SG;
case 'a': block_type = FLASH;
case 'b': block_type = CARPET;
case 'c': block_type = EURO;
case '*':
{
CreateTeleport(0, TELEPORT_START, origin);
CreateTeleport(0, TELEPORT_DESTINATION, angles);
++tele_count;
}
case '!':
{
CreateLight(origin, property1, property2, property3, property4);
++light_count;
}
}
if ( type[0] != '*' && type[0] != '!' )
{
CreatedEnt = CreateBlock(0, block_type, origin, axis, size, property1, property2, property3, property4);
set_pev(CreatedEnt, pev_renderfx, RenderFX);
set_pev(CreatedEnt, pev_rendermode, RenderMode);
set_pev(CreatedEnt, pev_rendercolor, RGB);
set_pev(CreatedEnt, pev_renderamt, RenderAmt);
client_print(id, 3, "woef");
if (str_to_float(sVelocityFactor))
{
g_vOrigin[CreatedEnt] = origin;
g_fDelayEnd[CreatedEnt] = 0.0;
set_pev(CreatedEnt, pev_movetype, MOVETYPE_FLY);
g_fStopDelay[CreatedEnt] = str_to_float(sStopDelay);
g_fVelocityFactor[CreatedEnt] = str_to_float(sVelocityFactor);
g_vDestination[CreatedEnt][0] = str_to_float(sDest_x);
g_vDestination[CreatedEnt][1] = str_to_float(sDest_y);
g_vDestination[CreatedEnt][2] = str_to_float(sDest_z);
for (new i = 0; i < 3; i++)
g_vVelocity[CreatedEnt][i] = g_vDestination[CreatedEnt][i] - g_vOrigin[CreatedEnt][i];
// Unit vector * velocity
new Float:fFactor = (1.0 / vector_length(g_vVelocity[CreatedEnt]) * g_fVelocityFactor[CreatedEnt]);
for (new i = 0; i < 3; i++)
g_vVelocity[CreatedEnt][i] *= fFactor;
set_pev(CreatedEnt, pev_velocity, g_vVelocity[CreatedEnt]);
set_pev(CreatedEnt, pev_nextthink, get_gametime() + 5.0);
}
++block_count;
}
}
}
fclose(file);
if ( 1 <= id <= g_max_players )
{
static name[32];
get_user_name(id, name, charsmax(name));
for ( new i = 1; i <= g_max_players; ++i )
{
if ( !g_connected[i]
|| !g_admin[i] && !g_gived_access[i] ) continue;
BCM_Print(i, "^1%s^3 loaded^1 %d block%s^3,^1 %d teleport%s^3 and^1 %d light%s^3! Total entites in map:^1 %d", name, block_count, block_count == 1 ? g_blank : "s", tele_count, tele_count == 1 ? g_blank : "s", light_count, light_count == 1 ? g_blank : "s", entity_count());
}
}
return PLUGIN_HANDLED;
}
Last edited by mammapappa; 11-07-2013 at 17:51.
|
|