Page 1 of 1
[CSGO] Problem with "remove_team_restrictions"
Posted: Mon Mar 13, 2017 9:03 pm
by existenz
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.
Re: [CSGO] Problem with "remove_team_restrictions"
Posted: Tue Mar 14, 2017 12:32 am
by satoon101
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:
Re: [CSGO] Problem with "remove_team_restrictions"
Posted: Tue Mar 14, 2017 8:29 am
by existenz
Thanks.
I will try when i m back from my job.
Re: [CSGO] Problem with "remove_team_restrictions"
Posted: Tue Mar 14, 2017 9:15 pm
by existenz
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#L82https://github.com/VenomzGaming/Sp-Map- ... fig.py#L98At 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.
Re: [CSGO] Problem with "remove_team_restrictions"
Posted: Wed Mar 15, 2017 3:13 pm
by satoon101
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.
Re: [CSGO] Problem with "remove_team_restrictions"
Posted: Wed Mar 15, 2017 4:10 pm
by existenz
Thanks for you answer.
I will try when i m back :)
Re: [CSGO] Problem with "remove_team_restrictions"
Posted: Wed Mar 15, 2017 5:56 pm
by existenz
Thank you very much :D
It's work like a charm.
I will share it now ;)