SHARE
TWEET

TrueClip v1.01

a guest May 26th, 2014 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """TRUECLIP by Influx v1.01 for AoS 0.76
  2.  
  3. Adds realistic clips to the game. The server remembers how much ammo is in
  4. each clip, so if you have 1 bullet in your clip when you reload, at some
  5. point, you will reload to have only 1 bullet in your clip.
  6.  
  7. It will always reload the clip with the most bullets in.
  8.  
  9. Applies to Rifles and SMG's
  10.  
  11. """
  12.  
  13. from twisted.internet.task import LoopingCall
  14. from twisted.internet.reactor import callLater
  15. from pyspades.server import weapon_reload
  16. import math
  17.  
  18. def apply_script(protocol, connection, config):
  19.     class TrueClipConnection(connection):
  20.        
  21.         def on_spawn(self, pos):
  22.             self.protocol.trueclip_dict[self] = {}
  23.             if (self.weapon_object.stock+self.weapon_object.ammo) % self.weapon_object.ammo:
  24.                 clipno = int((self.weapon_object.stock+self.weapon_object.ammo)/self.weapon_object.ammo)
  25.                 round_no = True
  26.                 spare_ammo = 0
  27.             else:
  28.                 clipno = int(math.ceil((self.weapon_object.stock+self.weapon_object.ammo)/self.weapon_object.ammo))
  29.                 round_no = False
  30.                 spare_ammo = ((self.weapon_object.stock+self.weapon_object.ammo)-(self.weapon_object.ammo*(clipno - 1)))
  31.             self.protocol.trueclip_dict[self]['clipno'] = clipno
  32.             for x in xrange(0, clipno, 1):
  33.                 if round_no:
  34.                     key = "clip{0}".format(x)
  35.                     self.protocol.trueclip_dict[self][key] = self.weapon_object.ammo
  36.                 elif not round_no:
  37.                     if x == clipno:
  38.                         key = "clip{0}".format(x)
  39.                         self.protocol.trueclip_dict[self][key] = spare_ammo
  40.                     else:
  41.                         key = "clip{0}".format(x)
  42.                         self.protocol.trueclip_dict[self][key] = self.weapon_object.ammo
  43.             self.protocol.trueclip_dict[self]['current_clip'] = "clip0"
  44.             self.protocol.trueclip_dict[self]['current_stock'] = self.weapon_object.stock
  45.             return connection.on_spawn(self, pos)
  46.        
  47.         def _on_reload(self):
  48.             if self.weapon == 0 or self.weapon == 1:
  49.                 callLater(0.01, self.ammo_adjust)
  50.  
  51.             weapon_reload.player_id = self.player_id
  52.             weapon_reload.clip_ammo = self.weapon_object.current_ammo
  53.             weapon_reload.reserve_ammo = self.weapon_object.current_stock
  54.             self.send_contained(weapon_reload)
  55.             return connection._on_reload(self)
  56.        
  57.         def ammo_adjust(self):
  58.             curr_clip = self.protocol.trueclip_dict[self]['current_clip']
  59.             next_clip = None
  60.             cur_ammo = 0
  61.             for x in xrange(0, self.protocol.trueclip_dict[self]['clipno']):
  62.                 if self.protocol.trueclip_dict[self]["clip{0}".format(x)]>cur_ammo:
  63.                     cur_ammo = self.protocol.trueclip_dict[self]["clip{0}".format(x)]
  64.                     next_clip = "clip{0}".format(x)
  65.             self.protocol.trueclip_dict[self]['current_stock'] += self.protocol.trueclip_dict[self][curr_clip]
  66.             self.protocol.trueclip_dict[self]['current_clip'] = next_clip
  67.             self.protocol.trueclip_dict[self]['current_stock'] -= self.protocol.trueclip_dict[self][next_clip]
  68.             self.weapon_object.current_stock = self.protocol.trueclip_dict[self]['current_stock']
  69.             self.weapon_object.current_ammo = self.protocol.trueclip_dict[self][next_clip]
  70.             weapon_reload.player_id = self.player_id
  71.             weapon_reload.clip_ammo = self.protocol.trueclip_dict[self][next_clip]
  72.             weapon_reload.reserve_ammo = self.protocol.trueclip_dict[self]['current_stock']
  73.             self.send_contained(weapon_reload)
  74.        
  75.         def on_shoot_set(self, fire):
  76.             if self.weapon == 1:
  77.                 fire_delay_offset = 0.01
  78.             elif self.weapon == 0:
  79.                 fire_delay_offset = 0
  80.             if (self.weapon == 0 or self.weapon == 1) and self.tool == 2 and fire:
  81.                 self.shot_timer = LoopingCall(self.shot_fired)
  82.                 self.shot_timer.start(self.weapon_object.delay-fire_delay_offset)
  83.             if not fire:
  84.                 self.shot_timer.stop()
  85.             return connection.on_shoot_set(self, fire)
  86.        
  87.         def shot_fired(self):
  88.             current_clip = self.protocol.trueclip_dict[self]['current_clip']
  89.             if self.protocol.trueclip_dict[self][current_clip] >=1:
  90.                 self.protocol.trueclip_dict[self][current_clip] -= 1
  91.                
  92.         def on_refill(self):
  93.             if (self.weapon_object.stock+self.weapon_object.ammo) % self.weapon_object.ammo:
  94.                 clipno = int((self.weapon_object.stock+self.weapon_object.ammo)/self.weapon_object.ammo)
  95.                 round_no = True
  96.                 spare_ammo = 0
  97.             else:
  98.                 clipno = int(math.ceil((self.weapon_object.stock+self.weapon_object.ammo)/self.weapon_object.ammo))
  99.                 round_no = False
  100.                 spare_ammo = ((self.weapon_object.stock+self.weapon_object.ammo)-(self.weapon_object.ammo*(clipno - 1)))
  101.             self.protocol.trueclip_dict[self]['clipno'] = clipno
  102.             for x in xrange(0, clipno, 1):
  103.                 if round_no:
  104.                     key = "clip{0}".format(x)
  105.                     self.protocol.trueclip_dict[self][key] = self.weapon_object.ammo
  106.                 elif not round_no:
  107.                     if x == clipno:
  108.                         key = "clip{0}".format(x)
  109.                         self.protocol.trueclip_dict[self][key] = spare_ammo
  110.                     else:
  111.                         key = "clip{0}".format(x)
  112.                         self.protocol.trueclip_dict[self][key] = self.weapon_object.ammo
  113.             self.protocol.trueclip_dict[self]['current_clip'] = "clip0"
  114.             self.protocol.trueclip_dict[self]['current_stock'] = self.weapon_object.stock
  115.             weapon_reload.player_id = self.player_id
  116.             weapon_reload.clip_ammo = self.protocol.trueclip_dict[self]["clip0"]
  117.             weapon_reload.reserve_ammo = self.protocol.trueclip_dict[self]['current_stock']
  118.             self.send_contained(weapon_reload)
  119.             return connection.on_refill(self)
  120.        
  121.         def on_disconnect(self):
  122.             if self in self.protocol.trueclip_dict:
  123.                 del self.protocol.trueclip_dict[self]
  124.             return connection.on_disconnect(self)
  125.            
  126.     class TrueClipProtocol(protocol):
  127.         trueclip_dict = {}
  128.            
  129.     return TrueClipProtocol, TrueClipConnection
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top