Page 1 of 1

When to create and cache a TempEntity?

Posted: Mon Dec 13, 2021 3:34 pm
by Mahi
Hi, how often should I create a new TempEntity instance?

Say I'm creating a skill for an RPG mod and want to draw a laser beam between two people to indicate extra damage. I see three options:
  1. Create a new TempEntity for every player_hurt event and only cache the models
  2. Create and cache one TempEntity for identical laser beams, i.e. each RPG skill would have its own effects and only the location of the beam would change
  3. Create and cache one TempEntity for each model, i.e. have a global cache of temp entities for models
Which one would be the best? The name TempEntity really sounds like I shouldn't cache it at all, but I see some other mods caching them either permanently or per-effect.

Re: When to create and cache a TempEntity?

Posted: Mon Dec 13, 2021 9:13 pm
by L'In20Cible
Taking your example here you could preset all the following because it doesn't change:

Syntax: Select all

model = Model('sprites/laserbeam.vmt')
te = TempEntity('BeamRingPoint')
te.start_radius = 40
te.end_radius = 60
te.frame_rate = 100
te.life_time = 1
te.start_width = 10
te.end_width = 60
te.fade_length = 6
te.amplitude = 10
te.red = 255
te.green = 100
te.blue = 100
te.alpha = 255
te.speed = 100

@Event('player_jump')
def player_jump(ev):
te.model = model
te.halo = model
te.center = Player.from_userid(ev['userid']).origin
te.create()

Re: When to create and cache a TempEntity?

Posted: Mon Dec 13, 2021 9:40 pm
by Mahi
And I can reuse this throughout the plugin's entire lifetime? Just making sure :grin:

Re: When to create and cache a TempEntity?

Posted: Mon Dec 13, 2021 9:44 pm
by L'In20Cible
Mahi wrote:And I can reuse this throughout the plugin's entire lifetime? Just making sure :grin:

Yes. The engine uses a global instance and set all values every times it sends one, but the TempEntity class was designed with isolation in mind and make a copy of the global instance so that each instances have their own values that don't affect others from other plugins, etc.

Re: When to create and cache a TempEntity?

Posted: Mon Dec 13, 2021 9:47 pm
by Mahi
Thank you for all the help L'In20Cible! :)