Page 1 of 1
[HL2:DM] Remove Weapons on Spawn
Posted: Wed Jan 26, 2022 5:05 pm
by Painkiller
Hello Sp Team and Community,
I have a plugin that should remove all weapons and ammunition from the server.
Except for the 357 and crossbow.
But it just does not work.
Maybe someone can help
Syntax: Select all
from entities.hooks import EntityCondition, EntityPreHook
from entities.helpers import index_from_pointer
from filters.weapons import WeaponClassIter, WeaponIter
from weapons.entity import Weapon
def remove_idle_weapons():
for w in WeaponIter.iterator():
if w.get_property_int('m_hOwnerEntity') in [-1, 0]:
w.call_input('Kill')
@EntityPreHook(EntityCondition.is_human_player, 'bump_weapon')
@EntityPreHook(EntityCondition.is_bot_player, 'bump_weapon')
def pre_pickup(args):
weapon = Weapon(index_from_pointer(args[1]))
if weapon.classname in WeaponClassIter() and not weapon.classname in ['weapon_357', 'weapon_crossbow']:
remove_idle_weapons()
return False
Greeting Painkiller
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Mon Jan 31, 2022 3:45 pm
by VinciT
Try this:
Syntax: Select all
# ../remove_weapons/remove_weapons.py
# Source.Python
from events import Event
from filters.entities import EntityIter
from filters.weapons import WeaponClassIter
from listeners import OnNetworkedEntityCreated
from players.entity import Player
# Players will spawn with these weapons.
player_weapons = {'weapon_357', 'weapon_crossbow'}
# Weapons that can spawn on the map.
map_weapons = {'weapon_357', 'weapon_crossbow'}
# Set containing weapon names which will be removed.
banned_weapons = {weapon.name for weapon in WeaponClassIter()}.difference(
map_weapons)
# Dictionary that defines what ammo a weapon uses.
weapon_ammo = {
'weapon_357': ('item_ammo_357', 'item_ammo_357_large'),
'weapon_ar2': (
'item_ammo_ar2', 'item_ammo_ar2_large', 'item_ammo_ar2_altfire'
),
'weapon_crossbow': 'item_ammo_crossbow',
'weapon_pistol': ('item_ammo_pistol', 'item_ammo_pistol_large'),
'weapon_smg1': (
'item_ammo_smg1', 'item_ammo_smg1_large', 'item_ammo_smg1_grenade'
),
'weapon_shotgun': 'item_box_buckshot',
'weapon_rpg': 'item_rpg_round',
}
# Set containing names of ammo entities which will be removed.
banned_ammo = {'item_item_crate'}
# Now let's ban some ammo.
for weapon_name in banned_weapons:
# Get the name of the ammo entity.
ammo = weapon_ammo.get(weapon_name, None)
# Does this weapon even use ammo?
if ammo is None:
# Nope, skip it.
continue
# Are there multiple ammo entities for this weapon?
if isinstance(ammo, tuple):
banned_ammo.update(ammo)
# Or just one?
else:
banned_ammo.add(ammo)
# Combine both the weapons and ammo into a single set.
banned_entities = banned_weapons.union(banned_ammo)
class PlayerRW(Player):
"""Extended Player class."""
caching = True
def adjust_weapons(self):
"""Gives the player weapons specified in the 'player_weapons' set."""
# First let's remove all of their weapons.
for weapon in self.weapons():
weapon.remove()
# And then we shall give them the specified weapons.
for weapon_name in player_weapons:
self.give_named_item(weapon_name)
def load():
"""Called when the plugin gets loaded."""
for entity in EntityIter():
if entity.classname in banned_entities:
entity.delay(0, entity.remove)
@Event('player_spawn')
def player_spawn(event):
"""Called when a player spawns."""
player = PlayerRW.from_userid(event['userid'])
player.delay(0, player.adjust_weapons)
@OnNetworkedEntityCreated
def on_networked_entity_created(entity):
"""Called when a networked entity gets created."""
if entity.classname in banned_entities:
# We need to delay the next check by a single frame because the
# 'owner_handle' property hasn't been set yet.
entity.delay(0, delayed_check, (entity,))
def delayed_check(entity):
"""Removes the entity if it doesn't belong to anyone."""
if entity.owner_handle == -1:
entity.remove()
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Mon Jan 31, 2022 3:54 pm
by Painkiller
Thank you, even with ammunition that is perfect.
Also works without problem.
Greeting Painkiller
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Mon Jan 31, 2022 4:01 pm
by VinciT
Sweet, I'm glad it's working properly.
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Wed Feb 09, 2022 2:22 pm
by Painkiller
Another option would be very interesting!
At the moment you can add the exceptions which is good but the problem is that you spawn with all these weapons.
Which is not so good.
Greets Painkiller
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Thu Feb 10, 2022 3:47 pm
by VinciT
I've updated the
plugin to separate weapons the player spawns with and the ones that can spawn on the map.
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Thu Feb 10, 2022 4:00 pm
by Painkiller
Thank you that works great. Thank you very much.
Edit: I'll just add these missing weapons below ?
Code: Select all
'weapon_shotgun': 'item_box_buckshot',
'weapon_rpg': 'item_rpg_round',
'weapon_slam': '',
'weapon_frag': '',
'weapon_crowbar': '',
'weapon_stunstick': '',
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Thu Feb 10, 2022 4:14 pm
by VinciT
Painkiller wrote:Edit: I'll just add these missing weapons below ?
Code: Select all
'weapon_shotgun': 'item_box_buckshot',
'weapon_rpg': 'item_rpg_round',
'weapon_slam': '',
'weapon_frag': '',
'weapon_crowbar': '',
'weapon_stunstick': '',
There's no need, the
weapon_ammo dictionary is only used for weapons that have ammo items.
Re: [HL2:DM] Remove Weapons on Spawn
Posted: Thu Feb 10, 2022 4:25 pm
by Painkiller
Ok, I have tried to add something like a combine_ball ammunition so
"item_ammo_ar2_altfire"
As this does not exist on some maps.
The problem is when I have 3 max I have to shoot three times.
"item_ammo_ar2_altfire" three times.
It will probably do the same with smg1 grenades and rpg ammo.
But i think it doesn't matter i can put it in as many times as i want.
Syntax: Select all
# Players will spawn with these weapons.
player_weapons = {'weapon_crowbar', 'weapon_physcannon', 'item_ammo_ar2_altfire', 'item_ammo_ar2_altfire', 'item_ammo_ar2_altfire'}