Custom weapon plugins (due to other fire sounds)

Сообщения
27
Реакции
6
So I have re-compiled all models and am willing to understand a thing or two about the amxx part.

1. Which functions of reapi could be applied on this code, for further optimization

2. What purpose does WEAPON_SECRETCODE serve?

PHP:
 set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
PHP:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>

#define PLUGIN "amxx weapons"
#define VERSION "1.0"
#define AUTHOR "edo"

#define V_MODEL "models/v_mdl.mdl"
#define P_MODEL "models/p_mdl.mdl"
#define W_MODEL "models/w_mdl.mdl"

#define CSW_BASEDON CSW_P228
#define weapon_basedon "weapon_p228"

#define DAMAGE 10.0
#define CLIP 30
#define BPAMMO 180
#define SPEED 1.0
#define RECOIL 1.0
#define RELOAD_TIME 1.0

#define SHOOT_ANIM 0
#define DRAW_ANIM 0
#define RELOAD_ANIM 0


#define WEAPON_SECRETCODE 156851
#define WEAPON_EVENT "events/p228.sc"
#define OLD_W_MODEL "models/w_p228.mdl"
#define FIRE_SOUND "weapons/mdl-1.wav"



new g_Had_Weapon, g_Old_Weapon[33], Float:g_Recoil[33][3], g_Clip[33]
new g_weapon_event, g_ShellId, g_SmokePuff_SprId
new g_HamBot, g_Msg_CurWeapon

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
   
    register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)   
    register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")   
    register_forward(FM_SetModel, "fw_SetModel")   
   
    RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
    RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")
    RegisterHam(Ham_Weapon_PrimaryAttack, weapon_basedon, "fw_Weapon_PrimaryAttack")
    RegisterHam(Ham_Weapon_PrimaryAttack, weapon_basedon, "fw_Weapon_PrimaryAttack_Post", 1)
    RegisterHam(Ham_Item_AddToPlayer, weapon_basedon, "fw_Item_AddToPlayer_Post", 1)
    RegisterHam(Ham_Weapon_Reload, weapon_basedon, "fw_Weapon_Reload")
    RegisterHam(Ham_Weapon_Reload, weapon_basedon, "fw_Weapon_Reload_Post", 1)
    RegisterHam(Ham_Item_PostFrame, weapon_basedon, "fw_Item_PostFrame")       
   
    g_Msg_CurWeapon = get_user_msgid("CurWeapon")
    register_clcmd("give_wpn", "Get_Weapon")
}

public plugin_precache()
{
    engfunc(EngFunc_PrecacheModel, V_MODEL)
    engfunc(EngFunc_PrecacheModel, P_MODEL)
    engfunc(EngFunc_PrecacheModel, W_MODEL)
    engfunc(EngFunc_PrecacheSound, FIRE_SOUND)
   
    g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
    g_ShellId = engfunc(EngFunc_PrecacheModel, "models/rshell.mdl")   
   
    register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
   

}

public fw_PrecacheEvent_Post(type, const name[])
{
    if(equal(WEAPON_EVENT, name))
        g_weapon_event = get_orig_retval()       
}

public client_putinserver(id)
{
    if(!g_HamBot && is_user_bot(id))
    {
        g_HamBot = 1
        set_task(0.1, "Do_RegisterHam", id)
    }
}

public Do_RegisterHam(id)
{
    RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")   
}


public Get_Weapon(id)
{
    if(!is_user_alive(id))
        return
       
    Set_BitVar(g_Had_Weapon, id)
    fm_give_item(id, weapon_basedon)   
   
    // Set Ammo
    static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASEDON)
    if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, CLIP)
   
    cs_set_user_bpammo(id, CSW_BASEDON,BPAMMO)
   
    engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, g_Msg_CurWeapon, {0, 0, 0}, id)
    write_byte(1)
    write_byte(CSW_BASEDON)
    write_byte(CLIP)
    message_end()   
}

public Remove_Weapon(id)
{
    UnSet_BitVar(g_Had_Weapon, id)
}

public Event_CurWeapon(id)
{
    if(!is_user_alive(id))
        return
   
    static CSWID; CSWID = read_data(2)
   
    if((CSWID == CSW_BASEDON && g_Old_Weapon[id] != CSW_BASEDON) && Get_BitVar(g_Had_Weapon, id))
    {
        set_pev(id, pev_viewmodel2, V_MODEL)
        set_pev(id, pev_weaponmodel2, "")
       
        set_weapon_anim(id, DRAW_ANIM)
        Draw_NewWeapon(id, CSWID)
    } else if((CSWID == CSW_BASEDON && g_Old_Weapon[id] == CSW_BASEDON) && Get_BitVar(g_Had_Weapon, id)) {
        static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASEDON)
        if(!pev_valid(Ent))
        {
            g_Old_Weapon[id] = get_user_weapon(id)
            return
        }
       
        set_pdata_float(Ent, 46, get_pdata_float(Ent, 46, 4) * SPEED, 4)
    } else if(CSWID != CSW_BASEDON && g_Old_Weapon[id] == CSW_BASEDON) Draw_NewWeapon(id, CSWID)
   
    g_Old_Weapon[id] = get_user_weapon(id)
}

public Draw_NewWeapon(id, CSW_ID)
{
    if(CSW_ID == CSW_BASEDON)
    {
        static ent
        ent = fm_get_user_weapon_entity(id, CSW_BASEDON)
       
        if(pev_valid(ent) && Get_BitVar(g_Had_Weapon, id))
        {
            set_pev(ent, pev_effects, pev(ent, pev_effects) &~ EF_NODRAW)
            engfunc(EngFunc_SetModel, ent, P_MODEL)   
           
        }
    } else {
        static ent
        ent = fm_get_user_weapon_entity(id, CSW_BASEDON)
       
        if(pev_valid(ent)) set_pev(ent, pev_effects, pev(ent, pev_effects) | EF_NODRAW)            
    }
   
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
    if(!is_user_alive(id))
        return FMRES_IGNORED   
    if(get_user_weapon(id) == CSW_BASEDON && Get_BitVar(g_Had_Weapon, id))
        set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
   
    return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
    if (!is_user_connected(invoker))
        return FMRES_IGNORED   
    if(get_user_weapon(invoker) != CSW_BASEDON || !Get_BitVar(g_Had_Weapon, invoker))
        return FMRES_IGNORED
    if(eventid != g_weapon_event)
        return FMRES_IGNORED
   
    engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
   
    set_weapon_anim(invoker, SHOOT_ANIM)
    emit_sound(invoker, CHAN_WEAPON, FIRE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
   
    Eject_Shell(invoker, g_ShellId, 0.0)
       
    return FMRES_SUPERCEDE
}

public fw_SetModel(entity, model[])
{
    if(!pev_valid(entity))
        return FMRES_IGNORED
   
    static Classname[32]
    pev(entity, pev_classname, Classname, sizeof(Classname))
   
    if(!equal(Classname, "weaponbox"))
        return FMRES_IGNORED
   
    static iOwner
    iOwner = pev(entity, pev_owner)
   
    if(equal(model, OLD_W_MODEL))
    {
        static weapon; weapon = fm_find_ent_by_owner(-1, weapon_basedon, entity)
       
        if(!pev_valid(weapon))
            return FMRES_IGNORED;
       
        if(Get_BitVar(g_Had_Weapon, iOwner))
        {
            Remove_Weapon(iOwner)
           
            set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
            engfunc(EngFunc_SetModel, entity, W_MODEL)
           
            return FMRES_SUPERCEDE
        }
    }

    return FMRES_IGNORED;
}

public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
{
    if(!is_user_connected(Attacker))
        return HAM_IGNORED   
    if(get_user_weapon(Attacker) != CSW_BASEDON || !Get_BitVar(g_Had_Weapon, Attacker))
        return HAM_IGNORED
       
    static Float:flEnd[3], Float:vecPlane[3]
   
    get_tr2(Ptr, TR_vecEndPos, flEnd)
    get_tr2(Ptr, TR_vecPlaneNormal, vecPlane)       
       
    Make_BulletHole(Attacker, flEnd, Damage)
    Make_BulletSmoke(Attacker, Ptr)

    SetHamParamFloat(3, DAMAGE)
   
    return HAM_IGNORED
}

public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
{
    if(!is_user_connected(Attacker))
        return HAM_IGNORED   
    if(get_user_weapon(Attacker) != CSW_BASEDON || !Get_BitVar(g_Had_Weapon, Attacker))
        return HAM_IGNORED
       
    SetHamParamFloat(3, DAMAGE)

    return HAM_IGNORED
}

public fw_Weapon_PrimaryAttack(Ent)
{
    static id; id = pev(Ent, pev_owner)
    pev(id, pev_punchangle, g_Recoil[id])
   
    return HAM_IGNORED
}

public fw_Weapon_PrimaryAttack_Post(Ent)
{
    static id; id = pev(Ent, pev_owner)
   
    if(Get_BitVar(g_Had_Weapon, id))
    {
        static Float:Push[3]
        pev(id, pev_punchangle, Push)
        xs_vec_sub(Push, g_Recoil[id], Push)
       
        xs_vec_mul_scalar(Push, RECOIL, Push)
        xs_vec_add(Push, g_Recoil[id], Push)
        set_pev(id, pev_punchangle, Push)
    }
}

public fw_Item_AddToPlayer_Post(ent, id)
{
    if(!pev_valid(ent))
        return HAM_IGNORED
       
    if(pev(ent, pev_impulse) == WEAPON_SECRETCODE)
    {
        Set_BitVar(g_Had_Weapon, id)
        set_pev(ent, pev_impulse, 0)
    }       

    return HAM_HANDLED   
}

public fw_Item_PostFrame(ent)
{
    if(!pev_valid(ent))
        return HAM_IGNORED
   
    static id
    id = pev(ent, pev_owner)
   
    if(is_user_alive(id) && Get_BitVar(g_Had_Weapon, id))
    {   
        static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
        static bpammo; bpammo = cs_get_user_bpammo(id, CSW_BASEDON)
        static iClip; iClip = get_pdata_int(ent, 51, 4)
        static fInReload; fInReload = get_pdata_int(ent, 54, 4)
       
        if(fInReload && flNextAttack <= 0.0)
        {
            static temp1; temp1 = min(CLIP - iClip, bpammo)

            set_pdata_int(ent, 51, iClip + temp1, 4)
            cs_set_user_bpammo(id, CSW_BASEDON, bpammo - temp1)       
           
            set_pdata_int(ent, 54, 0, 4)
           
            fInReload = 0
        }       
    }
   
    return HAM_IGNORED   
}

public fw_Weapon_Reload(ent)
{
    static id; id = pev(ent, pev_owner)
    if(!is_user_alive(id))
        return HAM_IGNORED
    if(!Get_BitVar(g_Had_Weapon, id))
        return HAM_IGNORED
   
    g_Clip[id] = -1
   
    static bpammo; bpammo = cs_get_user_bpammo(id, CSW_BASEDON)
    static iClip; iClip = get_pdata_int(ent, 51, 4)
   
    if(bpammo <= 0) return HAM_SUPERCEDE
   
    if(iClip >= CLIP) return HAM_SUPERCEDE       
       
    g_Clip[id] = iClip

    return HAM_HANDLED
}

public fw_Weapon_Reload_Post(ent)
{
    static id; id = pev(ent, pev_owner)
    if(!is_user_alive(id))
        return HAM_IGNORED
    if(!Get_BitVar(g_Had_Weapon, id))
        return HAM_IGNORED

    if (g_Clip[id] == -1)
        return HAM_IGNORED
   
    set_pdata_int(ent, 51, g_Clip[id], 4)
    set_pdata_int(ent, 54, 1, 4)
   
    set_weapon_anim(id, RELOAD_ANIM)
    set_pdata_float(id, 83, RELOAD_TIME, 5)

    return HAM_HANDLED
}

stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
{
    // Find target
    static Decal; Decal = random_num(41, 45)
    static LoopTime;
   
    if(Damage > 100.0) LoopTime = 2
    else LoopTime = 1
   
    for(new i = 0; i < LoopTime; i++)
    {
        // Put decal on "world" (a wall)
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_WORLDDECAL)
        engfunc(EngFunc_WriteCoord, Origin[0])
        engfunc(EngFunc_WriteCoord, Origin[1])
        engfunc(EngFunc_WriteCoord, Origin[2])
        write_byte(Decal)
        message_end()
       
        // Show sparcles
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_GUNSHOTDECAL)
        engfunc(EngFunc_WriteCoord, Origin[0])
        engfunc(EngFunc_WriteCoord, Origin[1])
        engfunc(EngFunc_WriteCoord, Origin[2])
        write_short(id)
        write_byte(Decal)
        message_end()
    }
}

public Make_BulletSmoke(id, TrResult)
{
    static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
   
    get_weapon_attachment(id, vecSrc)
    global_get(glb_v_forward, vecEnd)
   
    xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
    xs_vec_add(vecSrc, vecEnd, vecEnd)

    get_tr2(TrResult, TR_vecEndPos, vecSrc)
    get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
   
    xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
    xs_vec_add(vecSrc, vecEnd, vecEnd)
   
    TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
    TE_FLAG |= TE_EXPLFLAG_NOSOUND
    TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
   
    engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
    write_byte(TE_EXPLOSION)
    engfunc(EngFunc_WriteCoord, vecEnd[0])
    engfunc(EngFunc_WriteCoord, vecEnd[1])
    engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
    write_short(g_SmokePuff_SprId)
    write_byte(2)
    write_byte(50)
    write_byte(TE_FLAG)
    message_end()
}


stock hook_ent2(ent, Float:VicOrigin[3], Float:speed, Float:multi, type)
{
    static Float:fl_Velocity[3]
    static Float:EntOrigin[3]
    static Float:EntVelocity[3]
   
    pev(ent, pev_velocity, EntVelocity)
    pev(ent, pev_origin, EntOrigin)
    static Float:distance_f
    distance_f = get_distance_f(EntOrigin, VicOrigin)
   
    static Float:fl_Time; fl_Time = distance_f / speed
    static Float:fl_Time2; fl_Time2 = distance_f / (speed * multi)
   
    if(type == 1)
    {
        fl_Velocity[0] = ((VicOrigin[0] - EntOrigin[0]) / fl_Time2) * 1.5
        fl_Velocity[1] = ((VicOrigin[1] - EntOrigin[1]) / fl_Time2) * 1.5
        fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time       
    } else if(type == 2) {
        fl_Velocity[0] = ((EntOrigin[0] - VicOrigin[0]) / fl_Time2) * 1.5
        fl_Velocity[1] = ((EntOrigin[1] - VicOrigin[1]) / fl_Time2) * 1.5
        fl_Velocity[2] = (EntOrigin[2] - VicOrigin[2]) / fl_Time
    }

    xs_vec_add(EntVelocity, fl_Velocity, fl_Velocity)
    set_pev(ent, pev_velocity, fl_Velocity)
}

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{
    static Float:vfEnd[3], viEnd[3]
    get_user_origin(id, viEnd, 3) 
    IVecFVec(viEnd, vfEnd)
   
    static Float:fOrigin[3], Float:fAngle[3]
   
    pev(id, pev_origin, fOrigin)
    pev(id, pev_view_ofs, fAngle)
   
    xs_vec_add(fOrigin, fAngle, fOrigin)
   
    static Float:fAttack[3]
   
    xs_vec_sub(vfEnd, fOrigin, fAttack)
    xs_vec_sub(vfEnd, fOrigin, fAttack)
   
    static Float:fRate
   
    fRate = fDis / vector_length(fAttack)
    xs_vec_mul_scalar(fAttack, fRate, fAttack)
   
    xs_vec_add(fOrigin, fAttack, output)
}

stock Eject_Shell(id, Shell_ModelIndex, Float:Time) // By Dias
{
    static Ent; Ent = get_pdata_cbase(id, 373, 5)
    if(!pev_valid(Ent))
        return

        set_pdata_int(Ent, 57, Shell_ModelIndex, 4)
        set_pdata_float(id, 111, get_gametime() + Time)
}

stock set_weapon_anim(id, anim)
{
    if(!is_user_alive(id))
        return
   
    set_pev(id, pev_weaponanim, anim)
   
    message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
    write_byte(anim)
    write_byte(pev(id, pev_body))
    message_end()
}
 
Сообщения
2,491
Реакции
2,794
Помог
61 раз(а)
djbosma, regarding WEAPON_SECRETCODE yes it's unique defined by you. Limit is the same as int32 (check on wiki for actual values because I don't remember). But it's not an HL weapon ID.
 
Сообщения
2,491
Реакции
2,794
Помог
61 раз(а)
w0w, it's not fully custom weapon. Only existing modification. Not related to his topic.
 
Сообщения
2,491
Реакции
2,794
Помог
61 раз(а)
djbosma, it's need a lot of time to type all things that can be changed. I haven't these time. First try to remove CurWeapon hook by settings p_ and v_ models in Ham_Item_Deploy hook, and setting speed Ham_CS_Item_GetMaxSpeed. Also, RG_CWeaponBox_SetModel will help you to easy change w_ model and remove FM_SetModel hook which calls a lot of times
16 Апр 2020
And Ham_CS_Weapon_SendWeaponAnim is good choice to hook/send animations
 
Сообщения
27
Реакции
6
Great, I'm looking for a good way to replace the weapon shooting sounds, any resolution on that one?
 
Сообщения
27
Реакции
6
Since I can't reproduce a valid way of changing shooting sounds on weapons, I have decided to compromise and just replace the models of the custom weapons. (reload, clip-in-out and draw sound plays on 176kbps, but not the shooting sound).

I am experiencing a weird issue with almost any plugin that replaces weapons now.. I've looked everywhere and still can't solve the issue.

The plugin is running, all meta modules online, yet models are downloaded when joining but do not load (still using default model)

PHP:
; Format: "old model" "new model" (without 'models/' & '.mdl')
"v_ak47" "DEX/weapons/v_ak47"
"p_ak47" "DEX/weapons/p_ak47"
"w_ak47" "DEX/weapons/w_ak47"
PHP:
// #define SET_MODELINDEX


#define MAX_MODEL_LEN        64
#define MAX_PATH_LEN         128
#define MAX_PLAYERS            32
#define MAX_BUFFER_LEN        MAX_MODEL_LEN + MAX_MODEL_LEN


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

#define VERSION "0.0.2"

#define UserValidTeam(%1)             (TEAM_TERRORIST <= get_member(%1, m_iTeam) <= TEAM_CT)
#define AllocString(%1)             engfunc(EngFunc_AllocString,%1)
#define SetModel(%1,%2)             engfunc(EngFunc_SetModel,%1,%2)
#define IsPlayer(%1)                (1 <= %1 <= g_iMaxPlayers)

#define SetUserModeled(%1)            g_bModeled |= 1<<(%1 & 31)
#define SetUserNotModeled(%1)        g_bModeled &= ~( 1<<(%1 & 31))
#define IsUserModeled(%1)            (g_bModeled &  1<<(%1 & 31))

#define SetUserConnected(%1)        g_bConnected |= 1<<(%1 & 31)
#define SetUserNotConnected(%1)        g_bConnected &= ~( 1<<(%1 & 31))
#define IsUserConnected(%1)            (g_bConnected &  1<<(%1 & 31))

const ClCorpse_ModelName = 1
const ClCorpse_PlayerID = 12

const g_ulModelIndexPlayer = 491

new const MODEL[] = "model"
new const g_szMapEntitys[][] = {"cycler_sprite", "cycler", "armoury_entity"}

new const g_szDefaultModels[][] = {"", "urban", "terror", "leet", "arctic", 
    "gsg9", "gign", "sas", "guerilla", "vip", "militia", "spetsnaz"
}

new const g_szWeaponNames[CSW_P90+1][] = {"","p228","","scout","hegrenade","xm1014","c4","mac10",
    "aug","smokegrenade","elite","fiveseven","ump45","sg550","galil","famas","usp","glock18","awp",
    "mp5navy","m249","m3","m4a1","tmp","g3sg1","flashbang","deagle","sg552","ak47","knife","p90"
}

new g_iWeaponIds[CSW_P90+1]

new Trie:g_tDefaultModels, Trie:g_tModelIndexes, Trie:g_tMapModels
new Trie:g_tViewModels, Trie:g_tWeaponModels, Trie:g_tWorldModels

new g_bConnected, g_bModeled, g_iMaxPlayers, bool:g_bPlayerModels
new g_szCurrentModel[MAX_PLAYERS+1][MAX_MODEL_LEN]


public plugin_init()
{
    register_plugin("Models Replacement", VERSION, "ConnorMcLeod | Vaqtincha")

    if(g_bPlayerModels)
    {
        register_forward(FM_SetClientKeyValue, "SetClientKeyValue_Pre", 0)
        register_message(get_user_msgid("ClCorpse"), "Message_ClCorpse")
    }
    if(g_tWorldModels)
    {
        register_forward(FM_SetModel, "SetModel_Pre", 0)
    }
    if(g_tMapModels)
    {
        SetMapModels()
    }
    g_iMaxPlayers = get_maxplayers()
}

public plugin_precache()
{
    new szConfigFile[MAX_PATH_LEN]
    get_localinfo("amxx_configsdir", szConfigFile, charsmax(szConfigFile))
    add(szConfigFile, charsmax(szConfigFile), "/models_replacement.ini")

    if(file_exists(szConfigFile))
    {
        new iFile = fopen(szConfigFile, "rt")
        if(!iFile)
        {
            set_fail_state("[MODELS_REPLACEMENT] ERROR: Failed reading file!")
            return
        }
        new szDatas[MAX_BUFFER_LEN + 10], szWeaponClass[32], iId, c
        new szOldModel[MAX_MODEL_LEN], szNewModel[MAX_MODEL_LEN]

        new Trie:tRegisterWeaponDeploy = TrieCreate()
        new Trie:tWeaponsIds = TrieCreate()
        g_tModelIndexes = TrieCreate()
        g_tDefaultModels = TrieCreate()

        for(new i = 1; i<sizeof(g_szDefaultModels); i++)
        {
            TrieSetCell(g_tDefaultModels, g_szDefaultModels[i], i)
        }
        for(new i = CSW_P228; i <= CSW_P90; i++)
        {
            TrieSetCell(tWeaponsIds, g_szWeaponNames[i], g_iWeaponIds[i])
        }

        while(!feof(iFile))
        {
            fgets(iFile, szDatas, charsmax(szDatas))
            trim(szDatas)

            if(!(c = szDatas[0]) || c == ';' || c == '#')
            {
                continue
            }
            if(parse(szDatas, szOldModel, charsmax(szOldModel), szNewModel, charsmax(szNewModel)) != 2)
            {
                continue
            }
            if(!szOldModel[0] || !szNewModel[0] || equal(szNewModel, szOldModel))
            {
                continue
            }
            if(TrieKeyExists(g_tDefaultModels, szOldModel))
            {
                if(PrecachePlayerModel(szNewModel))
                {
                    TrieSetString(g_tDefaultModels, szOldModel, szNewModel)
                    g_bPlayerModels = true
                }
            }else{
                if(((c = szOldModel[0]) == 'p' || c == 'v' ) && szOldModel[1] == '_')
                {
                    if(equal(szOldModel[2], "mp5", 3))
                    {
                        copy(szWeaponClass, charsmax(szWeaponClass), "weapon_mp5navy")
                    }else{
                        formatex(szWeaponClass, charsmax(szWeaponClass), "weapon_%s", szOldModel[2])
                    }

                    if(!TrieGetCell(tWeaponsIds, szWeaponClass[7], iId))
                    {
                        server_print("[MODELS_REPLACEMENT] WARNING: Invalid weapon class ^"%s^" will be skipped!", szWeaponClass)
                        continue
                    }
                    if(!TrieKeyExists(tRegisterWeaponDeploy, szWeaponClass))
                    {
                        TrieSetCell
                        (
                            tRegisterWeaponDeploy,
                            szWeaponClass,
                            RegisterHam(Ham_Item_Deploy, szWeaponClass, "ItemDeploy_Post", true)
                        )
                    }

                    format(szNewModel, charsmax(szNewModel), "models/%s.mdl", szNewModel)
                    if(c == 'v')
                    {
                        if(!g_tViewModels)
                        {
                            g_tViewModels = TrieCreate()
                        }
                        if(PrecacheWeaponModel(szNewModel))
                        {
                            TrieSetCell(g_tViewModels, szWeaponClass, AllocString(szNewModel))
                        }
                    }else{
                        if(!g_tWeaponModels)
                        {
                            g_tWeaponModels = TrieCreate()
                        }
                        if(PrecacheWeaponModel(szNewModel))
                        {
                            TrieSetCell(g_tWeaponModels, szWeaponClass, AllocString(szNewModel))
                        }
                    }
                }else{
                    format(szOldModel, charsmax(szOldModel), "models/%s.mdl", szOldModel)
                    format(szNewModel, charsmax(szNewModel), "models/%s.mdl", szNewModel)

                    if(c == 'w')
                    {
                        if(!g_tWorldModels)
                        {
                            g_tWorldModels = TrieCreate()
                        }
                        else if(TrieKeyExists(g_tWorldModels, szOldModel))
                        {
                            continue
                        }
                        if(PrecacheWeaponModel(szNewModel))
                        {
                            TrieSetString(g_tWorldModels, szOldModel, szNewModel)
                        }
                    }
                }
                if(!g_tMapModels)
                {
                    g_tMapModels = TrieCreate()
                }
                if(PrecacheWeaponModel(szNewModel))
                {
                    TrieSetString(g_tMapModels, szOldModel, szNewModel)
                }
            }
        }

        fclose(iFile)
        TrieDestroy(tRegisterWeaponDeploy)
        TrieDestroy(tWeaponsIds)
    }else{
        new iFile = fopen(szConfigFile, "w")
        if(!iFile)
        {
            set_fail_state("[MODELS_REPLACEMENT] ERROR: Failed creating file!")
            return
        }

        fputs(iFile, "^n; Format: ^"old model^" ^"new model^" (without 'models/' & '.mdl')^n;^n; Examples:^n")
        fputs(iFile, "^n; ^"arctic^" ^"vip^"^n; ^"chick^" ^"winebottle^"")
        fputs(iFile, "^n; ^"v_awp^" ^"custom/v_awp^"^n; ^"p_awp^" ^"custom/p_awp^"^n; ^"w_awp^" ^"custom/w_awp^"")

        fclose(iFile)
    }
}

public client_putinserver(id)
{
    if(!is_user_hltv(id))
    {
        SetUserConnected(id)
    }
}

public client_disconnected(id)
{
    SetUserNotModeled(id)
    SetUserNotConnected(id)
}

public ItemDeploy_Post(wEnt)
{
    if(wEnt <= 0)
    {
        return
    }
    
    new id = get_member(wEnt, m_pPlayer)
    if(IsPlayer(id))
    {
        new iszNewModel, szWeaponClass[32]
        set_entvar(wEnt, var_classname, szWeaponClass, charsmax(szWeaponClass))

        if(g_tViewModels && TrieGetCell(g_tViewModels, szWeaponClass, iszNewModel))
        {
            set_entvar(id, var_viewmodel, iszNewModel)
        }
        if(g_tWeaponModels && TrieGetCell(g_tWeaponModels, szWeaponClass, iszNewModel))
        {
            set_entvar(id, var_weaponmodel, iszNewModel)
        }
    }
}

public SetModel_Pre(iEnt, const szModel[])
{
    /* if(!pev_valid(iEnt))
    {
        return FMRES_IGNORED
    } */

    new szNewModel[MAX_MODEL_LEN]
    if(TrieGetString(g_tWorldModels, szModel, szNewModel, charsmax(szNewModel)))
    {
        SetModel(iEnt, szNewModel)
        return FMRES_SUPERCEDE
    }
    return FMRES_IGNORED
}

public SetClientKeyValue_Pre(id, const szInfoBuffer[], const szKey[], const szValue[])
{
    if(!equal(szKey, MODEL) || !IsUserConnected(id) || !UserValidTeam(id))
    {
        return FMRES_IGNORED
    }

    new szSupposedModel[MAX_MODEL_LEN]
    if(TrieGetString(g_tDefaultModels, szValue, szSupposedModel, charsmax(szSupposedModel)))
    {
        if(szSupposedModel[0])
        {
            if(!IsUserModeled(id) || !equal(g_szCurrentModel[id], szSupposedModel) || !equal(szValue, szSupposedModel))
            {
                copy(g_szCurrentModel[id], MAX_MODEL_LEN-1, szSupposedModel)
                SetUserModeled(id)
                set_user_info(id, MODEL, szSupposedModel)
            #if defined SET_MODELINDEX
                new iModelIndex
                TrieGetCell(g_tModelIndexes, szSupposedModel, iModelIndex)
                // set_pev(id, pev_modelindex, iModelIndex); // is this needed ?
                set_member(id, m_modelIndexPlayer, iModelIndex)
            #endif
                return FMRES_SUPERCEDE
            }
        }

        if(IsUserModeled(id))
        {
            SetUserNotModeled(id)
            g_szCurrentModel[id][0] = 0
        }
    }
    return FMRES_IGNORED
}

public Message_ClCorpse()
{
    new id = get_msg_arg_int(ClCorpse_PlayerID)
    if(IsUserModeled(id))
    {
        set_msg_arg_string(ClCorpse_ModelName, g_szCurrentModel[id])
    }
}

public plugin_end()
{
    if(g_tModelIndexes)
    {
        TrieDestroy(g_tModelIndexes)
    }
    if(g_tViewModels)
    {
        TrieDestroy(g_tViewModels)
    }
    if(g_tWeaponModels)
    {
        TrieDestroy(g_tWeaponModels)
    }
    if(g_tWorldModels)
    {
        TrieDestroy(g_tWorldModels)
    }
    if(g_tMapModels)
    {
        TrieDestroy(g_tMapModels)
    }
}

SetMapModels()
{
    new iEnt = FM_NULLENT
    new szSupposedModel[MAX_MODEL_LEN], szModel[MAX_MODEL_LEN]

    for(new i = 0; i <sizeof(g_szMapEntitys); i++)
    {
        while((iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", g_szMapEntitys[i])))
        {
            get_entvar(iEnt, var_model, szModel, charsmax(szModel));
            if(TrieGetString(g_tMapModels, szModel, szSupposedModel, charsmax(szSupposedModel)))
            {
                SetModel(iEnt, szSupposedModel)
            }
        }
    }
}

PrecacheWeaponModel(const szModel[])
{
    new szMsg[MAX_MODEL_LEN + 64]

    if(!file_exists(szModel))
    {
        formatex(szMsg, charsmax(szMsg), "[MODELS_REPLACEMENT] ERROR: Model ^"%s^" not found!", szModel)
        set_fail_state(szMsg)
        return 0
    }
    precache_model(szModel)
    return 1
}

PrecachePlayerModel(const szModel[])
{
    if(TrieKeyExists(g_tModelIndexes, szModel) || TrieKeyExists(g_tDefaultModels, szModel))
    {
        return 1
    }
    new szFileToPrecache[64], szMsg[MAX_MODEL_LEN + 64]
    formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%s.mdl", szModel, szModel)

    if(!file_exists(szFileToPrecache))
    {
        formatex(szMsg, charsmax(szMsg), "[MODELS_REPLACEMENT] ERROR: Player model ^"%s^" not found!", szFileToPrecache)
        set_fail_state(szMsg)
        return 0
    }

    TrieSetCell(g_tModelIndexes, szModel, precache_model(szFileToPrecache))

    formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%st.mdl", szModel, szModel)
    if(file_exists(szFileToPrecache))
    {
        precache_model(szFileToPrecache)
        return 1
    }
    formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%sT.mdl", szModel, szModel)
    if(file_exists(szFileToPrecache))
    {
        precache_model(szFileToPrecache)
        return 1
    }
    return 1
}
 
Сообщения
27
Реакции
6
You need to block prediction, event and other stuff. After that make all the same but without playback_event. It's hard
Ok then; I am hereby making a paid request for anyone who is willing to provide a plugin based on reapi which changes not only the weapon models but fire sounds as well with blocking prediction, so not both sounds will be played. I'm not limited to a certain budget - just want it made and done.
 

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

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