[SCRIPT] WeaponDisable
Posted: Tue Jul 02, 2013 5:13 pm
This script lets you control which weapons are in play and freely change them with a commmand
the commands are;
By default the SMG is disabled, the defaults can be changed in the script config
the commands are;
Spoiler:
Code: Select all
Happy customweaponing!"""
thepolm3
Enable or disable weapons at will
requested by Faker
"""
RIFLE_ENABLED=True
SHOTGUN_ENABLED=True
SMG_ENABLED=False
from commands import add,admin,name
from pyspades.server import weapon_reload
from twisted.internet.reactor import callLater
def RCNI(letters,string): #remove charachters not in letters
ret=""
for letter in string:
if letter in letters:
ret+=letter
return ret
@admin
@name("toggle")
def toggle_weapon( connection , weapon , boolean = None ):
if RCNI("rifle",weapon.lower())=="rifle":
return toggle_rifle(connection,boolean)
if RCNI("shotgun",weapon.lower())=="shotgun":
return toggle_shotgun(connection,boolean)
if RCNI("smg",weapon.lower())=="smg":
return toggle_smg(connection,boolean)
if RCNI("all",weapon.lower())=="all":
if boolean==None:
return "Please do either '/toggle all off' or '/toggle all on'"
toggle_rifle(connection,boolean)
toggle_shotgun(connection,boolean)
toggle_smg(connection,boolean)
return "All weapon now %s" %(["OFF","ON"][boolean=="on"])
return "Please specify either rifle, smg, shotgun or all"
@admin
@name("trifle")
def toggle_rifle(connection,boolean=None):
global RIFLE_ENABLED
RIFLE_ENABLED = boolean.lower()=="on" if boolean!=None else not RIFLE_ENABLED
connection.protocol.reset_all_weapons()
return "Rifle %sabled." %(["dis","en"][RIFLE_ENABLED])
@admin
@name("tshotgun")
def toggle_shotgun(connection,boolean=None):
global SHOTGUN_ENABLED
SHOTGUN_ENABLED = boolean.lower()=="on" if boolean!=None else not SHOTGUN_ENABLED
connection.protocol.reset_all_weapons()
return "Shotgun %sabled." %(["dis","en"][SHOTGUN_ENABLED])
@admin
@name("tsmg")
def toggle_smg(connection,boolean=None):
global SMG_ENABLED
SMG_ENABLED = boolean.lower()=="on" if boolean!=None else not SMG_ENABLED
connection.protocol.reset_all_weapons()
return "SMG %sabled." %(["dis","en"][SMG_ENABLED])
add(toggle_weapon)
add(toggle_rifle)
add(toggle_shotgun)
add(toggle_smg)
def apply_script(protocol,connection,config):
class WDConnection(connection):
def spawn(self):
self.refresh_weapon()
return connection.spawn(self)
def refresh_weapon(self):
if self.weapon==0 and not RIFLE_ENABLED: self.weapon=2
if self.weapon==2 and not SHOTGUN_ENABLED: self.weapon=1
if self.weapon==1 and not SMG_ENABLED: self.weapon=0
if not (RIFLE_ENABLED or SHOTGUN_ENABLED or SMG_ENABLED): #if all disabled
self.set_ammo(0,0)
else:
wep=self.weapon_object
if wep.current_stock==0 and wep.current_ammo==0:
self.set_ammo(wep.ammo,wep.stock)
def on_weapon_set(self,weapon):
if weapon==0 and not RIFLE_ENABLED: return False
if weapon==2 and not SHOTGUN_ENABLED: return False
if weapon==1 and not SMG_ENABLED: return False
return connection.on_weapon_set(self,weapon)
def set_ammo(self, new_ammo, new_stock=None):
new_ammo=max(min(255,new_ammo),0)
new_stock=max(min(255,new_stock),0)
weapon=self.weapon_object
weapon.current_ammo = new_ammo
weapon_reload.player_id = self.player_id
weapon_reload.clip_ammo = new_ammo
weapon.current_stock = new_stock
weapon_reload.reserve_ammo = new_stock
self.send_contained(weapon_reload)
class WDProtocol(protocol):
def reset_all_weapons(self):
for player in self.players.values():
player.refresh_weapon()
return WDProtocol,WDConnection