AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   rotate ents save and load (https://forums.alliedmods.net/showthread.php?t=153504)

mammapappa 03-24-2011 15:29

rotate ents save and load
 
hi i have made a ent rotate thing :P 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 (id4);
    if (!
ent)
        return 
PLUGIN_HANDLED;
    
    
entity_get_vector(entEV_VEC_anglesangles);
    for (new 
i=0;i<3;i++)
    {
        
read_argv(i+1,arg,31);
        
angles [i] += floatstr (arg);
    }
    
    
getorigin(ententorigin);
    
entity_set_vector(entEV_VEC_v_angleangles);
    
entity_set_vector(entEV_VEC_anglesangles);
    
setorigin(ententorigin);
    
    return 
PLUGIN_HANDLED;


PHP Code:

public getorigin (entorigin [3])
{
    if (
ent <= get_maxplayers())
        
get_user_origin (entorigin);
    else
    {
        new 
Float:orig [3];
        
entity_get_vector(entEV_VEC_originorig);
        
FVecIVec(origorigin);
    }


PHP Code:

public getorigin (entorigin [3])
{
    if (
ent <= get_maxplayers())
        
get_user_origin (entorigin);
    else
    {
        new 
Float:orig [3];
        
entity_get_vector(entEV_VEC_originorig);
        
FVecIVec(origorigin);
    }



And i want it to save with this
PHP Code:

saveBlocks(id)
{
    if (
gCantSave)
        
client_print(idprint_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(szPath128"%s/%s.bm"gDirgCurConfig);
        
        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:flPropertie1Float:flPropertie2iProp3;
        new 
Float:flRenderColor], Float:flRenderAmtiRenderFXiRenderMode;
        new 
szWeapon[32];
        new 
origin[3];
        new 
keyvalue[64];
        
        while ((
ent find_ent_by_class(entgszBlockClassname)))
        {
            
//get block info
            
blockType entity_get_int(entEV_INT_body);
            if( 
blockType == BM_MAGICCARPET )
                
pev(entpev_v_anglevOrigin);
            else
                
pev(entpev_originvOrigin);
            
entity_get_vector(entEV_VEC_anglesvAngles);
            
entity_get_vector(entEV_VEC_maxsvSizeMax);
            
            
size SMALL;
            
fMax vSizeMax[0] + vSizeMax[1] + vSizeMax[2];
            if (
fMax 36.0size POLE;
            if (
fMax 64.0size NORMAL;
            if (
fMax 128.0size LARGE;
            
            
iRenderFX    peventpev_renderfx );
            
iRenderMode    peventpev_rendermode );
            
peventpev_rendercolorflRenderColor );
            
peventpev_renderamtflRenderAmt );
            
            
peventpev_fuser1flPropertie1 );
            
peventpev_fuser2flPropertie2 );
            
iProp3 pev(entpev_fixangle);
            
            
//format block info and save it to file
            
if (blockType == BM_WEAPON) {
                
pev(entpev_messageszWeapon31);
                
formatex(szData128"%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], sizeszWeaponflPropertie2iProp3iRenderFXiRenderModeflRenderAmtflRenderColor[0], flRenderColor[1], flRenderColor[2]);
            } else
                
formatex(szData128"%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], sizeflPropertie1flPropertie2iProp3iRenderFXiRenderModeflRenderAmtflRenderColor[0], flRenderColor[1], flRenderColor[2]);
            
            
fputs(fileszData);
            
            
//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(entgszTeleportEndClassname)))
        {
            
//get the id of the start of the teleporter
            
new tele entity_get_int(entEV_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(teleEV_VEC_originvStart);
                
entity_get_vector(entEV_VEC_originvEnd);
                
                
formatex(szData128"%c %f %f %f %f %f %f^n"gTeleportSaveIdvStart[0], vStart[1], vStart[2], vEnd[0], vEnd[1], vEnd[2]);
                
fputs(fileszData);
                
                
//2 teleport entities count as 1 teleporter
                
++teleCount;
            }
        }
        
        
//get players name
        
new szName[32];
        
get_user_name(idszName32);
        
        
//notify all admins that the player saved blocks to file
        
for (new 1<= 32; ++i)
        {
            
//make sure player is connected
            
if (is_user_connected(i))
            {
                if (
get_user_flags(i) & BM_ADMIN_LEVEL)
                {
                    
client_print(iprint_chat"%s'%s' saved %d block%s and %d teleporter%s in template '%s'! Total entites in map: %d"gszPrefixszNameblockCount, (blockCount == "" "s"), teleCount, (teleCount == "" "s"), gCurConfigentity_count());
                }
            }
        }
        
        
//close file
        
fclose(file);
    }




And load in this:
PHP Code:

loadBlocks(idnumber, 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(szPath128"%s/%s.bm"gDirszConfigsName);
        
        
//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 && id <= 32 || number == 1)
            {
                
deleteAllBlocks(idfalse);
                
deleteAllTeleports(idfalse);
            }
            
            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 
fopen(szPath"rt");
            new 
blockCount 0;
            new 
teleCount 0;
            new 
Float:flProperty1Float:flProperty2iProp3;
            new 
iCreatedEntity;
            
            new 
szRenderColor[3][16], szRenderFX[3], szRenderMode[3], szRenderAmt[16];
            new 
Float:flRenderColor], Float:flRenderAmtiRenderFXiRenderMode;
            
            
copy(gCurConfig32szConfigsName);
            
            
//iterate through all the lines in the file
            
while (!feof(f))
            {
                
szType "";
                
fgets(fszData128);
                
parse(szDataszType1sz116sz216sz316sz416sz516sz616sz716sz816sz916sz1016szRenderFX2szRenderMode2szRenderAmt16szRenderColor[0], 16szRenderColor[1], 16szRenderColor[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_floatszRenderColor[0] );
                
flRenderColor[1] = str_to_floatszRenderColor[1] );
                
flRenderColor[2] = str_to_floatszRenderColor[2] );
                
flRenderAmt str_to_floatszRenderAmt );
                
                
iRenderFX str_to_numszRenderFX );
                
iRenderMode str_to_numszRenderMode );
                
                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(0BM_PLATFORMvVec1axissize);
                        case 
'B'iCreatedEntity createBlock(0BM_BHOPvVec1axissize);
                        case 
'C'iCreatedEntity createBlock(0BM_DAMAGEvVec1axissize);
                        case 
'D'iCreatedEntity createBlock(0BM_HEALERvVec1axissize);
                        case 
'E'iCreatedEntity createBlock(0BM_INVINCIBILITYvVec1axissize);
                        case 
'F'iCreatedEntity createBlock(0BM_STEALTHvVec1axissize);
                        case 
'G'iCreatedEntity createBlock(0BM_TRAMPOLINEvVec1axissize);
                        case 
'H'iCreatedEntity createBlock(0BM_SPEEDBOOSTvVec1axissize);
                        case 
'I'iCreatedEntity createBlock(0BM_NOFALLDAMAGEvVec1axissize);
                        case 
'J'iCreatedEntity createBlock(0BM_ICEvVec1axissize);
                        case 
'K'iCreatedEntity createBlock(0BM_DEATHvVec1axissize);
                        case 
'N'iCreatedEntity createBlock(0BM_LOWGRAVITYvVec1axissize);
                        case 
'P'iCreatedEntity createBlock(0BM_SLAPvVec1axissize);
                        case 
'R'iCreatedEntity createBlock(0BM_HONEYvVec1axissize);
                        case 
'S'iCreatedEntity createBlock(0BM_BARRIER_CTvVec1axissize);
                        case 
'T'iCreatedEntity createBlock(0BM_BARRIER_TvVec1axissize);
                        case 
'U'iCreatedEntity createBlock(0BM_BOOTSOFSPEEDvVec1axissize);
                        case 
'Y'iCreatedEntity createBlock(0BM_MAGICCARPETvVec1axissize);
                        case 
'Z'iCreatedEntity createBlock(0BM_DELAYEDBHOPvVec1axissize);
                        case 
'1'iCreatedEntity createBlock(0BM_SPAMDUCKvVec1axissize);
                        case 
'2'iCreatedEntity createBlock(0BM_WEAPONvVec1axissize);
                        case 
'3'iCreatedEntity createBlock(0BM_POINTvVec1axissize);
                        
                        case 
gTeleportSaveId:
                        {
                            
createTeleport(0TELEPORT_STARTvVec1);
                            
createTeleport(0TELEPORT_ENDvVec2);
                            
                            
//increment teleport count
                            
++teleCount;
                        }
                        
                        default:
                        {
                            
log_amx("%sInvalid block type: %c in: %s"gszPrefixszType[0], gszFile);
                            
                            
//decrement block counter because a block was not created
                            
--blockCount;
                        }
                    }
                    if (
pev_valid(iCreatedEntity)) {
                        new 
blockType entity_get_int(iCreatedEntityEV_INT_body);
                        
                        
set_peviCreatedEntitypev_renderfxiRenderFX );
                        
set_peviCreatedEntitypev_rendermodeiRenderMode );
                        
set_peviCreatedEntitypev_rendercolorflRenderColor );
                        
set_peviCreatedEntitypev_renderamtflRenderAmt );
                        
                        if (
blockType == BM_WEAPON)
                            
set_pev(iCreatedEntitypev_messagesz8);
                        else
                            
set_pev(iCreatedEntitypev_fuser1flProperty1);
                        
                        
set_pev(iCreatedEntitypev_fuser2flProperty2);
                        
set_pev(iCreatedEntitypev_fixangleiProp3);
                    }
                }
            }
            
            
fclose(f);
            
            
//if a player is loading the blocks
            
if (id && id <= 32)
            {
                
//get players name
                
new szName[32];
                
get_user_name(idszName32);
                
                
//notify all admins that the player loaded blocks from file
                
for (new 1<= 32; ++i)
                {
                    
//make sure player is connected
                    
if (is_user_connected(i))
                    {
                        if (
get_user_flags(i) & BM_ADMIN_LEVEL)
                        {
                            
client_print(iprint_chat"%s'%s' loaded template '%s' which has %d block%s and %d teleporter%s! Total entites in map: %d"gszPrefixszNameszConfigsNameblockCount, (blockCount == "" "s"), teleCount, (teleCount == "" "s"), entity_count());
                        }
                    }
                }
            }
        }
        else
        {
            
//if a player is loading the blocks
            
if (id && id <= 32)
            {
                
//notify player that the file could not be found
                
client_print(idprint_chat"%sCouldn't find file: %s"gszPrefixgszNewFile);
            }
        }
    }


Realy sorry for long codes but i hope someone can fix this


All times are GMT -4. The time now is 14:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.