particles.lua help (again)
Posted: Sun Jan 19, 2020 10:50 pm
by Hammerless Penguin
I'm trying to make certain npcs leave trails of smoke and fire as they move but i'm not sure how to make npcs do that. I've seen this been done before but I still don't know how to do it.
Re: particles.lua help (again)
Posted: Mon Jan 20, 2020 1:10 am
by Enjl
Here's step-by-step how most people do this:
1) Make an empty table which you will use for all emitters that have been spawned. This list will be responsible for drawing the emitters. People don't use NPC code for drawing emitters because when the NPC dies, that just means all the particles will also die instantly as they no longer get drawn.
2) In onDraw, loop over the list and call :Draw(priority) on every emitter to make sure it draws.
3) Time to populate the list! In your for loop over your NPCs, wrap the NPC in pnpc and then, if v.data.emitter is nil, set it to a new emitter of the file you wish to use.
4) Remember to call v.data.emitter:Attach(v) to make the emitter move with the NPC, and to insert v.data.emitter into the emitter table for drawing.
For the last part, there are two ways to go about it. You have to stop spawning particles when the NPCs die.
5a) Set the rate of your emitter to 0 and manually spawn particles in the NPC tick function using v.data.emitter:Emit(amount).
5b) Assign v.data.emitter.enabled = false when the NPC dies in onNPCKill
Re: particles.lua help (again)
Posted: Mon Jan 20, 2020 7:42 am
by Hammerless Penguin
Enjl wrote: ↑Mon Jan 20, 2020 1:10 am
Here's step-by-step how most people do this:
1) Make an empty table which you will use for all emitters that have been spawned. This list will be responsible for drawing the emitters. People don't use NPC code for drawing emitters because when the NPC dies, that just means all the particles will also die instantly as they no longer get drawn.
2) In onDraw, loop over the list and call :Draw(priority) on every emitter to make sure it draws.
3) Time to populate the list! In your for loop over your NPCs, wrap the NPC in pnpc and then, if v.data.emitter is nil, set it to a new emitter of the file you wish to use.
4) Remember to call v.data.emitter:Attach(v) to make the emitter move with the NPC, and to insert v.data.emitter into the emitter table for drawing.
For the last part, there are two ways to go about it. You have to stop spawning particles when the NPCs die.
5a) Set the rate of your emitter to 0 and manually spawn particles in the NPC tick function using v.data.emitter:Emit(amount).
5b) Assign v.data.emitter.enabled = false when the NPC dies in onNPCKill
Im still a bit confused. Can you give me an example code on how to assemble all of this?