Raised This Month: $ Target: $400
 0% 

Reapi Weapon Models


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 07-20-2023 , 21:59   Reapi Weapon Models
Reply With Quote #1

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!
JuanitoAlimana is offline
Old 07-21-2023, 07:57
lexzor
This message has been deleted by lexzor. Reason: nvm
plychips
New Member
Join Date: Jul 2023
Old 07-21-2023 , 11:04   Re: Reapi Weapon Models
Reply With Quote #2

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
}

Last edited by plychips; 07-21-2023 at 11:09. Reason: a mistake made
plychips is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 07-21-2023 , 17:37   Re: Reapi Weapon Models
Reply With Quote #3

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 is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 07-21-2023 , 18:55   Re: Reapi Weapon Models
Reply With Quote #4

Quote:
Originally Posted by plychips View Post
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"
JuanitoAlimana is offline
plychips
New Member
Join Date: Jul 2023
Old 07-24-2023 , 06:29   Re: Reapi Weapon Models
Reply With Quote #5

send me a private message, and i will solve the problem
plychips is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 07-24-2023 , 19:49   Re: Reapi Weapon Models
Reply With Quote #6

Quote:
Originally Posted by plychips View Post
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!
JuanitoAlimana is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 07-25-2023 , 15:16   Re: Reapi Weapon Models
Reply With Quote #7

use PHP tag to highlight code
__________________
mlibre is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-26-2023 , 04:36   Re: Reapi Weapon Models
Reply With Quote #8

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

lexzor is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 07-27-2023 , 21:08   Re: Reapi Weapon Models
Reply With Quote #9

Quote:
Originally Posted by lexzor View Post
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)
JuanitoAlimana is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-28-2023 , 07:49   Re: Reapi Weapon Models
Reply With Quote #10

replace

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

with


Code:
static const V_MODELS[][] = static const P_MODELS[][] =
lexzor is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:45.


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