[CS:S] Blocking item pickup notification

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 214
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

[CS:S] Blocking item pickup notification

Postby Kami » Tue Jan 12, 2021 6:38 pm

Hey guys,

I'd like to block the hud element that notifies you when you pick up a weapon (the yellow picture of the weapon you picked up on the right).

I tried using hidehudflags, ResetHUD and the ItemPickup Usermesage with no luck.

Maybe someone here knows how to achieve this. Thank you!

An alternative approach to my problem would be to give weapons (weapon_flashbang) without triggering the Hud Message.
User avatar
satoon101
Project Leader
Posts: 2651
Joined: Sat Jul 07, 2012 1:59 am

Re: [CS:S] Blocking item pickup notification

Postby satoon101 » Tue Jan 12, 2021 8:17 pm

I'm not 100% sure this will work properly, but maybe try stopping the pickup event from broadcasting to players:

Syntax: Select all

from events.hooks import EventAction, PreEvent

@PreEvent('item_pickup')
def _pre_pickup(game_event):
return EventAction.STOP_BROADCAST
Image
User avatar
Kami
Global Moderator
Posts: 214
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Blocking item pickup notification

Postby Kami » Tue Jan 12, 2021 8:27 pm

Thank you for the reply!
I tried your code but sadly it did not work. I even tried to use EventAction.BLOCK to just block the event completely which didn't work either.
User avatar
L'In20Cible
Project Leader
Posts: 1391
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Blocking item pickup notification

Postby L'In20Cible » Tue Jan 12, 2021 9:29 pm

Kami wrote:Thank you for the reply!
I tried your code but sadly it did not work. I even tried to use EventAction.BLOCK to just block the event completely which didn't work either.

That is likely happening client-side when a new weapon is added to the player's inventory. Your best bet, and likely only alternative server-side, is likely to always keep the ammo > 1 so it doesn't count as a new weapon.
User avatar
Kami
Global Moderator
Posts: 214
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Blocking item pickup notification

Postby Kami » Tue Jan 12, 2021 9:48 pm

It seems that setting ammo for grenades counts as giving new ones. So everytime i add ammo, it shows as a picked up weapon. ResetHUD can actually remove the Image but its not reliable (I have to send multiple ResetHUDs to remove the image without blinking). I've seen servers where it does not show for grenades, but I could not figure out how.
User avatar
L'In20Cible
Project Leader
Posts: 1391
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Blocking item pickup notification

Postby L'In20Cible » Tue Jan 12, 2021 10:53 pm

Kami wrote:It seems that setting ammo for grenades counts as giving new ones. So everytime i add ammo, it shows as a picked up weapon. ResetHUD can actually remove the Image but its not reliable (I have to send multiple ResetHUDs to remove the image without blinking). I've seen servers where it does not show for grenades, but I could not figure out how.

Bummer. What's the end goal anyways? Infinite ammo? If so, then you can get away with it by blocking the ammo removal:

Syntax: Select all

from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook
from memory import Convention
from memory import DataType

@EntityPreHook(
EntityCondition.is_player,
lambda player: player.make_virtual_function(
254,
Convention.THISCALL,
(DataType.POINTER, DataType.INT, DataType.INT),
DataType.VOID
)
)
def pre_remove_ammo(stack_data):
if stack_data[2] == 12:
return False
User avatar
Kami
Global Moderator
Posts: 214
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Blocking item pickup notification

Postby Kami » Wed Jan 13, 2021 6:42 am

Yes the endgoal is infinite ammo for weapon_flashbang and this seems to be exactly what I needed! Thank you very much. It never occured to me that I could just block ammo consumption.
Could you maybe explain, how you found out which function you needed to hook?
User avatar
L'In20Cible
Project Leader
Posts: 1391
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Blocking item pickup notification

Postby L'In20Cible » Wed Jan 13, 2021 7:39 am

Kami wrote:Yes the endgoal is infinite ammo for weapon_flashbang and this seems to be exactly what I needed! Thank you very much. It never occured to me that I could just block ammo consumption.
Could you maybe explain, how you found out which function you needed to hook?

That is basically a hook on:

Syntax: Select all

_ZN20CBaseCombatCharacter10RemoveAmmoEii // void CBaseCombatCharacter::RemoveAmmo(CBaseCombatCharacter *this, int, int)

Where the first integer is the amount to remove, and the second the type of ammo. You can get the offset with this:

viewtopic.php?f=8&t=972

And the type of ammo with this:

Syntax: Select all

Weapon.find_or_create('weapon_flashbang').ammoprop

If you have more specific questions feel free to ask. :smile:
User avatar
Kami
Global Moderator
Posts: 214
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Blocking item pickup notification

Postby Kami » Wed Jan 13, 2021 7:36 pm

Thank you very much for taking the time to explain it to me!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 7 guests