Support to make the code better - tips.

Ако имате затруднения при изработката/преработката на даден плъгин - пишете тук, ще се опитаме да ви помогнем!
Аватар
X3.!
Извън линия
Foreigner
Foreigner
Мнения: 31
Регистриран на: 30 Ное 2018, 20:46
Се отблагодари: 1 път

Support to make the code better - tips.

Мнение от X3.! » 29 Юни 2020, 12:30

Hello,

Any suggestions or tips to make the code better? If it was hardcoded or so, and it can be done in a simple way.
PS: I just like to learn. :gamer1:

Код за потвърждение: Избери целия код

/*
Original plugin by xPaw - JailCellButton.
*/

#include <amxmodx>
#include <hamsandwich>
#include <engine>
#define CC_COLORS_TYPE CC_COLORS_SHORT
#include <cromchat>

// Bugsy //
#define IsPlayer(%1) (1<=%1<=g_iMaxPlayers)
#define ACCESS ADMIN_KICK

new g_iEnt,
    pCvarEnabled,
    g_iMaxPlayers,
    bool:g_bAllowed[33];

public plugin_init()
{
    register_plugin("Breakable Entity Name", "0.2", "X3")

    pCvarEnabled = register_cvar("enable_breakable_editor", "1");

    if(get_pcvar_num(pCvarEnabled))
    {
        register_clcmd("drop", "NameEntity");
        register_clcmd("BREAKABLE_NAME", "SetBreakableName");
    }

    RegisterHam(Ham_TakeDamage, "func_breakable", "fw_BreakableBroke", 1);
    LoadBreakables();

    CC_SetPrefix("!n[!gZombie Escape!n]")

    g_iMaxPlayers = get_maxplayers();
}

public NameEntity(id)
{
    if(~get_user_flags(id) & ACCESS)
        return;
    
    if(!get_pcvar_num(pCvarEnabled))
    {
        client_print(id, print_chat, "Editing is disabled! Enable and change map again");
        return;
    }
    
    new iEnt, Body;
    get_user_aiming(id, iEnt, Body, 400);
    g_iEnt = iEnt
    
    if(is_valid_ent(iEnt) && IsBreakable(iEnt))
    {
        new szTargetName[32];
        entity_get_string( iEnt, EV_SZ_targetname, szTargetName, charsmax(szTargetName));
        new szModel[7]
        entity_get_string( g_iEnt, EV_SZ_model, szModel, charsmax(szModel));

        if(equal( szTargetName, "" ))
        {
            g_bAllowed[id] = true;
            client_cmd(id, "messagemode BREAKABLE_NAME")
        }
        else
            client_print(id, print_chat, "Entity has a name - (%s) Model (%i)", szTargetName, szModel);
    }
    else
        client_print(id, print_chat, "Not breakable entity or too far.");
}

public SetBreakableName(id)
{
    if(!is_user_connected(id))
        return;
    
    if(!g_bAllowed[id])
    {
        client_print(id, print_chat, "You must use your 'g' button - 'drop'");
        return;
    }

    new szArgs[24];
    read_args(szArgs, charsmax(szArgs));
    remove_quotes(szArgs);

    if(equal(szArgs, ""))
    {
        client_print(id, print_chat, "Empty string");
        return;
    }

    if(IsBreakable(g_iEnt))
    {
        new szModel[7];
        entity_get_string(g_iEnt, EV_SZ_model, szModel, charsmax(szModel));
        entity_set_string(g_iEnt, EV_SZ_targetname, szArgs);

        new szFile[128];
        get_localinfo( "amxx_datadir", szFile, charsmax( szFile ) );
        add( szFile, charsmax( szFile ), "/Breakablesv2.ini" );

        new iFile = fopen(szFile, "at");

        if(iFile)
        {
            new szMapName[32];
            get_mapname(szMapName, charsmax(szMapName));

            formatex(szFile, charsmax(szFile), "%s %s %s^n", szMapName, szArgs, szModel);
            fputs(iFile, szFile);
            fclose(iFile);
            client_print(id, print_chat, "Entity name saved to file map (%s) - name (%s) - model (%s)", szMapName, szArgs, szModel);
        }
        g_bAllowed[id] = false;
    }
}

public client_disconnect(id)
{
    if(g_bAllowed[id])
        g_bAllowed[id] = false;
}

public LoadBreakables()
{
    new szFile[ 128 ];
    get_localinfo( "amxx_datadir", szFile, charsmax( szFile ) );
    add( szFile, charsmax( szFile ), "/Breakablesv2.ini" );
	
    new iFile = fopen( szFile, "rt" );

    if( !iFile ) return;

    new szMap[ 32 ], szModel[ 7 ], szCurrentMap[ 32 ], szTargetName[32];
    get_mapname( szCurrentMap, charsmax( szCurrentMap ) );

    while( !feof( iFile ) )
	{
        fgets( iFile, szFile, charsmax( szFile ) );
        trim( szFile );

        if( szFile[ 0 ] == ';' || ( szFile[ 0 ] == '/' && szFile[ 1 ] == '/' ) )
        continue;

        parse( szFile, szMap, charsmax( szMap ), szTargetName, charsmax(szTargetName), szModel, charsmax( szModel ) );
		
        if( equali( szMap, szCurrentMap ) )
        {
            new Entity = find_ent_by_model( -1, "func_breakable", szModel );
            entity_set_string(Entity, EV_SZ_targetname, szTargetName);
        }
    }
    fclose( iFile );
}

IsBreakable( const Entity )
{
	new szClassName[ 17 ];
	entity_get_string( Entity, EV_SZ_classname, szClassName, charsmax( szClassName ) );

	return equal( szClassName, "func_breakable" );
}

public fw_BreakableBroke(Ent, Weapon, Killer)
{
    if(entity_get_float(Ent, EV_FL_health) <= 0.0 )
    {

        if(!IsPlayer(Killer))
            return HAM_IGNORED;
        
        new szName[32]; get_user_name(Killer, szName, charsmax(szName));
        
        new szTargetName[32];
        entity_get_string(Ent, EV_SZ_targetname, szTargetName, charsmax(szTargetName));
        if(equal(szTargetName, ""))
            CC_SendMessage(0, "!g%s!n has broken !tsomething", szName);
        else
            CC_SendMessage(0, "!g%s!n has broken !g%s!n", szName, szTargetName);
    }
    return HAM_IGNORED
}
Последно промяна от OciXCrom на 29 Юни 2020, 15:06, променено общо 1 път.
Причина: No need to use [hidden] tags.

Публикувай отговор
  • Подобни теми
    Отговори
    Преглеждания
     Последно мнение

Обратно към “Помощ в скриптирането”

Кой е на линия

Потребители разглеждащи този форум: 0 регистрирани и 1 гост