|
Member
|

03-24-2011
, 15:29
rotate ents save and load
|
#1
|
hi i have made a ent rotate thing  but i dont know how to make it save the rotation so i wounder if someone could make it save ?
here is code:
PHP Code:
register_concmd("bm_rotate","rotate",BM_ADMIN_LEVEL,"<x> <y> <z>");
PHP Code:
public rotate (id,level,cid)
{
if (!cmd_access(id,level,cid,4))
return PLUGIN_HANDLED;
new arg [32], Float:angles [3], entorigin [3], ent = getent (id, 4);
if (!ent)
return PLUGIN_HANDLED;
entity_get_vector(ent, EV_VEC_angles, angles);
for (new i=0;i<3;i++)
{
read_argv(i+1,arg,31);
angles [i] += floatstr (arg);
}
getorigin(ent, entorigin);
entity_set_vector(ent, EV_VEC_v_angle, angles);
entity_set_vector(ent, EV_VEC_angles, angles);
setorigin(ent, entorigin);
return PLUGIN_HANDLED;
}
PHP Code:
public getorigin (ent, origin [3])
{
if (ent <= get_maxplayers())
get_user_origin (ent, origin);
else
{
new Float:orig [3];
entity_get_vector(ent, EV_VEC_origin, orig);
FVecIVec(orig, origin);
}
}
PHP Code:
public getorigin (ent, origin [3])
{
if (ent <= get_maxplayers())
get_user_origin (ent, origin);
else
{
new Float:orig [3];
entity_get_vector(ent, EV_VEC_origin, orig);
FVecIVec(orig, origin);
}
}
And i want it to save with this
PHP Code:
saveBlocks(id)
{
if (gCantSave)
client_print(id, print_chat, "%s You can't save because someone just jumped on a bhop", gszPrefix);
//make sure player has access to this command
else if (gAccess[id])
{
new szPath[129];
format(szPath, 128, "%s/%s.bm", gDir, gCurConfig);
new file = fopen(szPath, "wt");
new ent = -1;
new blockType;
new Float:vOrigin[3];
new Float:vAngles[3];
new Float:vStart[3];
new Float:vEnd[3];
new blockCount = 0;
new teleCount = 0;
new szData[128];
new Float:fMax;
new size;
new Float:vSizeMax[3];
new Float:flPropertie1, Float:flPropertie2, iProp3;
new Float:flRenderColor[ 3 ], Float:flRenderAmt, iRenderFX, iRenderMode;
new szWeapon[32];
new origin[3];
new keyvalue[64];
while ((ent = find_ent_by_class(ent, gszBlockClassname)))
{
//get block info
blockType = entity_get_int(ent, EV_INT_body);
if( blockType == BM_MAGICCARPET )
pev(ent, pev_v_angle, vOrigin);
else
pev(ent, pev_origin, vOrigin);
entity_get_vector(ent, EV_VEC_angles, vAngles);
entity_get_vector(ent, EV_VEC_maxs, vSizeMax);
size = SMALL;
fMax = vSizeMax[0] + vSizeMax[1] + vSizeMax[2];
if (fMax > 36.0) size = POLE;
if (fMax > 64.0) size = NORMAL;
if (fMax > 128.0) size = LARGE;
iRenderFX = pev( ent, pev_renderfx );
iRenderMode = pev( ent, pev_rendermode );
pev( ent, pev_rendercolor, flRenderColor );
pev( ent, pev_renderamt, flRenderAmt );
pev( ent, pev_fuser1, flPropertie1 );
pev( ent, pev_fuser2, flPropertie2 );
iProp3 = pev(ent, pev_fixangle);
//format block info and save it to file
if (blockType == BM_WEAPON) {
pev(ent, pev_message, szWeapon, 31);
formatex(szData, 128, "%c %f %f %f %f %f %f %d %s %.1f %i %i %i %f %f %f %f^n", gBlockSaveIds[blockType], vOrigin[0], vOrigin[1], vOrigin[2], vAngles[0], vAngles[1], vAngles[2], size, szWeapon, flPropertie2, iProp3, iRenderFX, iRenderMode, flRenderAmt, flRenderColor[0], flRenderColor[1], flRenderColor[2]);
} else
formatex(szData, 128, "%c %f %f %f %f %f %f %d %.1f %.1f %i %i %i %f %f %f %f^n", gBlockSaveIds[blockType], vOrigin[0], vOrigin[1], vOrigin[2], vAngles[0], vAngles[1], vAngles[2], size, flPropertie1, flPropertie2, iProp3, iRenderFX, iRenderMode, flRenderAmt, flRenderColor[0], flRenderColor[1], flRenderColor[2]);
fputs(file, szData);
//increment block count
++blockCount;
}
//iterate through teleport end entities because you can't have an end without a start
ent = -1;
while ((ent = find_ent_by_class(ent, gszTeleportEndClassname)))
{
//get the id of the start of the teleporter
new tele = entity_get_int(ent, EV_INT_iuser1);
//check that start of teleport is a valid entity
if (tele)
{
//get the origin of the start of the teleport and save it to file
entity_get_vector(tele, EV_VEC_origin, vStart);
entity_get_vector(ent, EV_VEC_origin, vEnd);
formatex(szData, 128, "%c %f %f %f %f %f %f^n", gTeleportSaveId, vStart[0], vStart[1], vStart[2], vEnd[0], vEnd[1], vEnd[2]);
fputs(file, szData);
//2 teleport entities count as 1 teleporter
++teleCount;
}
}
//get players name
new szName[32];
get_user_name(id, szName, 32);
//notify all admins that the player saved blocks to file
for (new i = 1; i <= 32; ++i)
{
//make sure player is connected
if (is_user_connected(i))
{
if (get_user_flags(i) & BM_ADMIN_LEVEL)
{
client_print(i, print_chat, "%s'%s' saved %d block%s and %d teleporter%s in template '%s'! Total entites in map: %d", gszPrefix, szName, blockCount, (blockCount == 1 ? "" : "s"), teleCount, (teleCount == 1 ? "" : "s"), gCurConfig, entity_count());
}
}
}
//close file
fclose(file);
}
}
And load in this:
PHP Code:
loadBlocks(id, number, const szConfigsName[])
{
new bool:bAccess = false;
//if this function was called on map load, ID is 0
if (id == 0)
{
bAccess = true;
}
//make sure user calling this function has access
else if (gAccess[id])
{
bAccess = true;
}
if (bAccess)
{
new szPath[129];
format(szPath, 128, "%s/%s.bm", gDir, szConfigsName);
//if map file exists
if (file_exists(szPath))
{
//if a player is loading then first delete all the old blocks, teleports and timers
if (id > 0 && id <= 32 || number == 1)
{
deleteAllBlocks(id, false);
deleteAllTeleports(id, false);
}
new szData[128];
new szType[2];
new sz1[16], sz2[16], sz3[16], sz4[16], sz5[16], sz6[16], sz7[16], sz8[16], sz9[16], sz10[16];
new Float:vVec1[3];
new Float:vVec2[3];
new axis;
new size;
new f = fopen(szPath, "rt");
new blockCount = 0;
new teleCount = 0;
new Float:flProperty1, Float:flProperty2, iProp3;
new iCreatedEntity;
new szRenderColor[3][16], szRenderFX[3], szRenderMode[3], szRenderAmt[16];
new Float:flRenderColor[ 3 ], Float:flRenderAmt, iRenderFX, iRenderMode;
copy(gCurConfig, 32, szConfigsName);
//iterate through all the lines in the file
while (!feof(f))
{
szType = "";
fgets(f, szData, 128);
parse(szData, szType, 1, sz1, 16, sz2, 16, sz3, 16, sz4, 16, sz5, 16, sz6, 16, sz7, 16, sz8, 16, sz9, 16, sz10, 16, szRenderFX, 2, szRenderMode, 2, szRenderAmt, 16, szRenderColor[0], 16, szRenderColor[1], 16, szRenderColor[2], 16);
vVec1[0] = str_to_float(sz1);
vVec1[1] = str_to_float(sz2);
vVec1[2] = str_to_float(sz3);
vVec2[0] = str_to_float(sz4);
vVec2[1] = str_to_float(sz5);
vVec2[2] = str_to_float(sz6);
size = str_to_num(sz7);
flProperty1 = str_to_float(sz8);
flProperty2 = str_to_float(sz9);
iProp3 = str_to_num(sz10);
flRenderColor[0] = str_to_float( szRenderColor[0] );
flRenderColor[1] = str_to_float( szRenderColor[1] );
flRenderColor[2] = str_to_float( szRenderColor[2] );
flRenderAmt = str_to_float( szRenderAmt );
iRenderFX = str_to_num( szRenderFX );
iRenderMode = str_to_num( szRenderMode );
if (strlen(szType) > 0)
{
//if type is not a teleport
if (szType[0] != gTeleportSaveId)
{
//set axis orientation depending on block angles
if (vVec2[0] == 90.0 && vVec2[1] == 0.0 && vVec2[2] == 0.0)
{
axis = X;
}
else if (vVec2[0] == 90.0 && vVec2[1] == 0.0 && vVec2[2] == 90.0)
{
axis = Y;
}
else
{
axis = Z;
}
//increment block counter
++blockCount;
}
//create block or teleport depending on type
switch (szType[0])
{
case 'A': iCreatedEntity = createBlock(0, BM_PLATFORM, vVec1, axis, size);
case 'B': iCreatedEntity = createBlock(0, BM_BHOP, vVec1, axis, size);
case 'C': iCreatedEntity = createBlock(0, BM_DAMAGE, vVec1, axis, size);
case 'D': iCreatedEntity = createBlock(0, BM_HEALER, vVec1, axis, size);
case 'E': iCreatedEntity = createBlock(0, BM_INVINCIBILITY, vVec1, axis, size);
case 'F': iCreatedEntity = createBlock(0, BM_STEALTH, vVec1, axis, size);
case 'G': iCreatedEntity = createBlock(0, BM_TRAMPOLINE, vVec1, axis, size);
case 'H': iCreatedEntity = createBlock(0, BM_SPEEDBOOST, vVec1, axis, size);
case 'I': iCreatedEntity = createBlock(0, BM_NOFALLDAMAGE, vVec1, axis, size);
case 'J': iCreatedEntity = createBlock(0, BM_ICE, vVec1, axis, size);
case 'K': iCreatedEntity = createBlock(0, BM_DEATH, vVec1, axis, size);
case 'N': iCreatedEntity = createBlock(0, BM_LOWGRAVITY, vVec1, axis, size);
case 'P': iCreatedEntity = createBlock(0, BM_SLAP, vVec1, axis, size);
case 'R': iCreatedEntity = createBlock(0, BM_HONEY, vVec1, axis, size);
case 'S': iCreatedEntity = createBlock(0, BM_BARRIER_CT, vVec1, axis, size);
case 'T': iCreatedEntity = createBlock(0, BM_BARRIER_T, vVec1, axis, size);
case 'U': iCreatedEntity = createBlock(0, BM_BOOTSOFSPEED, vVec1, axis, size);
case 'Y': iCreatedEntity = createBlock(0, BM_MAGICCARPET, vVec1, axis, size);
case 'Z': iCreatedEntity = createBlock(0, BM_DELAYEDBHOP, vVec1, axis, size);
case '1': iCreatedEntity = createBlock(0, BM_SPAMDUCK, vVec1, axis, size);
case '2': iCreatedEntity = createBlock(0, BM_WEAPON, vVec1, axis, size);
case '3': iCreatedEntity = createBlock(0, BM_POINT, vVec1, axis, size);
case gTeleportSaveId:
{
createTeleport(0, TELEPORT_START, vVec1);
createTeleport(0, TELEPORT_END, vVec2);
//increment teleport count
++teleCount;
}
default:
{
log_amx("%sInvalid block type: %c in: %s", gszPrefix, szType[0], gszFile);
//decrement block counter because a block was not created
--blockCount;
}
}
if (pev_valid(iCreatedEntity)) {
new blockType = entity_get_int(iCreatedEntity, EV_INT_body);
set_pev( iCreatedEntity, pev_renderfx, iRenderFX );
set_pev( iCreatedEntity, pev_rendermode, iRenderMode );
set_pev( iCreatedEntity, pev_rendercolor, flRenderColor );
set_pev( iCreatedEntity, pev_renderamt, flRenderAmt );
if (blockType == BM_WEAPON)
set_pev(iCreatedEntity, pev_message, sz8);
else
set_pev(iCreatedEntity, pev_fuser1, flProperty1);
set_pev(iCreatedEntity, pev_fuser2, flProperty2);
set_pev(iCreatedEntity, pev_fixangle, iProp3);
}
}
}
fclose(f);
//if a player is loading the blocks
if (id > 0 && id <= 32)
{
//get players name
new szName[32];
get_user_name(id, szName, 32);
//notify all admins that the player loaded blocks from file
for (new i = 1; i <= 32; ++i)
{
//make sure player is connected
if (is_user_connected(i))
{
if (get_user_flags(i) & BM_ADMIN_LEVEL)
{
client_print(i, print_chat, "%s'%s' loaded template '%s' which has %d block%s and %d teleporter%s! Total entites in map: %d", gszPrefix, szName, szConfigsName, blockCount, (blockCount == 1 ? "" : "s"), teleCount, (teleCount == 1 ? "" : "s"), entity_count());
}
}
}
}
}
else
{
//if a player is loading the blocks
if (id > 0 && id <= 32)
{
//notify player that the file could not be found
client_print(id, print_chat, "%sCouldn't find file: %s", gszPrefix, gszNewFile);
}
}
}
}
Realy sorry for long codes but i hope someone can fix this
|
|