Raised This Month: $51 Target: $400
 12% 

ham_give_weapon and ham_strip_weapon


Post New Thread Reply   
 
Thread Tools Display Modes
VEN
Veteran Member
Join Date: Jan 2005
Old 12-05-2008 , 11:04   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #41

Quote:
Is there a way to use this function for removing a defusekit from a player?
No, because this method is used to clear item(s) in player's item slots but defkit/nvgs is only indicated in player's pvPrivateData.
VEN is offline
Old 09-29-2009, 14:05
Exolent[jNr]
This message has been deleted by Exolent[jNr]. Reason: Oops
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-06-2010 , 15:46   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #42

Here is my strip version :

Pass the CSW_xxx id instead of weapon name.
Pass the weapon slot if you know it.

Needed offsets are here : http://forums.alliedmods.net/showpos...01#post1712101

PHP Code:
stock ham_strip_user_weapon(idiCswIdiSlot 0bool:bSwitchIfActive true)
{
    new 
iWeapon;
    if( !
iSlot )
    {
        static const 
iWeaponsSlots[] = {
            -
1,
            
2//CSW_P228
            
-1,
            
1//CSW_SCOUT
            
4//CSW_HEGRENADE
            
1//CSW_XM1014
            
5//CSW_C4
            
1//CSW_MAC10
            
1//CSW_AUG
            
4//CSW_SMOKEGRENADE
            
2//CSW_ELITE
            
2//CSW_FIVESEVEN
            
1//CSW_UMP45
            
1//CSW_SG550
            
1//CSW_GALIL
            
1//CSW_FAMAS
            
2//CSW_USP
            
2//CSW_GLOCK18
            
1//CSW_AWP
            
1//CSW_MP5NAVY
            
1//CSW_M249
            
1//CSW_M3
            
1//CSW_M4A1
            
1//CSW_TMP
            
1//CSW_G3SG1
            
4//CSW_FLASHBANG
            
2//CSW_DEAGLE
            
1//CSW_SG552
            
1//CSW_AK47
            
3//CSW_KNIFE
            
//CSW_P90
        
}
        
iSlot iWeaponsSlots[iCswId];
    }

    
iWeapon get_pdata_cbase(idm_rgpPlayerItems_CBasePlayer[iSlot]);

    while( 
iWeapon )
    {
        if( 
get_pdata_int(iWeaponm_iIdXO_CBASEPLAYERITEM) == iCswId )
        {
            break;
        }
        
iWeapon get_pdata_cbase(iWeaponm_pNextXO_CBASEPLAYERITEM);
    }

    if( 
iWeapon )
    {
        if( 
bSwitchIfActive && get_pdata_cbase(idm_pActiveItem) == iWeapon )
        {
            
ExecuteHamB(Ham_Weapon_RetireWeaponiWeapon);
        }

        if( 
ExecuteHamB(Ham_RemovePlayerItemidiWeapon) )
        {
            
user_has_weapon(idiCswId0);
            
ExecuteHamB(Ham_Item_KilliWeapon);
            return 
1;
        }
    }

    return 
0;

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-20-2013 at 03:50.
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-06-2010 , 16:13   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #43

You should explain what is the difference.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-06-2010 , 16:31   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #44

You pass weapon type instead of weapon name.
It checks directly in player slots instead of check all weapons and check owner.
The owner check in avanlanche stock is made module side so it shouldn't be a big difference between the 2 ways, and also, such a native shouldn't be often called.
Also, as on cs, player have only 1 weapon per slot (except with specific plugins), the method should be efficient.
Last difference is the use of user_has_weapon instead of pev_weapons that is more efficient, but again, this is trivial.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 06-19-2011 , 15:00   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #45

Have some trouble here.

Code:
L 06/19/2011 - 18:04:23: [AMXX] Run time error 3: stack error 
L 06/19/2011 - 18:04:23: [AMXX]    [0] bajery.inc::ham_strip_weapon (line 32)
L 06/19/2011 - 18:04:23: [AMXX]    [1] RR_Classic.sma::current_weapon (line 71)
This is CurWeapon:
Code:
public current_weapon(id)
{
    if(r_counter>2) 
        return PLUGIN_HANDLED;
        
    new weapon = get_user_weapon(id)
        
    if (weapon == CSW_HEGRENADE || weapon == CSW_SMOKEGRENADE || weapon == CSW_FLASHBANG )
        client_cmd(id, "lastinv");
        
    if (weapon == CSW_C4)
    {
        new gmsgStatusIcon = get_user_msgid("StatusIcon");
        
        ham_strip_weapon(id,"weapon_c4");
        message_begin(MSG_ONE,gmsgStatusIcon,_,id);
        write_byte(0);
        write_string("c4");
        message_end();
    }
    
    return PLUGIN_CONTINUE;
}
And line bajery.inc is a file which contains only functions from 1st post and line 32 is:
Code:
if(get_user_weapon(id) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
Any ideas why?
FiFiX is offline
Send a message via Skype™ to FiFiX
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 06-20-2011 , 02:45   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #46

Quote:
Originally Posted by FiFiX View Post
Have some trouble here.

Code:
L 06/19/2011 - 18:04:23: [AMXX] Run time error 3: stack error 
L 06/19/2011 - 18:04:23: [AMXX]    [0] bajery.inc::ham_strip_weapon (line 32)
L 06/19/2011 - 18:04:23: [AMXX]    [1] RR_Classic.sma::current_weapon (line 71)
This is CurWeapon:
Code:
public current_weapon(id) {     (...)     if (weapon == CSW_C4)     {         new gmsgStatusIcon = get_user_msgid("StatusIcon");        
        ham_strip_weapon(id,"weapon_c4");
                (...)     }         return PLUGIN_CONTINUE; }
Any ideas why?
Yeah, ham_strip_weapon(id,"weapon_c4") triggers an engine message. However, if a message gets sent during AMXX's message forward, it causes re-entrancy/recursion issues like that. (https://bugs.alliedmods.net/show_bug.cgi?id=3664)
__________________

Last edited by MeRcyLeZZ; 06-20-2011 at 17:02.
MeRcyLeZZ is offline
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 06-20-2011 , 03:45   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #47

So if I'll make something like:
Code:
if(!g_bombremove)
{
       ham_strip_weapon(id,"weapon_c4");
       g_bombremove = true;
}
it will slove that problem? Anyway is there another way to remove c4 ?
FiFiX is offline
Send a message via Skype™ to FiFiX
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 06-20-2011 , 17:06   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #48

Quote:
Originally Posted by FiFiX View Post
So if I'll make something like:
Code:
if(!g_bombremove)
{
       ham_strip_weapon(id,"weapon_c4");
       g_bombremove = true;
}
it will slove that problem? Anyway is there another way to remove c4 ?
You can still use CurWeapon event, just set a task to call ham_strip_weapon, like
Code:
    /* CurWeapon event */     set_task(0.1, "remove_c4", id)
Code:
public remove_c4(id) {     if (!is_user_alive(id)) return;     ham_strip_weapon(id, "weapon_c4") }
I know it's not pretty, but it shold get rid of "Run time error 3: stack error".
__________________

Last edited by MeRcyLeZZ; 06-20-2011 at 17:09.
MeRcyLeZZ is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-20-2011 , 17:26   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #49

If you want to not let player have a C4, you can do a few things:
1. Hook Ham_Item_Deploy and remove there.
2. Hook Ham_AddPlayerItem and remove entity (?) and supercede the forward.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 06-20-2011 , 18:15   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #50

For Ham_Item_Deploy hook would be:
RegisterHam(Ham_Item_Deploy, "weapon_c4", "weapon_c4", 1)
And how to remove it then?
FiFiX is offline
Send a message via Skype™ to FiFiX
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 01:42.


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