[SCRIPT] weapontier
Posted: Wed Jul 03, 2013 5:13 pm
Basically sets what weapons are available based on the number of kills you have
Requested by Jdrew
Requested by Jdrew
Code: Select all
"""
thepolm3
Enables weapons by kills
requested by Jdrew
"""
RIFLE,SMG,SHOTGUN=range(3)
UNLOCK_ORDER = [SHOTGUN,SMG,RIFLE]
INCREMENT = 5 #every 5 kills go up a level
from commands import add,admin,name
from server import weapon_reload
from twisted.internet.reactor import callLater
def apply_script(protocol,connection,config):
class WeaponTierConnection(connection):
def on_connect(self):
self.unlocked_weapons = -1.0
connection.on_connect(self)
def on_kill(self,by,type,grenade):
if by and self!=by:
by.unlocked_weapons+=(1/INCREMENT)
by.refresh_weapon()
return connection.on_kill(self,by,type,grenade)
def spawn(self):
self.refresh_weapon()
return connection.spawn(self)
def refresh_weapon(self):
if self.weapon==RIFLE and self.unlocked_weapons < UNLOCK_ORDER.index(RIFLE): self.weapon=SHOTGUN
if self.weapon==SHOTGUN and self.unlocked_weapons < UNLOCK_ORDER.index(SHOTGUN): self.weapon=SMG
if self.weapon==SMG and self.unlocked_weapons < UNLOCK_ORDER.index(SMG): self.weapon=RIFLE
if self.unlocked_weapons < 0: #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==RIFLE and self.unlocked_weapons < UNLOCK_ORDER.index(RIFLE): return False
if weapon==SHOTGUN and self.unlocked_weapons < UNLOCK_ORDER.index(SHOTGUN): return False
if weapon==SMG and self.unlocked_weapons < UNLOCK_ORDER.index(SMG): 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)
return protocol,WeaponTierConnection