Raised This Month: $ Target: $400
 0% 

Ham_item_deploy


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
egbertjan
Senior Member
Join Date: Mar 2007
Location: The Netherlands
Old 05-21-2014 , 12:37   Ham_item_deploy
Reply With Quote #1

In this script that I found Ham_item_deploy is used to change weapon models instead of using the curweapon. I want to change multiple weapons, and this code seems rather good, however I'm wondering if I need a loop like this to use multiple weapons? Or can I use something like:

Code:
        RegisterHam( Ham_Item_Deploy, "fwReplaceModels", 1);
Code:
public fwReplaceModel( entity )
{
    if( pev_valid( entity ) != 2 ) return HAM_IGNORED;
    
    new id = get_pdata_cbase( entity, 41, 4 );
    
    static entclass[32];
    pev(entity, pev_classname, entclass, 31);
    
    for( i = 0; i < g_size; i++ )
    {
        if( equal( entclass, szWeaponInfo[ i ][ 0 ] ) )
            set_pev( id, pev_viewmodel2, szWeaponInfo[ i ][ 1 ] );
        
    }
    
    return HAM_IGNORED;
}

And then do something like this:



Code:
public fwReplaceModel( entity ) {
    if( pev_valid( entity ) != 2 ) return HAM_IGNORED;
    
    new id = get_pdata_cbase( entity, 41, 4 );
    new clip,ammo
	new weapon=get_user_weapon(id,clip,ammo)

    static entclass[32];
    pev(entity, pev_classname, entclass, 31);
    
   switch(weapon) {
		case CSW_KNIFE:
		{
			if(player_class[id] != Ninja) {
				entity_set_string(id, EV_SZ_viewmodel, KNIFE_VIEW)  
				entity_set_string(id, EV_SZ_weaponmodel, KNIFE_PLAYER)  
			}
		}
		case CSW_C4:
		{
			entity_set_string(id, EV_SZ_viewmodel, C4_VIEW)  
			entity_set_string(id, EV_SZ_weaponmodel, C4_PLAYER)  
		}
		case CSW_HEGRENADE:
		{
			entity_set_string(id, EV_SZ_viewmodel, HE_VIEW)  
			entity_set_string(id, EV_SZ_weaponmodel, HE_PLAYER)  
		}
		case CSW_FLASHBANG:
		{
			entity_set_string(id, EV_SZ_viewmodel, FL_VIEW)  
			entity_set_string(id, EV_SZ_weaponmodel, FL_PLAYER)  
		}
		case CSW_SMOKEGRENADE:
		{
			entity_set_string(id, EV_SZ_viewmodel, SE_VIEW)  
			entity_set_string(id, EV_SZ_weaponmodel, SE_PLAYER)  
		}
	}
    
    return HAM_IGNORED;
}

Source: https://forums.alliedmods.net/showpo...42&postcount=5
egbertjan is offline
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 05-21-2014 , 13:21   Re: Ham_item_deploy
Reply With Quote #2

You need to register for each weapon

PHP Code:
RegisterHamHam_Item_Deploy"fwReplaceModels"1); 

PHP Code:
RegisterHamHam_Item_Deploy"weapon_knife""fwReplaceModels"1);
RegisterHamHam_Item_Deploy"weapon_m4a1""fwReplaceModels"1);
RegisterHamHam_Item_Deploy"weapon_ak47""fwReplaceModels"1); 
Or you can make an array like in the link you gave and then loop through it

Last edited by NikKOo31; 05-21-2014 at 13:22.
NikKOo31 is offline
egbertjan
Senior Member
Join Date: Mar 2007
Location: The Netherlands
Old 05-21-2014 , 15:57   Re: Ham_item_deploy
Reply With Quote #3

If I try something like this I get the wrong combination of model with the weapon.

Code:
public class_models(plr) {
	new id = get_pdata_cbase( plr, 41, 4 ); 
	new clip,ammo
	new weapon=get_user_weapon(id,clip,ammo)
	
	if( is_user_alive(id) || is_user_connected(id) )   {
        
		
		switch(weapon) {
			case CSW_KNIFE:
			{
				if(player_class[id] != Ninja) {
					entity_set_string(id, EV_SZ_viewmodel, KNIFE_VIEW)  
					entity_set_string(id, EV_SZ_weaponmodel, KNIFE_PLAYER)  
				}
			}
			case CSW_C4:
			{
				entity_set_string(id, EV_SZ_viewmodel, C4_VIEW)  
				entity_set_string(id, EV_SZ_weaponmodel, C4_PLAYER)  
			}
			case CSW_HEGRENADE:
			{
				entity_set_string(id, EV_SZ_viewmodel, HE_VIEW)  
				entity_set_string(id, EV_SZ_weaponmodel, HE_PLAYER)  
			}
			case CSW_FLASHBANG:
			{
				entity_set_string(id, EV_SZ_viewmodel, FL_VIEW)  
				entity_set_string(id, EV_SZ_weaponmodel, FL_PLAYER)  
			}
			case CSW_SMOKEGRENADE:
			{
				entity_set_string(id, EV_SZ_viewmodel, SE_VIEW)  
				entity_set_string(id, EV_SZ_weaponmodel, SE_PLAYER)  
			}
		}
			
		
	}
}
egbertjan is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-21-2014 , 17:17   Re: Ham_item_deploy
Reply With Quote #4

I'll just suggest untested method, because I haven't got time to test it, but decided to share it. Any modifications will be done later, I just want to show the idea. You may use an enum and a const to loop and register the weapons by their "weapon_" name, then to set the model for each weapon by the const and a loop.
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <engine>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "x"



enum _:WeaponParts
{
    
_wname[32],
    
_vmodel[32],
    
_pmodel[32]
}

new const 
WeaponsToLoop[][WeaponParts]=
{
    {
"weapon_knife"KNIFE_VIEWKNIFE_PLAYER},
    {
"weapon_c4"C4_VIEWC4_PLAYER},
    {
"weapon_hegrenade"HE_VIEWHE_PLAYER},
    {
"weapon_smokegrenade"SE_VIEWSE_PLAYER},
    {
"weapon_flashbang"FL_VIEWFL_PLAYER}
    
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    for(new 
0sizeof(WeaponsToLoop) - 1i++)
    {
        
RegisterHam(Ham_Item_DeployWeaponsToLoop[i][_wname], "fwReplaceModels"0)
    }    
}

public 
fwReplaceModels(ent)
{
    new 
id get_pdata_cbaseent41)
    
    
set_task(0.1"chat"id)
                
    
}

public 
chat(id)
{
    new 
weapon,clip,ammo,item
    weapon 
get_user_weapon(idclipammo)
    switch(
weapon)
    {
        case 
CSW_KNIFE:     item 0
        
case CSW_C4:         item 1
        
case CSW_HEGRENADE:     item 2
        
case CSW_FLASHBANG:     item 3
        
case CSW_SMOKEGRENADE:     item 4
    
}
    
            
    
entity_set_string(idEV_SZ_viewmodelWeaponsToLoop[item][_vmodel])  
    
entity_set_string(idEV_SZ_weaponmodelWeaponsToLoop[item][_pmodel])  

EDIT: The code is edited to the optimal way. So, look. In Ham_Item_Deploy, get_user_weapon is called before the change and actually in the moment of change it takes the index of the previous weapon. So, I made it with task, which to take the weapon index 0.1 sec after the change. Here you go, this worked on a test with a chat command, so it should work with this function, too.
__________________

Last edited by Flick3rR; 05-21-2014 at 20:00. Reason: EDIT of the code
Flick3rR is offline
Send a message via Skype™ to Flick3rR
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 05-21-2014 , 18:41   Re: Ham_item_deploy
Reply With Quote #5

I see what you guys are doing, but wouldn't be easier to use curweapon event instead of registering too many stuff?

Edit* just a thought

PHP Code:
public class_models(plr) {
    static 
id get_pdata_cbaseplr41)
    if( 
is_user_alive(id) )   {
        static 
weapon=get_user_weapon(id,_,_)
        
        switch(
weapon) {
            case 
CSW_KNIFE:
            {
                if(
player_class[id] != Ninja) {
                    
entity_set_string(idEV_SZ_viewmodelKNIFE_VIEW)  
                    
entity_set_string(idEV_SZ_weaponmodelKNIFE_PLAYER)  
                }
            }
            case 
CSW_C4:
            {
                
entity_set_string(idEV_SZ_viewmodelC4_VIEW)  
                
entity_set_string(idEV_SZ_weaponmodelC4_PLAYER)  
            }
            case 
CSW_HEGRENADE:
            {
                
entity_set_string(idEV_SZ_viewmodelHE_VIEW)  
                
entity_set_string(idEV_SZ_weaponmodelHE_PLAYER)  
            }
            case 
CSW_FLASHBANG:
            {
                
entity_set_string(idEV_SZ_viewmodelFL_VIEW)  
                
entity_set_string(idEV_SZ_weaponmodelFL_PLAYER)  
            }
            case 
CSW_SMOKEGRENADE:
            {
                
entity_set_string(idEV_SZ_viewmodelSE_VIEW)  
                
entity_set_string(idEV_SZ_weaponmodelSE_PLAYER)  
            }
        }
    }


Last edited by NikKOo31; 05-21-2014 at 18:47.
NikKOo31 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-21-2014 , 20:01   Re: Ham_item_deploy
Reply With Quote #6

Edited and tested the code, no mistakes spoken. Take a look.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 05-21-2014 , 20:16   Re: Ham_item_deploy
Reply With Quote #7

@Flick3rR, maybe you can register post to avoid task

PHP Code:
RegisterHam(Ham_Item_DeployWeaponsToLoop[i][_wname], "fwReplaceModels"0

PHP Code:
RegisterHam(Ham_Item_DeployWeaponsToLoop[i][_wname], "fwReplaceModels"1
I will test later, the code looks good
NikKOo31 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-22-2014 , 02:30   Re: Ham_item_deploy
Reply With Quote #8

Tried with post, you know... No difference suspected
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
egbertjan
Senior Member
Join Date: Mar 2007
Location: The Netherlands
Old 05-22-2014 , 06:43   Re: Ham_item_deploy
Reply With Quote #9

My current "Curweapon" function looks like the following. When I asked how I could optimize it I were told to use Ham_item_deploy. I've tried some methods but failed with it.

Code:
public CurWeapon(id) {    

    after_bullet[id]=1
    
    new clip,ammo
    new weapon=get_user_weapon(id,clip,ammo)
    
    
    switch(player_class[id]) {
    
        case Hunter: 
        {
            if (freeze_ended) execute_casting(id)
            if(bow[id]==1) {
            bow[id]=0
            if(on_knife[id]) {
                entity_set_string(id, EV_SZ_viewmodel, KNIFE_VIEW)  
                entity_set_string(id, EV_SZ_weaponmodel, KNIFE_PLAYER)  
            }
        }
        
        }
        case Assassin:
        {
            if (freeze_ended) execute_casting(id)    
            invisible_cast[id]=0            
        }
        case Ninja:
        {
            
            if ((weapon != CSW_C4 ) && !on_knife[id]) {
                
                client_cmd(id,"weapon_knife")
                engclient_cmd(id,"weapon_knife")
                on_knife[id]=1
                
                
            }
            if (weapon == CSW_KNIFE) {
                entity_set_string(id, EV_SZ_viewmodel, Ninja_katana)  
            }
        }
        case Paladin:
        {
            if (weapon == CSW_DEAGLE) {
                paladin_bullet[id] = true
                entity_set_string(id, EV_SZ_viewmodel, Deagle_view)  
                entity_set_string(id, EV_SZ_weaponmodel, Deagle_player)  
            } else {
                paladin_bullet[id] = false
            }
        }
    }
    
    
    switch(weapon) {
        
        case CSW_KNIFE:
        {
            on_knife[id]=1
            if(player_class[id] != Ninja) {
                entity_set_string(id, EV_SZ_viewmodel, KNIFE_VIEW)  
                entity_set_string(id, EV_SZ_weaponmodel, KNIFE_PLAYER)  
            }
        }
        
        case CSW_C4:
        {
            entity_set_string(id, EV_SZ_viewmodel, C4_VIEW)  
            entity_set_string(id, EV_SZ_weaponmodel, C4_PLAYER)  
        }
        case CSW_HEGRENADE:
        {
            entity_set_string(id, EV_SZ_viewmodel, HE_VIEW)  
            entity_set_string(id, EV_SZ_weaponmodel, HE_PLAYER)  
        }
        case CSW_FLASHBANG:
        {
            entity_set_string(id, EV_SZ_viewmodel, FL_VIEW)  
            entity_set_string(id, EV_SZ_weaponmodel, FL_PLAYER)  
        }
        case CSW_SMOKEGRENADE:
        {
            entity_set_string(id, EV_SZ_viewmodel, SE_VIEW)  
            entity_set_string(id, EV_SZ_weaponmodel, SE_PLAYER)  
        }
        
        default: 
        {
            on_knife[id]=0
        }
    }
            

        
    set_speedchange(id)
    set_renderchange(id)
    
}
egbertjan is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-22-2014 , 07:00   Re: Ham_item_deploy
Reply With Quote #10

Have you tried the edited version?
And also, for last - you want CurWeapon or Ham_Item_Deply, or you are asking which way is better?
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
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 09:42.


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