Bomb Effects (Quality of Life Plugin)

Release your plugins here!
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Bomb Effects (Quality of Life Plugin)

Postby Predz » Sun Nov 01, 2015 8:23 pm

I am going to be releasing a few quality of life plugins within the next few days for people to see.

First of which is just a simple set of bomb effects which make it easier for players on the server to locate the bomb upon being planted. Many players have requested I put this into my server, so all enjoy. :D

Syntax: Select all

##
## IMPORTS
##

from effects import temp_entities
from engines.precache import Model
from entities.entity import Entity
from events import Event
from filters.entities import EntityIter
from filters.recipients import RecipientFilter

_smokestack = None

_tick_model = Model('sprites/laser.vmt')

##
## FUNCTIONS
##

def get_recipients():
return RecipientFilter()

##
## EVENTS
##

@Event('bomb_planted')
def bomb_planted(event):
for ent in EntityIter('planted_c4', return_types='entity'):
bomb = ent
break

entity = Entity.create('env_smokestack')
entity.origin = bomb.origin
for output in ('basespread 8', 'spreadspeed 55', 'speed 80', 'rate 60', 'startsize 1', 'endsize 5', 'twist 30', 'jetlength 95', 'angles 0 0 0', 'rendercolor 255 10 10', 'SmokeMaterial particle/fire.vmt'):
entity.add_output(output)
entity.call_input('TurnOn')

global _smokestack
_smokestack = entity

@Event('bomb_defused')
def bomb_defused(event):
_smokestack.add_output('rendercolor 10 10 255')

origin = _smokestack.origin
index = _tick_model.index
recipients = get_recipients()
for t in range(0, 5):
temp_entities.beam_ring_point(recipients, t, origin, 20, 200, index, index, 0, 255, 1, 8, 1, 1, 10, 10, 255, 255, 1, 0)
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sun Nov 01, 2015 8:41 pm

Nice release! Few improvements to the Python code:

Syntax: Select all

global _smokestack
_smokestack = None
You don't need the global keyword here, as it's already global. You do need the keyword when you're setting it on line 42 though, since we're in a function by then.

The way you're getting the bomb (conditionless break in a for loop):

Syntax: Select all

for ent in EntityIter('planted_c4', return_types='entity'):
bomb = ent
break
Is quite likely never the best solution. This could all be replaced by using the built-in function next():

Syntax: Select all

bomb = next(EntityIter('planted_c4', return_types='entity'))
Although this will raise StopIteration exception if there is no bomb to be found, but then you just handle it using try/except. And if there was a chance that there was no bomb, you would have to do a check for the bomb with the for loop, too so next() is still a better solution.

Finally, the get_recipients() function could probably be replaced with a single global variable that contains the filter's parameter, but that's just my opinion, you might have a good reason to provide a function (which is indeed more capable) for this.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Nov 01, 2015 8:55 pm

You should avoid add_output and use the keyvalue setter methods of BaseEntity
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Postby Predz » Sun Nov 01, 2015 9:54 pm

Thanks for the feedback :)

Will update this within the next few hours...
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Nov 04, 2015 12:51 am

Another point about this line:

Syntax: Select all

for ent in EntityIter('planted_c4', return_types='entity'):
bomb = ent
break


There is no reason to loop using one name then assign that value a different name in this instance. Simply use:

Syntax: Select all

for bomb in EntityIter('planted_c4', return_types='entity'):
break


And, if you use that instead of next(), I know it is unlikely to ever happen, especially given the event you are in, but you might want to check for the existence of that entity type:

Syntax: Select all

for bomb in EntityIter('planted_c4', return_types='entity'):
break
# Was no planted_c4 entity found?
else:
return



Also, I am going to write a quick tutorial on how to add those types of values you are attempting to set to our data to make it easier on yourself.
Image

Return to “Plugin Releases”

Who is online

Users browsing this forum: No registered users and 8 guests