[CSGO] Problem with "remove_team_restrictions"

Please post any questions about developing your plugin here. Please use the search function before posting!
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

[CSGO] Problem with "remove_team_restrictions"

Postby existenz » Mon Mar 13, 2017 9:03 pm

Hey !

I have a problem with remove_team_restrictions, it doesn't work. I tried to remove the restriction after having restricted team but the weapon still restricted.

Code :
This is not my real code but i used that to restrict and unrestrict.
If you need the whole plugin tell me.

Syntax: Select all

_scout = ['ssg08']
_all_weapons = set(weapon.name for weapon in WeaponClassIter())
restrict_handler = WeaponRestrictionHandler()

restrict_handler.add_team_restrictions(3, *_scout)
restrict_handler.remove_team_restrictions(3, *_all_weapons)


Maybe somethings is wrong ?

Sincercly Existenz.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CSGO] Problem with "remove_team_restrictions"

Postby satoon101 » Tue Mar 14, 2017 12:32 am

The issue has to be somewhere else in your code:

Syntax: Select all

from filters.weapons import WeaponClassIter
from weapons.restrictions import WeaponRestrictionHandler

_scout = ['ssg08']
_all_weapons = set(weapon.name for weapon in WeaponClassIter())
restrict_handler = WeaponRestrictionHandler()

print(restrict_handler.team_restrictions[3])
restrict_handler.add_team_restrictions(3, *_scout)
print(restrict_handler.team_restrictions[3])
restrict_handler.remove_team_restrictions(3, *_all_weapons)
print(restrict_handler.team_restrictions[3])

Output:

Syntax: Select all

set()
{'ssg08'}
set()
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: [CSGO] Problem with "remove_team_restrictions"

Postby existenz » Tue Mar 14, 2017 8:29 am

Thanks.
I will try when i m back from my job.
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: [CSGO] Problem with "remove_team_restrictions"

Postby existenz » Tue Mar 14, 2017 9:15 pm

Hey !
Effectively your code works but i have a problem in my plugin.
My plugin allow cvar and restrict by map. I have put in my de_dust2.cfg "restrict_ssg08_t 1", so when i am on d2 the scout is restricted for t. It works fine. When i m changing map to one other like office i'm suppose to access to all weapon beacause any restrict has been set but the scout is already restricted for t.

I have put some debug i have found this :
https://github.com/VenomzGaming/Sp-Map- ... fig.py#L82

https://github.com/VenomzGaming/Sp-Map- ... fig.py#L98

At line 82 my list is empty which contains t restrict is emptybut but after in OnServerActivate this list has old value (ssg08) ...
I don't know why, but it's not a problem with restrict ^^
If you have an idea why.

Sincerly Existenz.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CSGO] Problem with "remove_team_restrictions"

Postby satoon101 » Wed Mar 15, 2017 3:13 pm

I see the problem. Even though weapon_restrict_t and weapon_restrict_ct are declared at the global scope, you do not declare them as globals in _on_map_start when re-assigning them. When you re-assign and don't declare them as global in a function or method, they are interpreted as being local. You need to do 1 of 2 things to fix that.

  • Declare them as global:

    Syntax: Select all

    @OnLevelInit
    def _on_map_start(map_name):
    global weapon_restrict_t, weapon_restrict_ct

  • Clear them (mutate the object itself) instead of re-assigning:

    Syntax: Select all

    @OnLevelInit
    def _on_map_start(map_name):
    weapon_restrict_t.clear()
    weapon_restrict_ct.clear()
My preferred method would be the 2nd one as using the global keyword should be avoided in pretty much all cases and is typically frowned upon. I still use the global keyword on occasion, but only in very specific situations.
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: [CSGO] Problem with "remove_team_restrictions"

Postby existenz » Wed Mar 15, 2017 4:10 pm

Thanks for you answer.
I will try when i m back :)
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: [CSGO] Problem with "remove_team_restrictions"

Postby existenz » Wed Mar 15, 2017 5:56 pm

Thank you very much :D
It's work like a charm.

I will share it now ;)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 28 guests