Advertisement
Guest User

blood.py

a guest
Mar 7th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.87 KB | None | 0 0
  1. from commands import *
  2. from pyspades.world import *
  3. from pyspades.constants import *
  4. from pyspades.server import *
  5. from pyspades.common import *
  6.  
  7. MAX_BLOOD = 2000
  8. BLOOD_COLOR = (175, 20, 20)
  9.  
  10. def apply_script(protocol, connection, config):
  11.     class BloodConnection(connection):
  12.         def on_hit(hitter, hit_amount, hittee, type, grenade):
  13.             if MAX_BLOOD <= 0:
  14.                 return connection.on_hit(hitter, hit_amount, hittee, type, grenade)
  15.             #hitter.protocol.send_chat("on hit: " + hitter.name + ", " + str(hit_amount) + ", " + hittee.name + ", " + str(type) + ", " + str(grenade))
  16.             result = connection.on_hit(hitter, hit_amount, hittee, type, grenade)
  17.             if result == False:
  18.                 return False
  19.             if result is not None:
  20.                 hit_amount = result
  21.             #hitter.protocol.send_chat("hit not cancelled, new damage " + str(hit_amount))
  22.             pos = hittee.world_object.position
  23.             pos2 = hitter.world_object.position
  24.             for i in range(min(10, int(hit_amount / 10) + 1)):
  25.                 #hitter.protocol.send_chat("trace")
  26.                 dir = pos - pos2
  27.                 dir.normalize()
  28.                 dir.x = dir.x + random.random() * 0.4 - 0.2
  29.                 dir.y = dir.y + random.random() * 0.4 - 0.2
  30.                 dir.z = dir.z + random.random() - 0.2
  31.                 dir.normalize()
  32.                 c = Character(hittee.world_object.world, pos, dir)
  33.                 loc = c.cast_ray()
  34.                 if loc:
  35.                 #if cast_ray(hittee.world_object.world.map.map, pos.x, pos.y, pos.z, dir.x, dir.y, dir.z, 8, x, y, z):
  36.                     x, y, z = loc
  37.                     #hitter.protocol.send_chat(str(x) + ", " + str(y) + ", " + str(z) + ", ray found")
  38.                     if x < 0 or y < 0 or z < 0 or z >= 512 or y >= 512 or z >= 62:
  39.                         continue
  40.                     #hitter.protocol.send_chat("painting")
  41.                     if hitter.protocol.map.get_color(x, y, z) == BLOOD_COLOR:
  42.                         continue
  43.                     if hitter.protocol.index >= MAX_BLOOD:
  44.                         solid = hitter.protocol.map.get_point(hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][0], hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][1], hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][2])
  45.                         if solid and hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][3] is not None:
  46.                             hitter.protocol.map.set_point(hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][0], hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][1], hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][2], hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][3])
  47.                             set_color.value = make_color(*hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][3])
  48.                             set_color.player_id = 32
  49.                             hitter.protocol.send_contained(set_color)
  50.                             block_action.x = hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][0]
  51.                             block_action.y = hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][1]
  52.                             block_action.z = hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD][2]
  53.                             block_action.player_id = 32
  54.                             block_action.value = DESTROY_BLOCK
  55.                             hitter.protocol.send_contained(block_action, save = True)
  56.                             block_action.value = BUILD_BLOCK
  57.                             hitter.protocol.send_contained(block_action, save = True)
  58.                     hitter.protocol.blood[hitter.protocol.index % MAX_BLOOD] = (x, y, z, hitter.protocol.map.get_color(x, y, z))
  59.                     hitter.protocol.index = hitter.protocol.index + 1
  60.                     #hitter.protocol.send_chat(str(hitter.protocol.index))
  61.                     hitter.protocol.map.set_point(x, y, z, BLOOD_COLOR)
  62.                     set_color.value = make_color(*BLOOD_COLOR)
  63.                     set_color.player_id = 32
  64.                     hitter.protocol.send_contained(set_color)
  65.                     block_action.x = x
  66.                     block_action.y = y
  67.                     block_action.z = z
  68.                     block_action.player_id = 32
  69.                     block_action.value = DESTROY_BLOCK
  70.                     hitter.protocol.send_contained(block_action, save = True)
  71.                     block_action.value = BUILD_BLOCK
  72.                     hitter.protocol.send_contained(block_action, save = True)
  73.             #hitter.protocol.send_chat("end")
  74.             return hit_amount
  75.     class BloodProtocol(protocol):
  76.         blood = {}
  77.         index = 0
  78.     return BloodProtocol, BloodConnection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement