This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Weapon Model Replacement


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 06-28-2023 , 21:59   Weapon Model Replacement
Reply With Quote #1

I'm using this weapon model replacement plugin. Is there a way that if the player buys or picks up a shield the model gets set to default or the ham is ignored? Somehow when somebody buys or picks up a shield the model gets bugged. Thanks!


PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <cstrike>

// Weapon entity names
new const WEAPONENTNAMES[][] = { """weapon_p228""""weapon_scout""weapon_hegrenade""weapon_xm1014""weapon_c4""weapon_mac10",
            
"weapon_aug""weapon_smokegrenade""weapon_elite""weapon_fiveseven""weapon_ump45""weapon_sg550",
            
"weapon_galil""weapon_famas""weapon_usp""weapon_glock18""weapon_awp""weapon_mp5navy""weapon_m249",
            
"weapon_m3""weapon_m4a1""weapon_tmp""weapon_g3sg1""weapon_flashbang""weapon_deagle""weapon_sg552",
            
"weapon_ak47""weapon_knife""weapon_p90" }
            
public 
plugin_init()
{
    
register_plugin("Weapon Model Replacement""0.0.1""ZP Dev")
    
    
//register Ham_Item_Deploy forward for all CS weapons
    
for (new 1sizeof WEAPONENTNAMESi++)
    {
        if (
WEAPONENTNAMES[i][0]) RegisterHam(Ham_Item_DeployWEAPONENTNAMES[i], "OnItemDeployPost"1);
    }
}

// Ham Weapon Deploy Forward
public OnItemDeployPost(ent)
{
    
// Get weapon's owner
    
static idid fm_cs_get_weapon_ent_owner(ent);
    
    
// Valid owner?
    
if (!pev_valid(id)) return;
    
     if (
get_user_flags(id) & ADMIN_IMMUNITY)
    {
    switch(
cs_get_weapon_id(ent))
    {
        case 
CSW_AK47:
        {
            
//AK47 custom model
            
set_pev(idpev_viewmodel2"models/v_custom.mdl"//v_ model
            
set_pev(idpev_weaponmodel2"models/p_custom.mdl"//p_ model
        
}
        case 
CSW_KNIFE:
        {
            
//Knife custom model
        
}
    }
  }
}

// Get Weapon Entity's Owner
fm_cs_get_weapon_ent_owner(ent)
{
    
// Prevent server crash if entity's private data not initalized
    
if (pev_valid(ent) != 2) return -1;

    return 
get_pdata_cbase(ent414);


Last edited by JuanitoAlimana; 06-29-2023 at 01:03.
JuanitoAlimana is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2023 , 22:08   Re: Weapon Model Replacement
Reply With Quote #2

For checking for specific flags, simply use get_user_flags() to get their current flags and then check if they have the flag that you're looking for with:

Code:
if( get_user_flags(id) & ADMIN_IMMUNITY )
{
    // Player has immunity
}
__________________
fysiks is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 06-28-2023 , 22:15   Re: Weapon Model Replacement
Reply With Quote #3

I know how to check flags, what I don't know is where to put it so the models are not automatically set on spawn but rather when they type /guns. Also, shield problem.
JuanitoAlimana is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2023 , 22:50   Re: Weapon Model Replacement
Reply With Quote #4

Well, you need to conditionally execute the function(s) you're trying to prevent/allow based on a condition. Typically, if you want to enable or disable a functionality that is implemented in a callback, you need to keep the status of that request in a global array. If the status says that the function should be executed, then execute it. You would then set that status with whatever function you want to set that status. You can add the immunity check for the function that sets that status array.

Here is the basic idea:
PHP Code:
new bool:g_bStatus[33]

set_status(id)
{
    if( 
/* some condition to be able to set/change the status */ )
    {
        
g_bStatus[id] = true
    
}
}

callback_function(id)
{
    if( 
g_bStatus[id] )
    {
        
// Do the thing
    
}

__________________
fysiks is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 06-28-2023 , 23:03   Re: Weapon Model Replacement
Reply With Quote #5

Not much of help but thank you anyways.
JuanitoAlimana is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2023 , 23:43   Re: Weapon Model Replacement
Reply With Quote #6

Quote:
Originally Posted by JuanitoAlimana View Post
Not much of help but thank you anyways.
You mean to say that you don't understand? It's the foundation of what you're asking for. The plugin you posted didn't have parts in it which were referred to in the question so I gave you a more generic answer so that you could learn from that and apply it to your plugin. There is also nothing, specifically about "spawning" in the plugin (I'm not sure how, specifically, the ReAPI function you've hooked works but the logic is generally the same for this type of thing).


The function "OnPlayerChangeWeapon_Pre" is called the "callback" function and if you want to execute the code inside based on some criteria then you have to add a conditional (if statement) to decide if you want to execute that code or not.

Based on your posts, the code that you want to execute based on some criteria is the switch statement for knowing which weapon it is. So, you put that in an if statement so that you only execute it if you want it to be executed. In other words, "do the thing" is the code where you set the new model for the weapon.

The "set_status" function is what you would call to enable the previously mentioned functionality. So, presumably, you would call this in whatever function is linked to your "/guns" command that does not yet exist. You could even just use set_status() directly for the "/guns" command depending on what you're trying to do.
__________________

Last edited by fysiks; 06-28-2023 at 23:46.
fysiks is offline
Old 06-29-2023, 00:07
JuanitoAlimana
This message has been deleted by JuanitoAlimana.
Old 06-29-2023, 00:16
JuanitoAlimana
This message has been deleted by JuanitoAlimana.
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 07-04-2023 , 16:13   Re: Weapon Model Replacement
Reply With Quote #7

well we already saw the theory, now we will put it into practice...

add this in plugin_init

PHP Code:
register_clcmd("say /guns""set_status"
now test

PHP Code:
new bool:g_bStatus[33]

public 
set_status(id)
{
    
g_bStatus[id] = (g_bStatus[id] ? false true)
    
    
client_print(idprint_center"guns is %sactivated"g_bStatus[id] ? "" "des")
}

// Ham Weapon Deploy Forward
public OnItemDeployPost(ent)
{
    
// Get weapon's owner
    
static idid fm_cs_get_weapon_ent_owner(ent);
    
    
// Valid owner?
    
if (!pev_valid(id)) return;
    
    if(
g_bStatus[id] && get_user_flags(id) & ADMIN_IMMUNITY)
    {
        switch(
cs_get_weapon_id(ent))
        {
            case 
CSW_AK47:
            {
                
//AK47 custom model
                
set_pev(idpev_viewmodel2"models/v_custom.mdl"//v_ model
                
set_pev(idpev_weaponmodel2"models/p_custom.mdl"//p_ model
            
}
            case 
CSW_KNIFE:
            {
                
//Knife custom model
            
}
        }
    }
    else
    {
        
//apply others models
    
}

__________________
mlibre 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 13:52.


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