Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from entities.entity import Entity
- from entities.helpers import edict_from_index
- from players.entity import Player
- from commands import CommandReturn
- from commands.client import ClientCommand
- from stringtables import string_tables
- from engines.server import engine_server
- # syntax: dev_particle <target> <name of the particle system/effect> <particle system lifetime/duration> [height]
- # height is an optional argument, if you don't use it, the particle system will spawn at the entity origin
- # (player's entity origin is at their feet)
- # example: dev_particle self firework_crate_ground_low_02 5
- # this will spawn and parent the 'firework_crate_ground_low_02' particle to yourself
- # example: dev_particle aim explosion_molotov_air_splash01a 2
- # this will spawn the 'explosion_molotov_air_splash01a' particle at your crosshair
- # example: dev_particle 5 molotov_fire01_cheap 10
- # this will spawn and parent the 'molotov_fire01_cheap' particle to the player with index 5
- @ClientCommand('dev_particle')
- def dev_command(command, index):
- # are we missing some command arguments?
- if len(command) < 3:
- debug(index, 'dev_particle <index/aim/self> <particle name> <particle lifetime> [height]')
- return CommandReturn.BLOCK
- # store the command arguments
- target = command[1].lower()
- particle_name = command[2]
- lifetime = int(command[3])
- height = 0
- # was the optional argument 'height' set?
- if len(command) >= 5:
- height = int(command[4])
- # is the target an index?
- if target.isdigit():
- try:
- player = Player(int(target))
- origin = player.origin
- except:
- debug(index, 'dev_particle: invalid player index')
- return CommandReturn.BLOCK
- else:
- player = Player(index)
- if target == 'self':
- origin = player.origin
- elif target == 'aim':
- origin = player.get_view_coordinates()
- else:
- debug(index, 'dev_particle: invalid target')
- return CommandReturn.BLOCK
- origin.z += height
- particle = create_particle(origin, particle_name, lifetime)
- if not target == 'aim':
- particle.set_parent(player, -1)
- return CommandReturn.BLOCK
- def create_particle(position, particle_name, lifetime):
- # create and store the 'info_particle_system' entity in the 'particle' variable
- particle = Entity.create('info_particle_system')
- # set the 'effect name' of the particle
- # you can find more particle effect names here: https://developer.valvesoftware.com/wiki/List_of_CS_GO_Particles
- # that list isn't complete though, there are loads more that you can find if you poke around the CSGO .pcf files
- particle.effect_name = particle_name
- # set the position where the particle will spawn
- particle.origin = position
- # add the particle effect index to the server particle effect stringtable
- particle.effect_index = string_tables.ParticleEffectNames.add_string(particle_name)
- # make sure the particle system starts as soon as it spawns
- particle.start_active = 1
- # in case the above part fails, force the start of the particle system
- particle.start()
- # after the specified 'lifetime', kill the particle system
- # setting the lifetime to 0 will make it last until the round ends
- # NOTE: some particle effects have a built-in lifetime
- # this means that even if you set the lifetime to 0 or something long,
- # they will end whenever their built-in lifetime ends
- if lifetime > 0:
- particle.delay(lifetime, particle.remove)
- # return the particle system so we can do cool stuff with it (like parenting it to a player)
- return particle
- def debug(index, message):
- engine_server.client_command(edict_from_index(index), 'echo {0}'.format(message))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement