AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Reapi Weapon Models (https://forums.alliedmods.net/showthread.php?t=343403)

JuanitoAlimana 07-20-2023 21:59

Reapi Weapon Models
 
Hello. I've recently started using this weapon models replacement plugin but I can't seem to manage to make it so only users with ADMIN_LEVEL_A can use the skins. I'm not that familiar with ReAPI and everytime I try I get "Invalid player" errors and stuff. Here's the code.

PHP Code:

#include <amxmodx>
#include <reapi>

#define PLUGIN  "[Reapi] Replace Weapon Models"
#define VERSION "1.0"
#define AUTHOR  "[N]drs"

#define rg_get_weapon_id(%0) get_member(get_member(get_member(%0, m_pPlayer), m_pActiveItem), m_iId)

new const szV_Model[] = "models/custom/v_usp.mdl"
new const szP_Model[] = "models/custom/p_usp.mdl"


public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy"OnPlayerChangeWeapon_Pre"false)
}

public 
plugin_precache()
{
    
precache_model(szV_Model)
    
precache_model(szP_Model)
}

public 
OnPlayerChangeWeapon_Pre(const iEntityszViewModel[], szWeaponModel[])
{
    switch(
rg_get_weapon_id(iEntity))
    {
        case 
CSW_USP:
        {
            
SetHookChainArg(2ATYPE_STRINGszV_Model)
            
SetHookChainArg(3ATYPE_STRINGszP_Model)
        }
    }

    return 
HC_CONTINUE


If you guys can help me out, I will be extremely happy. Thanks!

plychips 07-21-2023 11:04

Re: Reapi Weapon Models
 
Sure, to achieve this, you'll need to have some way of checking if the current player is an admin with level ADMIN_LEVEL_A. I assume you're using an admin system that provides a function like get_user_flags(id) to check the flags of a user. If such function is available, you can modify the code like so:

#include <amxmodx>
#include <reapi>

#define PLUGIN "[Reapi] Replace Weapon Models"
#define VERSION "1.0"
#define AUTHOR "[N]drs"

#define rg_get_weapon_id(%0) get_member(get_member(get_member(%0, m_pPlayer), m_pActiveItem), m_iId)

new const szV_Model[] = "models/custom/v_usp.mdl"
new const szP_Model[] = "models/custom/p_usp.mdl"

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)

RegisterHookChain(RG_CBasePlayerWeapon_Defaul tDeploy, "OnPlayerChangeWeapon_Pre", false)
}

public plugin_precache()
{
precache_model(szV_Model)
precache_model(szP_Model)
}

public OnPlayerChangeWeapon_Pre(const iEntity, szViewModel[], szWeaponModel[])
{
// get player's ID from the entity
new iPlayerId = get_pdata_cbase(iEntity, 209, _, sizeof(_));

// check if the player is an admin and has ADMIN_LEVEL_A
if (!(get_user_flags(iPlayerId) & ADMIN_LEVEL_A))
return HC_CONTINUE;

switch(rg_get_weapon_id(iEntity))
{
case CSW_USP:
{
SetHookChainArg(2, ATYPE_STRING, szV_Model)
SetHookChainArg(3, ATYPE_STRING, szP_Model)
}
}

return HC_CONTINUE
}


Remember, you need to include the header file containing the definition of ADMIN_LEVEL_A and get_user_flags() function. Replace these names with the ones used in your project if they are different.

Also, if your admin system does not provide a function like get_user_flags(), you will need to write your own function to check the admin status and level of a player.

or try this plugin :

#include <amxmodx>
#include <fun>
#include <engine>

#define PLUGIN "Admin Weapon Skin"
#define VERSION "1.0"
#define AUTHOR "plychips"

#define USP_MODEL "models/v_usp_admin.mdl"

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("CurWeapon", "event_curweapon", "be", "2=1") // This event is fired when the player changes his weapon
}

public plugin_precache()
{
precache_model(USP_MODEL) // preloading the desired weapon model
}

public event_curweapon(id)
{
if(!is_user_admin(id)) // Check if the player is an admin
{
return PLUGIN_CONTINUE // If he is not, do nothing
}

new weapon = read_data(1)

if(weapon == CSW_USP) // If the current weapon is USP
{
set_pev(id, pev_viewmodel, USP_MODEL) // Change the weapon model to the admin model
}

return PLUGIN_CONTINUE
}

JuanitoAlimana 07-21-2023 17:37

Re: Reapi Weapon Models
 
I'll try "if (!(get_user_flags(iPlayerId) & ADMIN_LEVEL_A))". Every time I did it that way I got "Invalid Player". I'd rather user ReAPI, seems to be lighter. I find that the "CurWeapon" method slows the server a bit, specially when full. Thanks

JuanitoAlimana 07-21-2023 18:55

Re: Reapi Weapon Models
 
Quote:

Originally Posted by plychips (Post 2807535)
Sure, to achieve this, you'll need to have some way of checking if the current player is an admin with level ADMIN_LEVEL_A. I assume you're using an admin system that provides a function like get_user_flags(id) to check the flags of a user. If such function is available, you can modify the code like so:

#include <amxmodx>
#include <reapi>

#define PLUGIN "[Reapi] Replace Weapon Models"
#define VERSION "1.0"
#define AUTHOR "[N]drs"

#define rg_get_weapon_id(%0) get_member(get_member(get_member(%0, m_pPlayer), m_pActiveItem), m_iId)

new const szV_Model[] = "models/custom/v_usp.mdl"
new const szP_Model[] = "models/custom/p_usp.mdl"

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)

RegisterHookChain(RG_CBasePlayerWeapon_Defaul tDeploy, "OnPlayerChangeWeapon_Pre", false)
}

public plugin_precache()
{
precache_model(szV_Model)
precache_model(szP_Model)
}

public OnPlayerChangeWeapon_Pre(const iEntity, szViewModel[], szWeaponModel[])
{
// get player's ID from the entity
new iPlayerId = get_pdata_cbase(iEntity, 209, _, sizeof(_));

// check if the player is an admin and has ADMIN_LEVEL_A
if (!(get_user_flags(iPlayerId) & ADMIN_LEVEL_A))
return HC_CONTINUE;

switch(rg_get_weapon_id(iEntity))
{
case CSW_USP:
{
SetHookChainArg(2, ATYPE_STRING, szV_Model)
SetHookChainArg(3, ATYPE_STRING, szP_Model)
}
}

return HC_CONTINUE
}


Remember, you need to include the header file containing the definition of ADMIN_LEVEL_A and get_user_flags() function. Replace these names with the ones used in your project if they are different.

Also, if your admin system does not provide a function like get_user_flags(), you will need to write your own function to check the admin status and level of a player.

or try this plugin :

#include <amxmodx>
#include <fun>
#include <engine>

#define PLUGIN "Admin Weapon Skin"
#define VERSION "1.0"
#define AUTHOR "plychips"

#define USP_MODEL "models/v_usp_admin.mdl"

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("CurWeapon", "event_curweapon", "be", "2=1") // This event is fired when the player changes his weapon
}

public plugin_precache()
{
precache_model(USP_MODEL) // preloading the desired weapon model
}

public event_curweapon(id)
{
if(!is_user_admin(id)) // Check if the player is an admin
{
return PLUGIN_CONTINUE // If he is not, do nothing
}

new weapon = read_data(1)

if(weapon == CSW_USP) // If the current weapon is USP
{
set_pev(id, pev_viewmodel, USP_MODEL) // Change the weapon model to the admin model
}

return PLUGIN_CONTINUE
}

I get the following error when compiling: error 017: undefined symbol "get_pdata_cbase"

plychips 07-24-2023 06:29

Re: Reapi Weapon Models
 
send me a private message, and i will solve the problem

JuanitoAlimana 07-24-2023 19:49

Re: Reapi Weapon Models
 
Quote:

Originally Posted by plychips (Post 2807678)
send me a private message, and i will solve the problem

Post it right here so other people who are finding a similar plugin can have it too!

mlibre 07-25-2023 15:16

Re: Reapi Weapon Models
 
use PHP tag to highlight code

lexzor 07-26-2023 04:36

Re: Reapi Weapon Models
 
try this one,

position from array V/P_MODELS of the models must be the same as weaponid

PHP Code:

#include <amxmodx>
#include <reapi>

#define PLUGIN  "[Reapi] Replace Weapon Models"
#define VERSION "1.0"
#define AUTHOR  "[N]drs"

#define rg_get_weapon_id(%0) get_member(get_member(get_member(%0, m_pPlayer), m_pActiveItem), m_iId)

static const SKIN_FLAGS[] = "cd"

static const V_MODELS[] =
{
    
"path/to/v_model/",
    
"path/to/v_model/",
    
"path/to/v_model/",
    
"path/to/v_model/",
    
"path/to/v_model/",
}

static const 
P_MODELS[] =
{
    
"path/to/p_model/",
    
"path/to/p_model/",
    
"path/to/p_model/",
    
"path/to/p_model/",
    
"path/to/p_model/"
}

new 
bool:g_bCanHaveSkin[MAX_PLAYERS 1]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy"OnPlayerChangeWeapon_Pre"false)
}

public 
plugin_precache()
{
    for(new 
isizeof(V_MODELS); i++)
    {
        if(
file_exists(V_MODELS[i]))
        {
            
precache_model(V_MODELS[i])
        }
        else 
        {
            
server_print("Model %s does not exists"V_MODELS[i])
        }
    }

    for(new 
isizeof(P_MODELS); i++)
    {
        if(
file_exists(P_MODELS[i]))
        {
            
precache_model(P_MODELS[i])
        }
        else 
        {
            
server_print("Model %s does not exists"P_MODELS[i])
        }
    }
}

public 
client_putinserver(id)
{
    
g_bCanHaveSkin[id] = bool:(get_user_flags(id) & read_flags(SKIN_FLAGS))
}

public 
OnPlayerChangeWeapon_Pre(const idszViewModel[], szWeaponModel[])
{
    if(!
g_bCanHaveSkin[id])
    {
        return 
HC_CONTINUE
    
}

    static 
iWeaponID;
    
iWeaponID rg_get_weapon_id(id)
    
SetHookChainArg(2ATYPE_STRINGV_MODELS[iWeaponID])
    
SetHookChainArg(3ATYPE_STRINGP_MODELS[iWeaponID])

    return 
HC_CONTINUE



JuanitoAlimana 07-27-2023 21:08

Re: Reapi Weapon Models
 
Quote:

Originally Posted by lexzor (Post 2807768)
try this one,

position from array V/P_MODELS of the models must be the same as weaponid

PHP Code:

#include <amxmodx>
#include <reapi>

#define PLUGIN  "[Reapi] Replace Weapon Models"
#define VERSION "1.0"
#define AUTHOR  "[N]drs"

#define rg_get_weapon_id(%0) get_member(get_member(get_member(%0, m_pPlayer), m_pActiveItem), m_iId)

static const SKIN_FLAGS[] = "cd"

static const V_MODELS[] =
{
    
"path/to/v_model/",
    
"path/to/v_model/",
    
"path/to/v_model/",
    
"path/to/v_model/",
    
"path/to/v_model/",
}

static const 
P_MODELS[] =
{
    
"path/to/p_model/",
    
"path/to/p_model/",
    
"path/to/p_model/",
    
"path/to/p_model/",
    
"path/to/p_model/"
}

new 
bool:g_bCanHaveSkin[MAX_PLAYERS 1]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy"OnPlayerChangeWeapon_Pre"false)
}

public 
plugin_precache()
{
    for(new 
isizeof(V_MODELS); i++)
    {
        if(
file_exists(V_MODELS[i]))
        {
            
precache_model(V_MODELS[i])
        }
        else 
        {
            
server_print("Model %s does not exists"V_MODELS[i])
        }
    }

    for(new 
isizeof(P_MODELS); i++)
    {
        if(
file_exists(P_MODELS[i]))
        {
            
precache_model(P_MODELS[i])
        }
        else 
        {
            
server_print("Model %s does not exists"P_MODELS[i])
        }
    }
}

public 
client_putinserver(id)
{
    
g_bCanHaveSkin[id] = bool:(get_user_flags(id) & read_flags(SKIN_FLAGS))
}

public 
OnPlayerChangeWeapon_Pre(const idszViewModel[], szWeaponModel[])
{
    if(!
g_bCanHaveSkin[id])
    {
        return 
HC_CONTINUE
    
}

    static 
iWeaponID;
    
iWeaponID rg_get_weapon_id(id)
    
SetHookChainArg(2ATYPE_STRINGV_MODELS[iWeaponID])
    
SetHookChainArg(3ATYPE_STRINGP_MODELS[iWeaponID])

    return 
HC_CONTINUE




All models show:
Model odels/guns2024/p_scout.mdl does not exists
Model dels/guns2024/p_scout.mdl does not exists
Model els/guns2024/p_scout.mdl does not exists
Model ls/guns2024/p_scout.mdl does not exists
Model s/guns2024/p_scout.mdl does not exists
Model /guns2024/p_scout.mdl does not exists
Model guns2024/p_scout.mdl does not exists
Model uns2024/p_scout.mdl does not exists
Model ns2024/p_scout.mdl does not exists
Model s2024/p_scout.mdl does not exists
Model 2024/p_scout.mdl does not exists
Model 024/p_scout.mdl does not exists
Model 24/p_scout.mdl does not exists
Model 4/p_scout.mdl does not exists
Model /p_scout.mdl does not exists
Model p_scout.mdl does not exists
Model _scout.mdl does not exists
Model scout.mdl does not exists
Model cout.mdl does not exists
Model out.mdl does not exists
Model ut.mdl does not exists
Model t.mdl does not exists
Model .mdl does not exists
Model mdl does not exists
Model dl does not exists
Model l does not exists
Model does not exists

Also:
L 07/27/2023 - 21:05:42: [AMXX] Displaying debug trace (plugin "guns2024.amxx", version "1.0")
L 07/27/2023 - 21:05:42: [AMXX] Run time error 4: index out of bounds
L 07/27/2023 - 21:05:42: [AMXX] [0] guns2024.sma::OnPlayerChangeWeapon_Pre (line 87)

lexzor 07-28-2023 07:49

Re: Reapi Weapon Models
 
replace

Code:
static const V_MODELS[] = static const P_MODELS[] =

with


Code:
static const V_MODELS[][] = static const P_MODELS[][] =


All times are GMT -4. The time now is 08:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.