взять оружие

Статус
В этой теме нельзя размещать новые ответы.
Сообщения
278
Реакции
137
Привет всем, у меня есть плагин. Я хотел бы, чтобы вы сделали этот плагин Reapi плагин. Я попробовал это, но не смог.
Спасибо вам всем.
~
Hello everyone, I have a plugin. I would like you to make this plugin Reapi plugin. I tried it, but could not.
Thank you all.

PHP:
#include <amxmodx>
#include <engine>
#include <hamsandwich>

public plugin_init() {
    register_plugin("Weapon pick up", "1.04", "daedhelil");
}

public client_PreThink(id) {
    if(!is_user_alive(id))
        return PLUGIN_CONTINUE;
   
    static oldbuttons;
    oldbuttons = get_user_oldbutton(id);
    if(oldbuttons & IN_USE)
        return PLUGIN_CONTINUE;
   
    static buttons;
    buttons = get_user_button(id);
    if((buttons & IN_USE)) {
        new aimOrigin[3];
        get_user_origin(id, aimOrigin, 3);
       
        new entity = -1;
        while((entity = find_ent_by_class(entity, "weaponbox"))) {
            new Float:min_weaponboxOrigin[3];
            entity_get_vector(entity, EV_VEC_absmin, min_weaponboxOrigin);
           
            new Float:max_weaponboxOrigin[3];
            entity_get_vector(entity, EV_VEC_absmax, max_weaponboxOrigin);
           
            new Float:playerOrigin[3];
            entity_get_vector(id, EV_VEC_origin, playerOrigin);
           
            new Float:weaponboxOrigin[3];
            entity_get_vector(entity, EV_VEC_origin, weaponboxOrigin);
           
            new Float:distance = get_distance_f(playerOrigin, weaponboxOrigin);
            if(distance < 150.0) {
                if(aimOrigin[0] < max_weaponboxOrigin[0] && aimOrigin[0] > min_weaponboxOrigin[0]
                && aimOrigin[1] < max_weaponboxOrigin[1] && aimOrigin[1] > min_weaponboxOrigin[1]) {
                    new type = cs_get_weapon_by(entity, EV_ENT_owner);
                    switch(type) {
                        case 3, 5, 7, 8, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 27, 28, 30: {
                            new primary = cs_get_weapon_by(get_pdata_cbase(id, 368), EV_ENT_pContainingEntity);
                            if(primary)
                                drop(id, primary);
                            pick_up(id, entity);
                            return PLUGIN_CONTINUE;
                        }
                        case 1, 10, 11, 16, 17, 26: {
                            new secondary = cs_get_weapon_by(get_pdata_cbase(id, 369), EV_ENT_pContainingEntity);
                            if(secondary)
                                drop(id, secondary);
                            pick_up(id, entity);
                            return PLUGIN_CONTINUE;
                        }
                    }
                }
            }
        }
        entity_set_int(id, EV_INT_button, get_user_oldbutton(id) & ~IN_USE);
        entity_set_int(id, EV_INT_button, get_user_button(id) & ~IN_USE);
    }
    return PLUGIN_CONTINUE;
}

pick_up(id, entity) {
    new Float:origin[3];
    entity_get_vector(id, EV_VEC_origin, origin);
    if(get_user_button(id) & IN_DUCK)
        origin[2] -= 16.0;
    else
        origin[2] -= 36.0;
    entity_set_origin(entity, origin);
}

drop(id, weaponID) {
    if(weaponID > 0) {
        new name[32];
        get_weaponname(weaponID, name, 31);
        engclient_cmd(id, "drop", name);
    }
}

cs_get_weapon_by(entity, entity_type) {
    for(new i = 32 + 1; i < 512; ++i) {
        if(is_valid_ent(i) && entity == entity_get_edict(i, entity_type)) {
            new name[32];
            entity_get_string(i, EV_SZ_classname, name, sizeof name - 1)
            return get_weaponid(name);
        }
    }
    return 0;
}
 
Сообщения
2,288
Реакции
1,739
Помог
31 раз(а)
PurposeLess,
Код:
// Copyright © 2018 Vaqtincha

/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG START ■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/

// #define SHOW_HUD_INFO
#define REPLACE_ONLY_SAME_SLOT
// #define BLOCK_DEFAULT_TOUCH

/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG END ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/

#include <amxmodx>
#include <reapi>
#include <hamsandwich>
#include <fakemeta>

#if AMXX_VERSION_NUM > 183
    #error FUCK YOU
#endif

const CANT_REPLACE_WEAPONS_BIT = (BIT(any:WEAPON_KNIFE) | BIT(any:WEAPON_C4)
    | BIT(any:WEAPON_HEGRENADE) | BIT(any:WEAPON_FLASHBANG) | BIT(any:WEAPON_SMOKEGRENADE))

enum color_e { R, G, B }

new Float:g_vecTeamColors[TeamName][color_e] =
{
    { 0, 220, 0 },
    { 235, 0, 0 }, // TEAM_TERRORIST
    { 0, 0, 235 }, // TEAM_CT
    { 220, 220, 220 }
}

new g_hHudSync

public plugin_init()
{
    register_plugin("Weapon Alternate Pickup", "0.1", "Vaqtincha")

    RegisterHam(Ham_Use, "weaponbox", "CWeaponBox_Use", .Post = false)
    RegisterHam(Ham_ObjectCaps, "weaponbox", "CWeaponBox_ObjectCaps", .Post = false)

#if defined BLOCK_DEFAULT_TOUCH
    RegisterHookChain(RG_CWeaponBox_SetModel, "CWeaponBox_SetModel", .post = true)
#endif

    g_hHudSync = CreateHudSyncObj()
}

#if defined BLOCK_DEFAULT_TOUCH
    public CWeaponBox_SetModel(const pWeaponBox, const szModel[])
    {
        if (pWeaponBox > 0 && !(CANT_REPLACE_WEAPONS_BIT & BIT(any:rg_get_weaponbox_id(pWeaponBox))))
        {
            set_entvar(pWeaponBox, var_solid, SOLID_NOT)
        }
    }
#endif

public CWeaponBox_ObjectCaps(const pWeaponBox)
{
    if (pWeaponBox <= 0)
        return HAM_IGNORED

    SetHamReturnInteger(FCAP_ONOFF_USE)
    return HAM_SUPERCEDE
}

public CWeaponBox_Use(const pWeaponBox, const pPlayer, const pCaller, USE_TYPE:useType, Float:value)
{
    if (value == 0.0 || is_nullent(pWeaponBox) || !(get_entvar(pWeaponBox, var_flags) & FL_ONGROUND)
        /* || get_member(pWeaponBox, m_WeaponBox_bIsBomb) */ || !is_user_alive(pPlayer))
    {
        return
    }

    new any:iSlot = NONE_SLOT
    new pWeapon = GetWeaponBoxWeapon(pWeaponBox, iSlot)

    if (pWeapon == NULLENT || iSlot == NONE_SLOT)
    {
        return
    }
    
#if defined SHOW_HUD_INFO
    new pOwner = get_entvar(pWeaponBox, var_owner)
#endif

    if (is_nullent(get_member(pPlayer, m_rgpPlayerItems, iSlot)))
    {
        ExecuteHam(Ham_Touch, pWeaponBox, pPlayer)

        if (get_member(pWeapon, m_pPlayer) == pPlayer)
        {
#if defined SHOW_HUD_INFO
            ShowInfo(pPlayer, pOwner, pWeapon)
#endif
            // set_entvar(pWeaponBox, var_owner, pPlayer)
        }

        return
    }

    new pActiveItem = get_member(pPlayer, m_pActiveItem)

    if (is_nullent(pActiveItem))
    {
        return
    }

    new any:iId = get_member(pActiveItem, m_iId)

    if (CANT_REPLACE_WEAPONS_BIT & BIT(iId))
    {
        client_print(pPlayer, print_center, "You can't replace this weapon.")
        return
    }
#if defined REPLACE_ONLY_SAME_SLOT
    if (iSlot != ExecuteHam(Ham_Item_ItemSlot, pActiveItem))
    {
        client_print(pPlayer, print_center, "You can't replace this weapon.")
        return
    }
#endif
    if (user_has_weapon(pPlayer, get_member(pWeapon, m_iId)))
    {
        client_print(pPlayer, print_center, "You already own that weapon.")
        return
    }

    ExecuteHam(Ham_Item_Holster, pActiveItem, 1 /* skiplocal = false */)

    if (!ExecuteHam(Ham_RemovePlayerItem, pPlayer, pActiveItem))
    {
        return
    }

    if (!ExecuteHam(Ham_AddPlayerItem, pPlayer, pWeapon))
    {
        return
    }

    new szModel[26], pszAmmo1[32], szWeapon[20]

    new iBoxAmmo = get_member(pWeaponBox, m_WeaponBox_rgAmmo, 1 /* FirstAmmoSlot */)

    user_has_weapon(pPlayer, iId, 0)         // take item off hud (pev->weapons &= ~BIT(iId))
    
#if defined REPLACE_ONLY_SAME_SLOT
    new iAmmoId = ExecuteHam(Ham_Item_PrimaryAmmoIndex, pWeapon)
    new iPlayerAmmo = get_member(pPlayer, m_rgAmmo, iAmmoId)
    set_member(pPlayer, m_rgAmmo, 0, iAmmoId) // remove backpack ammo
#endif

    ExecuteHam(Ham_Item_AttachToPlayer, pWeapon, pPlayer)

    rg_get_iteminfo(pWeapon, ItemInfo_pszAmmo1, pszAmmo1, charsmax(pszAmmo1))
    ExecuteHam(Ham_GiveAmmo, pPlayer, iBoxAmmo, pszAmmo1, iBoxAmmo /* iMax = -1 */)

    emit_sound(pPlayer, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
#if defined SHOW_HUD_INFO
    ShowInfo(pPlayer, pOwner, pWeapon)
#endif
    if (!WeaponBox_RemoveWeapon(pWeaponBox, pWeapon, iSlot))
    {
        set_entvar(pWeaponBox, var_nextthink, get_gametime() + 0.1)
        return
    }

    set_entvar(pWeaponBox, var_owner, pPlayer)

    WeaponBox_PackWeapon(pWeaponBox, pActiveItem, iSlot)
#if defined REPLACE_ONLY_SAME_SLOT
    WeaponBox_PackAmmo(pWeaponBox, pszAmmo1, iPlayerAmmo)
#endif

    get_entvar(pActiveItem, var_classname, szWeapon, charsmax(szWeapon))

    if (szWeapon[10] == 'n') // weapon_mp5navy
    {
        szWeapon[10] = EOS
    }

    formatex(szModel, charsmax(szModel), "models/w_%s.mdl", szWeapon[7])
    engfunc(EngFunc_SetModel, pWeaponBox, szModel)
}

stock ShowInfo(pPlayer, pOwner, pWeapon)
{
    new szWeapon[20], szOwnerName[32], szBuffer[sizeof(szOwnerName) + sizeof(szWeapon) + 20]
    new TeamName:iTeam = TEAM_UNASSIGNED

    get_entvar(pWeapon, var_classname, szWeapon, charsmax(szWeapon))

    strtoupper(szWeapon)

    if (pOwner == pPlayer)
    {
        formatex(szBuffer, charsmax(szBuffer), "%s", szWeapon[7])
    }
    else if (is_user_connected(pOwner))
    {
        iTeam = get_member(pOwner, m_iTeam)
        get_user_name(pOwner, szOwnerName, charsmax(szOwnerName))
        formatex(szBuffer, charsmax(szBuffer), "%s's %s", szOwnerName, szWeapon[7])
    }

    set_hudmessage(g_vecTeamColors[iTeam][R], g_vecTeamColors[iTeam][G], g_vecTeamColors[iTeam][B],
        0.70, 0.80, 0, 1.0, 4.0)

    ShowSyncHudMsg(pPlayer, g_hHudSync, "You got %s", szBuffer)
}

stock GetWeaponBoxWeapon(const pWeaponBox, &any:iSlot = NONE_SLOT)
{
    for (new pWeapon, InventorySlotType:i = PRIMARY_WEAPON_SLOT; i <= C4_SLOT; i++)
    {
        if (i != KNIFE_SLOT
            && !is_nullent((pWeapon = get_member(pWeaponBox, m_WeaponBox_rgpPlayerItems, i))))
        {
            iSlot = i
            return pWeapon
        }
    }

    return NULLENT
}

stock bool:WeaponBox_RemoveWeapon(const pWeaponBox, const pItem, const iSlot)
{
    new pPrev = get_member(pWeaponBox, m_WeaponBox_rgpPlayerItems, iSlot)

    if (pPrev == pItem)
    {
        set_member(pWeaponBox, m_WeaponBox_rgpPlayerItems, get_member(pItem, m_pNext), iSlot)
        return true
    }

    while (pPrev > 0 && get_member(pPrev, m_pNext) != pItem) {
        set_member(pPrev, m_pNext, pPrev)
    }

    if (pPrev > 0)
    {
        set_member(pPrev, m_pNext, get_member(pItem, m_pNext))
        return true
    }

    return false
}

stock WeaponBox_PackWeapon(const pWeaponBox, const pWeapon, const iSlot)
{
    set_member(pWeaponBox, m_WeaponBox_rgpPlayerItems, pWeapon, iSlot)
    set_member(pWeapon, m_pNext, NULLENT)

    // never respawn
    set_entvar(pWeapon, var_spawnflags, SF_NORESPAWN)
    set_entvar(pWeapon, var_movetype, MOVETYPE_NONE)
    // set_entvar(pWeapon, var_solid, SOLID_NOT)     // set by "AttachToPlayer"
    // set_entvar(pWeapon, var_effects, EF_NODRAW)    // set by "AttachToPlayer"
    // set_entvar(pWeapon, var_modelindex, 0)        // set by "AttachToPlayer"
    // set_entvar(pWeapon, var_model, 0)            // set by "AttachToPlayer"
    set_entvar(pWeapon, var_owner, pWeaponBox)
    set_member(pWeapon, m_pPlayer, NULLENT)
}

stock WeaponBox_PackAmmo(const pWeaponBox, const pszAmmo1[], const iCount)
{
    if (iCount > 0)
    {
        set_member(pWeaponBox, m_WeaponBox_rgiszAmmo, pszAmmo1, 1 /* FirstAmmoSlot */)
        set_member(pWeaponBox, m_WeaponBox_rgAmmo, iCount, 1 /* FirstAmmoSlot */)
    }
}
 
Сообщения
278
Реакции
137
Pokemoshka,
Do you know that you are a king? Thanks! xd

+
ты знаешь, что ты король? Спасибо! хаxa
 
Статус
В этой теме нельзя размещать новые ответы.

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу