Raised This Month: $32 Target: $400
 8% 

How to take away a player's shield if they are holding a knife


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Woodi5
Junior Member
Join Date: Nov 2020
Location: Russia
Old 12-07-2020 , 07:40   How to take away a player's shield if they are holding a knife
Reply With Quote #1

How to take away a player's shield if they are holding a knife?
I did the check "ham item deploy weapon_knife"
HTML Code:
#include <AmxModx>
#include <HamSandwich>
 
public plugin_init() 
{
   RegisterHam(Ham_Item_Deploy, "weapon_knife", "Item_Deploy_Post", 1)
}
 
public Item_Deploy_Post(weapon)
{
   new id = get_pdata_cbase(weapon, 41, 4)
   client_print(id, print_chat, "You changed your weapon for a knife") 

   return HAM_IGNORED
}

Last edited by Woodi5; 12-07-2020 at 07:50.
Woodi5 is offline
Woodi5
Junior Member
Join Date: Nov 2020
Location: Russia
Old 12-15-2020 , 09:19   Re: How to take away a player's shield if they are holding a knife
Reply With Quote #2

Heeeelllppp!!!
Woodi5 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-15-2020 , 09:52   Re: How to take away a player's shield if they are holding a knife
Reply With Quote #3

Just check whether the player is holding a shield or not, if true execute the drop command on him
Code:
if (cs_get_user_shield(id)) {     client_cmd(id, "drop") }

https://www.amxmodx.org/api/cstrike/cs_get_user_shield
https://www.amxmodx.org/api/amxmodx/client_cmd
__________________








CrazY. is offline
Woodi5
Junior Member
Join Date: Nov 2020
Location: Russia
Old 12-15-2020 , 13:09   Re: How to take away a player's shield if they are holding a knife
Reply With Quote #4

Quote:
Originally Posted by CrazY. View Post
Just check whether the player is holding a shield or not, if true execute the drop command on him
Code:
if (cs_get_user_shield(id)) {     client_cmd(id, "drop") }

https://www.amxmodx.org/api/cstrike/cs_get_user_shield
https://www.amxmodx.org/api/amxmodx/client_cmd
Works:
HTML Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

const m_bOwnsShield = 2043;

public plugin_init()
{
    RegisterHam(Ham_Item_Deploy, "weapon_knife", "Item_Deploy_Post", 1)
}
 
public Item_Deploy_Post(weapon)
{
    new id = get_pdata_cbase(weapon, 41, 4)
    client_print(id, print_chat, "You changed your weapon for a knife!")
    
    if(get_pdata_bool(id, m_bOwnsShield) && get_pdata_cbase(weapon, 41, 4))
    {
        engclient_cmd(id, "drop", "weapon_shield")
    }
    return HAM_IGNORED
}
But I need the command not "drop", but the command strip_user_weapons (id, "weapon_shield") or ham_strip_weapon(id, "weapon_shield") or fm_strip_user_gun(id,"weapon_shield")
How do i do this?

Last edited by Woodi5; 12-15-2020 at 13:26.
Woodi5 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 12-15-2020 , 15:10   Re: How to take away a player's shield if they are holding a knife
Reply With Quote #5

There are multiple possible solutions here...

You could just simply make the player chance his weapon again from the moment he's trying to wear his shield using CurWeapon

secondly, you could save the player's loadout, strip all weapons, give everything back except for the shield.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-15-2020 , 16:23   Re: How to take away a player's shield if they are holding a knife
Reply With Quote #6

This is how CS removes player shield.
Code:
void CBasePlayer::RemoveShield()
{
	if (HasShield())
	{
		m_bOwnsShield = false;
		m_bHasPrimary = false;
		m_bShieldDrawn = false;
		pev->gamestate = HITGROUP_SHIELD_DISABLED;

		UpdateShieldCrosshair(true);
	}
}
Rewrite to amxx and execute the function in Ham_Item_Deploy pre instead of post.

Here's the UpdateShieldCrosshair code
Code:
void CBasePlayer::UpdateShieldCrosshair(bool draw)
{
	if (draw)
		m_iHideHUD &= ~HIDEHUD_CROSSHAIR;
	else
		m_iHideHUD |= HIDEHUD_CROSSHAIR;
}
__________________









Last edited by CrazY.; 12-15-2020 at 16:30.
CrazY. 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 04:24.


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