View Single Post
nadavafuta
Junior Member
Join Date: Oct 2008
Old 04-13-2009 , 09:41   Re: blockmaker_v4.01 [BM]
Reply With Quote #1085

I see that this part:
Code:
/***** FILE HANDLING *****/
saveBlocks(id)
{
    //make sure player has access to this command
    if (get_user_flags(id) & BM_ADMIN_LEVEL)
    {
        new file = fopen(gszNewFile, "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 timerCount = 0;
        new szData[128];
        new Float:fMax;
        new size;
        new Float:vSizeMax[3];
        
        while ((ent = find_ent_by_class(ent, gszBlockClassname)))
        {
            //get block info
            blockType = entity_get_int(ent, EV_INT_body);
            entity_get_vector(ent, EV_VEC_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 > 64.0) size = NORMAL;
            if (fMax > 128.0) size = LARGE;
            
            //format block info and save it to file
            formatex(szData, 128, "%c %f %f %f %f %f %f %d^n", gBlockSaveIds[blockType], vOrigin[0], vOrigin[1], vOrigin[2], vAngles[0], vAngles[1], vAngles[2], size);
            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;
            }
        }
        
        //iterate through timer end entities because you can't have an end without a start
        ent = -1;
        
        while ((ent = find_ent_by_class(ent, gszTimerClassname)))
        {
            //get the type of timer
            new timerType = entity_get_int(ent, EV_INT_body);
            
            //timer type must be an end
            if (timerType == TIMER_END)
            {
                //get the id of the start of the timer
                new timer = entity_get_int(ent, EV_INT_iuser1);
                
                //check that start of timer is a valid entity
                if (timer)
                {
                    //get the origin of the start of the timer and its angles
                    entity_get_vector(timer, EV_VEC_origin, vStart);
                    entity_get_vector(timer, EV_VEC_angles, vAngles);
                    
                    //save the start timer information to file
                    formatex(szData, 128, "%c %f %f %f %f %f %f^n", gTimerSaveId, vStart[0], vStart[1], vStart[2], vAngles[0], vAngles[1], vAngles[2]);
                    fputs(file, szData);
                    
                    //get the origin of the end of the timer and its angles
                    entity_get_vector(ent, EV_VEC_origin, vEnd);
                    entity_get_vector(ent, EV_VEC_angles, vAngles);
                    
                    //save the end timer information to file
                    formatex(szData, 128, "%c %f %f %f %f %f %f^n", gTimerSaveId, vEnd[0], vEnd[1], vEnd[2], vAngles[0], vAngles[1], vAngles[2]);
                    fputs(file, szData);
                    
                    //2 timer entities count as 1 timer
                    ++timerCount;
                }
            }
        }
        
        //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, %d teleporter%s and %d timer%s! Total entites in map: %d", gszPrefix, szName, blockCount, (blockCount == 1 ? "" : "s"), teleCount, (teleCount == 1 ? "" : "s"), timerCount, (timerCount == 1 ? "" : "s"), entity_count());
                }
            }
        }
        
        //close file
        fclose(file);
    }
}
Is the part where it saves to file,
Any chance someone can teach me how can I turn it into a command like:
bm_save, to use with hlds console?
nadavafuta is offline