Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #taser_particle_example.py
  2.  
  3. from players.entity import Player
  4. from entities.entity import Entity
  5. from commands.say import SayCommand
  6. from stringtables import string_tables
  7.  
  8.  
  9. @SayCommand('spawn')
  10. def spawn_effect(command, index, team_only=None):
  11.     player = Player(index)
  12.     taze(player.eye_location, player.view_coordinates, player.view_angle)
  13.  
  14.  
  15. def taze(start_pos, end_pos, start_angle):
  16.     # This is our main particle effect.
  17.     particle1 = Entity.create('info_particle_system')
  18.     # We are using particle2 as our controlpoint1.
  19.     particle2 = Entity.create('info_particle_system')
  20.  
  21.     # Name for controlpoint1 (cpoint1).
  22.     cp_name = f'cp_for_{particle1.index}'
  23.  
  24.     # Setting the correct particle effects.
  25.     particle1.effect_name = 'weapon_tracers_taser'
  26.     particle2.effect_name = 'weapon_taser_glow_impact'
  27.  
  28.     # Add the particle effects to the stringtables,
  29.     # and in return, get the particle effect indexes
  30.     particle1.effect_index = string_tables.ParticleEffectNames.add_string('weapon_tracers_taser')
  31.     particle2.effect_index = string_tables.ParticleEffectNames.add_string('weapon_taser_glow_impact')
  32.  
  33.     # Setting the position and angle of the particle effect.
  34.     # (without the angle, the taser effect will look odd)
  35.     particle1.origin = start_pos
  36.     particle1.teleport(None, start_angle, None)
  37.     particle2.origin = end_pos
  38.    
  39.     # Use 'cp_name' as the targetname for particle2 - since this is where we
  40.     # want the taser effect to go / end.
  41.     particle2.set_key_value_string('targetname', cp_name)
  42.  
  43.     # This is where the magic happens.
  44.     # Setting this to the same name as particle2's targetname will make it
  45.     # work properly.
  46.     particle1.cpoint1 = cp_name
  47.  
  48.     # Make sure the particle starts as soon as it spawns.
  49.     particle1.start_active = 1
  50.     particle2.start_active = 1
  51.  
  52.     # In case the above part fails, force them to start.
  53.     particle1.start()
  54.     particle2.start()