[Cs:s] How to block weapon pick up

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[Cs:s] How to block weapon pick up

Postby cssbestrpg » Sun Dec 20, 2020 10:05 am

Hi, how i can block weapon pick up, that only ct's can use weapon, but terorist only use knife?
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [Cs:s] How to block weapon pick up

Postby Kami » Sun Dec 20, 2020 12:40 pm

Hey, I think SourcePython has exactly the functionality you are looking for.

http://wiki.sourcepython.com/developing ... strictions
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] How to block weapon pick up

Postby cssbestrpg » Sun Dec 20, 2020 2:04 pm

Hi Kami, i tried use that, but i don't get/understand how i can use it to block weapon pickup
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [Cs:s] How to block weapon pick up

Postby VinciT » Sun Dec 20, 2020 5:30 pm

There's an excellent post by satoon101 describing how weapon restriction works. This is what you're looking for:

Syntax: Select all

# ../weapon_restrict_example/weapon_restrict_example.py

# Source.Python
from filters.weapons import WeaponClassIter
from weapons.restrictions import WeaponRestrictionHandler


my_handler = WeaponRestrictionHandler()

# Restrict Terrorists from using any weapon besides their knife.
my_handler.add_team_restrictions(
2, *[weapon.basename for weapon in WeaponClassIter(not_filters='knife')])

You could also do something like this:

Syntax: Select all

# ../weapon_restrict_example2/weapon_restrict_example2.py

# Source.Python
from events import Event
from players.entity import Player
from filters.weapons import WeaponClassIter


# List containing every weapon name except the knife.
weapons = [weapon.basename for weapon in WeaponClassIter(not_filters='knife')]


@Event('player_spawn')
def player_spawn(event):
"""Called when a player spawns."""
player = Player.from_userid(event['userid'])
# Is this a terrorist?
if player.team == 2:
# You need to pass the list of restricted weapons as a string.
# (e.g. ['awp', 'ak47', 'm4a1'] -> 'awp ak47 m4a1')
player.restrict_weapons(*weapons)
ImageImageImageImageImage
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] How to block weapon pick up

Postby cssbestrpg » Mon Dec 21, 2020 9:53 am

Thank You VinciT, now i got it work, it works perfectly

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 43 guests