Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. from entities.entity import Entity
  2. from entities.helpers import edict_from_index
  3.  
  4. from players.entity import Player
  5.  
  6. from commands import CommandReturn
  7. from commands.client import ClientCommand
  8.  
  9. from stringtables import string_tables
  10. from engines.server import engine_server
  11.  
  12.  
  13. # syntax: dev_particle <target> <name of the particle system/effect> <particle system lifetime/duration> [height]
  14. # height is an optional argument, if you don't use it, the particle system will spawn at the entity origin
  15. # (player's entity origin is at their feet)
  16.  
  17. # example: dev_particle self firework_crate_ground_low_02 5
  18. # this will spawn and parent the 'firework_crate_ground_low_02' particle to yourself
  19.  
  20. # example: dev_particle aim explosion_molotov_air_splash01a 2
  21. # this will spawn the 'explosion_molotov_air_splash01a' particle at your crosshair
  22.  
  23. # example: dev_particle 5 molotov_fire01_cheap 10
  24. # this will spawn and parent the 'molotov_fire01_cheap' particle to the player with index 5
  25.  
  26. @ClientCommand('dev_particle')
  27. def dev_command(command, index):
  28.     # are we missing some command arguments?
  29.     if len(command) < 3:
  30.         debug(index, 'dev_particle <index/aim/self> <particle name> <particle lifetime> [height]')
  31.         return CommandReturn.BLOCK
  32.  
  33.     # store the command arguments
  34.     target = command[1].lower()
  35.     particle_name = command[2]
  36.     lifetime = int(command[3])
  37.  
  38.     height = 0
  39.     # was the optional argument 'height' set?
  40.     if len(command) >= 5:
  41.         height = int(command[4])
  42.  
  43.     # is the target an index?
  44.     if target.isdigit():
  45.         try:    
  46.             player = Player(int(target))
  47.             origin = player.origin
  48.         except:
  49.             debug(index, 'dev_particle: invalid player index')
  50.             return CommandReturn.BLOCK
  51.     else:
  52.         player = Player(index)
  53.  
  54.         if target == 'self':
  55.             origin = player.origin
  56.         elif target == 'aim':
  57.             origin = player.get_view_coordinates()
  58.         else:
  59.             debug(index, 'dev_particle: invalid target')
  60.             return CommandReturn.BLOCK
  61.  
  62.     origin.z += height
  63.     particle = create_particle(origin, particle_name, lifetime)
  64.  
  65.     if not target == 'aim':
  66.         particle.set_parent(player, -1)
  67.  
  68.     return CommandReturn.BLOCK
  69.  
  70.  
  71. def create_particle(position, particle_name, lifetime):
  72.     # create and store the 'info_particle_system' entity in the 'particle' variable
  73.     particle = Entity.create('info_particle_system')
  74.  
  75.     # set the 'effect name' of the particle
  76.     # you can find more particle effect names here: https://developer.valvesoftware.com/wiki/List_of_CS_GO_Particles
  77.     # that list isn't complete though, there are loads more that you can find if you poke around the CSGO .pcf files
  78.     particle.effect_name = particle_name
  79.  
  80.     # set the position where the particle will spawn
  81.     particle.origin = position
  82.  
  83.     # add the particle effect index to the server particle effect stringtable
  84.     particle.effect_index = string_tables.ParticleEffectNames.add_string(particle_name)
  85.  
  86.     # make sure the particle system starts as soon as it spawns
  87.     particle.start_active = 1
  88.  
  89.     # in case the above part fails, force the start of the particle system
  90.     particle.start()
  91.  
  92.     # after the specified 'lifetime', kill the particle system
  93.     # setting the lifetime to 0 will make it last until the round ends
  94.     # NOTE: some particle effects have a built-in lifetime
  95.     # this means that even if you set the lifetime to 0 or something long,
  96.     # they will end whenever their built-in lifetime ends
  97.     if lifetime > 0:
  98.         particle.delay(lifetime, particle.remove)
  99.  
  100.     # return the particle system so we can do cool stuff with it (like parenting it to a player)
  101.     return particle
  102.  
  103.  
  104. def debug(index, message):
  105.     engine_server.client_command(edict_from_index(index), 'echo {0}'.format(message))