Dropping Knife
Dropping Knife
Hey, i tried to use the search function but didnt gave me what i was looking for.
Is there anyway to drop knife, he smokes etc. with the clientside drop button?
Sorry for the bad english, im on my phone
Is there anyway to drop knife, he smokes etc. with the clientside drop button?
Sorry for the bad english, im on my phone
Syntax: Select all
from commands.client import ClientCommand
from entities.helpers import index_from_inthandle
from filters.weapons import WeaponClassIter
from mathlib import NULL_VECTOR
from players.entity import Player
from weapons.entity import Weapon
knife_weapons = [x.name for x in WeaponClassIter('knife')]
nade_weapons = [x.name for x in WeaponClassIter('grenade')]
drop_weapons = knife_weapons + nade_weapons
@ClientCommand('drop')
def drop_weapon(command, index):
player = Player(index)
weapon = Weapon(index_from_inthandle(player.active_weapon))
if weapon.classname in drop_weapons:
player.drop_weapon(weapon.pointer, NULL_VECTOR, NULL_VECTOR)
You can use any vector for the last 2 arguments in drop_weapon. Getting the weapon will be slightly easier once we finish the player_weapons_update branch and merge those changes.
Wouldn't it be better with
?
Also, you can use BaseEntity instead of Weapon for this purpose, I believe it would be faster
By the way, NULL_VECTOR throws it very far away from the player.
Syntax: Select all
try:
weapon = Weapon(index_from_inthandle(player.active_weapon))
except (ValueError, OverflowError):
return
?
Also, you can use BaseEntity instead of Weapon for this purpose, I believe it would be faster
By the way, NULL_VECTOR throws it very far away from the player.

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Meh, minor details. Again, that will be easier once the other branch is merged. In the other branch, active_weapon is a property instead of using data, and it will do all that on its own to return the Weapon instance.
No it doesn't, quite the opposite in fact, since the second vector is the velocity:
https://github.com/alliedmodders/hl2sdk/blob/98fe5b5a34b3721fe4d60ec7ba3a28ade3512560/game/server/hl2mp/hl2mp_player.h#L74
iPlayer wrote:By the way, NULL_VECTOR throws it very far away from the player.
No it doesn't, quite the opposite in fact, since the second vector is the velocity:
https://github.com/alliedmodders/hl2sdk/blob/98fe5b5a34b3721fe4d60ec7ba3a28ade3512560/game/server/hl2mp/hl2mp_player.h#L74
satoon101 wrote:No it doesn't, quite the opposite in fact as one of the vectors is the velocity.
Well, then maybe our NULL_VECTOR then gets summed with some other vectors? Because for me (cstrike) it always throws the item in the direction of (1, -1, 1). Right, backwards and up according to Hammer axises.

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Hey thank you first!
I want players to drop any weapon they have, I think CS:S atleast refuses to drop knife and grenades. So when you have a knife as active weapon you just need to press "G" (Default) to drop it as usual.
I just found a code from SP times, but couldnt find something similiar:
You can probably do that with ClientCommand('drop')
Would be also great if it might kill any weapon which has been dropped. (Not only for this plugin, in total)
Is there an event when a weapon has been dropped?
EDIT: oh well I see my browser didnt showed the code until I restarted it.. weird Sorry but ye ignore the first code part. :p
I want players to drop any weapon they have, I think CS:S atleast refuses to drop knife and grenades. So when you have a knife as active weapon you just need to press "G" (Default) to drop it as usual.
I just found a code from SP times, but couldnt find something similiar:
You can probably do that with ClientCommand('drop')
Syntax: Select all
// drop any weapon
public Action :D ropItem(client, const String:command[], argc)
{
new weaponIndex = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
// Allow ghosts to drop all weapons and allow players if the cvar allows them to
if(GetConVarBool(g_hAllowKnifeDrop) || IsFakeClient(client))
{
if(weaponIndex != -1)
{
CS_DropWeapon(client, weaponIndex, true, false);
}
return Plugin_Handled;
}
return Plugin_Continue;
}
Would be also great if it might kill any weapon which has been dropped. (Not only for this plugin, in total)
Is there an event when a weapon has been dropped?
Syntax: Select all
// kill weapon and weapon attachments on drop
public Action:CS_OnCSWeaponDrop(client, weaponIndex)
{
if(weaponIndex != -1)
{
AcceptEntityInput(weaponIndex, "KillHierarchy");
AcceptEntityInput(weaponIndex, "Kill");
}
}
EDIT: oh well I see my browser didnt showed the code until I restarted it.. weird Sorry but ye ignore the first code part. :p
If you want to kill it, just add this line right after 'drop_weapon' one:
Syntax: Select all
weapon.remove()

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Nevermind, something's going really weird during my testing.
Velocity vector doesn't seem to do anything for me, and I still don't know what makes the item fly that far.
Velocity vector doesn't seem to do anything for me, and I still don't know what makes the item fly that far.

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Because the first example included nades:
You have to be careful when dropping nades, you'll keep the nade if the pin is pulled on it or it's being thrown, and you'll also drop it, basically duplicating the items.
This is old, but you need something like this:
Additionally when you have more than one nade you also need to handle the ammo (I don't remember what specifically is needed.)
You have to be careful when dropping nades, you'll keep the nade if the pin is pulled on it or it's being thrown, and you'll also drop it, basically duplicating the items.
This is old, but you need something like this:
Syntax: Select all
SEQUENCE_THROWN = 5
SEQUENCE_PINOUT = 1
BLOCKED_SEQ = (SEQUENCE_THROWN, SEQUENCE_PINOUT)
if Entity(index_from_inthandle(m_hActiveWeapon)).get_property_int("m_nSequence") not in BLOCKED_SEQ: # save to drop the nade
Additionally when you have more than one nade you also need to handle the ammo (I don't remember what specifically is needed.)
Re: Dropping Knife
Weirdly never tested the dropping knife since I added it back then.
Right now it removes the weapon, but clientside you still see the knife equipped, any help?
Edit:
It bugs cause of:
Right now it removes the weapon, but clientside you still see the knife equipped, any help?
Syntax: Select all
@ClientCommand('drop')
def drop_knife(command, index):
player = Player(index)
weapon = player.active_weapon
if weapon.classname.startswith('weapon_knife'):
player.drop_weapon(weapon.pointer, NULL_VECTOR, NULL_VECTOR)
Edit:
It bugs cause of:
Syntax: Select all
@EntityPreHook(EntityCondition.is_player, 'drop_weapon')
def pre_drop_weapon(args):
weapon_ptr = args[1]
if not weapon_ptr:
return
weapon = memory.make_object(BaseEntity, weapon_ptr)
weapon.remove()
return False
Re: Dropping Knife
I'm not sure where you found that drop_weapon pre-hook, but I imagine you would rather that be a post-hook. Removing the weapon before it has been "dropped" will have some strange side-effects, like what you are seeing.
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 79 guests