Any possible way to simply just replace and unprecache a player model?

Сообщения
9
Реакции
0
Hey, i've tried to make a unprecacher which, clearly, would prevent crashes from errors like "Host_Error: PF_setmodel_I" but i see that something is wrong.. i've hooked fakemeta and hooked SetModel but the error "Host_Error: PF_setmodel_I" shows up, that means that the function isn't called so, is there another alternative or something?

Код:
#include <amxmodx>
#include <fakemeta>
#include <reapi>
#include <cso>

#define PLUGIN  "Unprecacher"
#define VERSION "1.0"
#define AUTHOR  "DeclineD"

new const modelsandsprites[][] =
{
    "models/articorange.mdl",
    "models/articorangeT.mdl",
    "models/bag.mdl",
    "models/chick.mdl",
    "models/conveyor_turn.mdl",
    "models/conveyor1.mdl",
    "models/conveyor2.mdl",
    "models/conveyor3.mdl",
    "models/dummyguerilla.mdl",
    "models/feather.mdl",
    "models/fern.mdl",
    "models/guerilla.mdl",
    "models/head.mdl",
    "models/hostage.mdl",
    "models/hostage1.mdl",
    "models/hostage2.mdl",
    "models/hostage3.mdl",
    "models/hostage4.mdl",
    "models/hostage5.mdl",
    "models/hostage6.mdl",
    "models/hostage7.mdl",
    "models/hostage8.mdl",
    "models/lv_bottle.mdl",
    "models/orange.mdl",
    "models/oranget.mdl",
    "models/pallet.mdl",
    "models/pallet_with_bags.mdl",
    "models/pallet_with_bags2.mdl",
    "models/PG-150.mdl",
    "models/pi_fern.mdl",
    "models/pi_tree.mdl",
    "models/pi_tree1.mdl",
    "models/pi_tree2.mdl",
    "models/pi_tree3.mdl",
    "models/pi_treeb.mdl",
    "models/pi_twig.mdl",
    "models/player.mdl",
    "models/pred_plant.mdl",
    "models/rshell.mdl",
    "models/rshell_big.mdl",
    "models/pshell.mdl",
    "models/qloader.mdl",
    "models/qtruck.mdl",
    "models/support1.mdl",
    "models/support2.mdl",
    "models/support3.mdl",
    "models/truck.mdl",
    "models/winebottle.mdl",
    "sprites/c4.spr",
    "sprites/defuser.spr",
    "sprites/grass_01.spr",
    "sprites/grass_03.spr"
}
   
new const weaponpmodels[][] =
{
    "models/p_aug.mdl",
    "models/p_c4.mdl",
    "models/p_famas.mdl",
    "models/p_fiveseven.mdl",
    "models/p_flashbang.mdl",
    "models/p_m3super90.mdl",
    "models/p_mac10.mdl",
    "models/p_p90.mdl",
    "models/p_p228.mdl",
    "models/p_sg550.mdl",
    "models/p_sg552.mdl",
    "models/p_smokegrenade.mdl",
    "models/p_shield.mdl",
    "models/p_tmp.mdl",
    "models/p_ump45.mdl",
    "models/shield/p_shield_deagle.mdl",
    "models/shield/p_shield_fiveseven.mdl",
    "models/shield/p_shield_flashbang.mdl",
    "models/shield/p_shield_glock18.mdl",
    "models/shield/p_shield_hegrenade.mdl",
    "models/shield/p_shield_knife.mdl",
    "models/shield/p_shield_p228.mdl",
    "models/shield/p_shield_smokegrenade.mdl",
    "models/shield/p_shield_usp.mdl",
    "models/shield/p_shield_deagle.mdl"
}

new const weaponvmodels[][] =
{
    "models/v_aug.mdl",
    "models/v_c4.mdl",
    "models/v_famas.mdl",
    "models/v_fiveseven.mdl",
    "models/v_flashbang.mdl",
    "models/v_mac10.mdl",
    "models/v_p90.mdl",
    "models/v_p228.mdl",
    "models/v_sg550.mdl",
    "models/v_sg552.mdl",
    "models/v_smokegrenade.mdl",
    "models/v_shield_r.mdl",
    "models/v_tmp.mdl",
    "models/v_ump45.mdl",
    "models/shield/v_shield_deagle.mdl",
    "models/shield/v_shield_fiveseven.mdl",
    "models/shield/v_shield_flashbang.mdl",
    "models/shield/v_shield_glock18.mdl",
    "models/shield/v_shield_hegrenade.mdl",
    "models/shield/v_shield_knife.mdl",
    "models/shield/v_shield_p228.mdl",
    "models/shield/v_shield_smokegrenade.mdl",
    "models/shield/v_shield_usp.mdl",
    "models/shield/v_shield_deagle.mdl"
}

new const weaponworldmodels[][] =
{
    "models/w_aug.mdl",
    "models/w_c4.mdl",
    "models/w_famas.mdl",
    "models/w_fiveseven.mdl",
    "models/w_flashbang.mdl",
    "models/w_mac10.mdl",
    "models/w_p90.mdl",
    "models/w_p228.mdl",
    "models/w_sg550.mdl",
    "models/w_sg552.mdl",
    "models/w_smokegrenade.mdl",
    "models/w_shield.mdl",
    "models/w_tmp.mdl",
    "models/w_ump45.mdl",
    "models/w_knife.mdl",
    "models/w_backpack.mdl",
    "models/w_thighpack.mdl"
}

new const playermodels[][] =
{
    "artic",
    "gsg9",
    "guerilla",
    "leet",
    "sas",
    "terror",
    "gign",
    "vip",
    "urban"
}

new const player_replacementmodels[2][][] =
{
    {"david_black", "enzo", "gerard", "kreig"},
    {"ling_ling", "natalie", "soy", "alex"}
}

new const weaponscls[][] =
{
    "weapon_aug",
    "weapon_c4",
    "weapon_famas",
    "weapon_mac10",
    "weapon_flashbang",
    "weapon_fiveseven",
    "weapon_p90",
    "weapon_p228",
    "weapon_sg550",
    "weapon_sg552",
    "weapon_smokegrenade",
    "weapon_shield"
}

new unprecache_soundfwd, unprecache_modelfwd
new g_unprecachedmodels, g_precachedmodels
new g_unprecachedsounds, g_precachedsounds

new blocked = true

public plugin_precache()
{
    for(new i = 0; i < 2; i++)
    {
        for(new x = 0; x < sizeof player_replacementmodels[]; x++)
        {
            new model[100]
            formatex(model, charsmax(model), "models/player/%s/%s.mdl", player_replacementmodels[i][x], player_replacementmodels[i][x])
            precache_model(model)
        }
    }

    unprecache_modelfwd = register_forward(FM_PrecacheModel, "PrecacheModel")
    //unprecache_soundfwd = register_forward(FM_PrecacheSound, "PrecacheSound")
}

public plugin_init()
{
    unregister_forward(FM_PrecacheModel, unprecache_modelfwd)
    //unregister_forward(FM_PrecacheSound, unprecache_soundfwd)

    register_forward(FM_SetModel, "SetModel")
    register_forward(FM_Spawn, "Spawn")

    RegisterHookChain(RG_CBasePlayer_SetClientUserInfoModel, "SetClientUserInfoModel")
    RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy, "DefaultDeploy")
    RegisterHookChain(RG_RoundEnd, "RoundEnd")

    server_print("[CSO] Unprecached %i models and, probably, sprites and Precached %i models and, probably, sprites.", g_unprecachedmodels, g_precachedmodels)
}

public RoundEnd(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
    set_task(tmDelay-0.001, "BlockedOff")
}

public BlockedOff()
{
    blocked = false
    set_task(0.1, "BlockedOn")
}

public BlockedOn() blocked = true

public Spawn(id)
{
    if(blocked) return FMRES_IGNORED;

    new classname[50]
    pev(id, pev_classname, classname, charsmax(classname))

    for(new i = 0; i < sizeof(weaponscls); i++)
    {
        if(equal(classname, weaponscls[i]))
        {
            return FMRES_SUPERCEDE;
        }
    }

    return FMRES_IGNORED;
}

public PrecacheModel(model[])
{
    for(new i = 0; i < sizeof(playermodels); i++)
    {
        new model2[100]
        formatex(model2, charsmax(model2), "models/player/%s/%s.mdl", playermodels[i], playermodels[i])
        if(equal(model2, model))
        {
            g_unprecachedmodels++
            return FMRES_SUPERCEDE;
        }
    }
    for(new i = 0; i < sizeof(weaponworldmodels); i++)
    {
        if(equal(weaponworldmodels[i], model))
        {
            g_unprecachedmodels++
            return FMRES_SUPERCEDE;
        }
    }

    for(new i = 0; i < sizeof(weaponpmodels); i++)
    {
        if(equal(weaponpmodels[i], model))
        {
            g_unprecachedmodels++
            return FMRES_SUPERCEDE;
        }
    }

    for(new i = 0; i < sizeof(weaponvmodels); i++)
    {
        if(equal(weaponvmodels[i], model))
        {
            g_unprecachedmodels++
            return FMRES_SUPERCEDE;
        }
    }

    for(new i = 0; i < sizeof(modelsandsprites); i++)
    {
        if(equal(modelsandsprites[i], model))
        {
            g_unprecachedmodels++
            return FMRES_SUPERCEDE;
        }
    }
    g_precachedmodels++

    return FMRES_IGNORED;
}

public SetClientUserInfoModel(id, InfoBuffer[], newModel[])
{
    for(new i = 0; i < sizeof(playermodels); i++)
    {
        if(equal(newModel, playermodels[i]))
        {
            SetHookChainArg(3, ATYPE_STRING, player_replacementmodels[cso_get_gender(id)-1][random_num(0, sizeof(player_replacementmodels[])-1)])
            return HC_SUPERCEDE;
        }
    }

    return HC_CONTINUE;
}

public DefaultDeploy(id, szViewModel[], szWeaponModel[], iAnim, szAnimExt[], skiplocal)
{
    for(new i = 0; i < sizeof(weaponvmodels); i++)
    {
        if(equal(szViewModel, weaponvmodels[i]))
        {
            SetHookChainArg(2, ATYPE_STRING, "")
        }
    }

    for(new i = 0; i < sizeof(weaponpmodels); i++)
    {
        if(equal(szWeaponModel, weaponpmodels[i]))
        {
            SetHookChainArg(3, ATYPE_STRING, "")
        }
    }
}

public SetModel(id, model[])
{
    for(new i = 0; i < sizeof(weaponworldmodels); i++)
    {
        if(equal(model, weaponworldmodels[i]))
        {
            forward_return(FMV_CELL, 0)
            return FMRES_SUPERCEDE;
        }
    }

    for(new i = 0; i < sizeof(modelsandsprites); i++)
    {
        if(equal(model, modelsandsprites[i]))
        {
            forward_return(FMV_CELL, 0)
            return FMRES_SUPERCEDE;
        }
    }

    for(new i = 0; i < sizeof(playermodels); i++)
    {
        new model2[100]
        formatex(model2, charsmax(model2), "models/player/%s/%s.mdl", playermodels[i], playermodels[i])
        if(equal(model2, model))
        {
            forward_return(FMV_CELL, 0)
            return FMRES_SUPERCEDE;
        }
        else server_print("%s and %s", model2, model)
    }

    return FMRES_IGNORED;
}
P.S. :Already tried to register FM_SetModel in plugin_precache (in case anyone wants to suggest this)
 
Сообщения
9
Реакции
0
Nevermind, i see that the problem was that the player models "urban" and "terror" are some kind of important cs models that can't be unprecached.
And that's because they are used before any being send to any hook i think
 

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

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