Hello. I started doing a PUBG gamemode for gmod. And i want to make a gas spread, like in PUBG. How can i do it?
I did exactly this like 2-3 months ago. First thing I would do is make multiple "grids" inside of a table, I use one to represent the index, one for the height and one to represent the normal plane. To put it easier it looked something like this:
table[1][1][-1][1] = true
table[2][0][-1][0] = true
1 unit being how dense you want the gas to be, for example we can have 1 unit being 10HU, the system is also localized to make it easier to work with.
That example I did means: The first gas source is 3 units above the initial point, 1 unit on the left and 3 units in front (You can have them arranged however you like). The second is 0 unit above, 1 unit on the left and 0 units in front.
Now I have a timer that goes to a random piece in the table (You can just have a timer to go to every piece if you want it to exponentially grow, I don't recomment it though) and check 1 random unit away from it if there's space in there, it there is then it adds this new source to the table and so on.
Now that's a way I would do it, how I did it before was just using point entities as the gas sources and every gas source would check around it if there was a gas source or something to block the way, if there wasn't then it wouldn't expand, if there wasn't anything then it would. Also I made it so each one that spawned a new piece would set itself as the parent of the entity and every like 1-2 seconds each one checked if their parent was still there (Making sure that timer was ALWAYS shorter than the timer for expanding), if it wasn't there then it would kill itself, so if you blocked the source every other piece will disappear. This is the easiest way to approach it. Here's two videos of how it came out:
https://www.youtube.com/watch?v=TqYXGK7TR6Y
https://www.youtube.com/watch?v=0ZW4aXF0uyg
Looks cool, but i don't know how to write the code, cuz i'm beginner ^_^
Check out some Lua tutorials here: Learning Lua and GLua
Okay, ty
Hey @ResQq , sorry to say it but someone already did make a PUBG gamemode: GMOD Battlegrounds
And I don't want to sound snarky but you did mention you're a beginner and he isn't, he spent 3 weeks on it and I'm sure it's better than what you can come up with. (Sorry again if I sounded aggressive)
You can still go for it as training to better yourself, but Gmod is old enough that most stuff has already been made and perfectioned.
It's ok bro) I'm just didn't know about already done PUBG gamemode. Thank you)
Mmmm looks like the creator stopped working on it or never released it, I'm not sure.
You should still develop it now that I see, there's no way to play that one.
Ok, i need the circle, that will be narrowed, and people who will be out of zone, will be damaged.
I tried that tool out, the creator is good but the item is pretty trash. It takes less time to learn standard CLuaParticles.
So i can realize my idea, using CLuaParticles?
Yeah sure
What i need to start?
--Put this at the beginning of the code (CLIENT) or any initialization hook
local fxEmitter = ParticleEmitter(vector_origin)
local function spawnSmokeCloud()
--Let's now spawn the particle 100 units above the position you're aiming at
local startPos = LocalPlayer():GetEyeTrace().HitPos + Vector(0,0,100)
if(fxEmitter) then --We check if fxEmitter exists, who knows
local fxParticle = fxEmitter:Add("particle/smokesprites_0004", startPos) --Smokesprite_0004 is one that I use the most
if(fxParticle) then --We check if the particle was spawned succesfully, some clients do stop generating them
fxParticle:SetVelocity(VectorRand()*10) --This will make it travel in a random direction
fxParticle:SetDieTime(1) --After 1 second it will disappear
fxParticle:SetStartAlpha(150) --When it gets spawned its alpha is 150, about 2/3 visible
fxParticle:SetEndAlpha(0) --It will gradually get more invisible and at the 1 second mark it will be 0 alpha
fxParticle:SetStartSize(5) --At the beginning it's this big
fxParticle:SetEndSize(60) --And at the end it's 12 times bigger, this makes it look like it's expanding
fxParticle:SetAngleVelocity(Angle(math.Rand(-5,5),0,0)) --Just to add randomness I make it rotate a bit
fxParticle:SetColor(120,20,70,255) --This will set its color, it's a dark pink
fxParticle:SetCollide(true) --This will make it collide with the world (AND ONLY WORLD)
fxParticle:SetGravity(Vector(0,0,-30)) --This will make it gradually go UP in the air, even if it spawns in being launched below it will slow down and start going up
end
end
end
--You can put it in a timer or a hook if you want to.
timer.Create("SpawnLotsOfClouds", 0.1, 50, spawnSmokeCloud())
Here's an example I made just for you
it says me "
[ERROR] gamemodes/garry's_mode_battlegrounds/gamemode/init.lua:6: attempt to call global 'ParticleEmitter' (a nil value)
"
Read the comments of the code carefully - init.lua is ran serverside.
So where i need to put this code?
Read the first line (the comment) of the code he provided. init is serverside and cl_init is clientside.
Oh, i understood, but when i put it in cl_init, it says me this
[ERROR] gamemodes/garry's_mode_battlegrounds/gamemode/cl_init.lua:35: bad argument #4 to 'Create' (function expected, got no value)
1. Create - [C]:-1
2. unknown - gamemodes/garry's_mode_battlegrounds/gamemode/cl_init.lua:35
Yeah sorry I didn't test the code out before giving it to you, try this:
--You can put it in a timer or a hook if you want to.
timer.Create("SpawnLotsOfClouds", 0.1, 50, function()
--Let's now spawn the particle 100 units above the position you're aiming at
local startPos = LocalPlayer():GetEyeTrace().HitPos + Vector(0,0,100)
if(fxEmitter) then --We check if fxEmitter exists, who knows
local fxParticle = fxEmitter:Add("particle/smokesprites_0004", startPos) --Smokesprite_0004 is one that I use the most
if(fxParticle) then --We check if the particle was spawned succesfully, some clients do stop generating them
fxParticle:SetVelocity(VectorRand()*10) --This will make it travel in a random direction
fxParticle:SetDieTime(1) --After 1 second it will disappear
fxParticle:SetStartAlpha(150) --When it gets spawned its alpha is 150, about 2/3 visible
fxParticle:SetEndAlpha(0) --It will gradually get more invisible and at the 1 second mark it will be 0 alpha
fxParticle:SetStartSize(5) --At the beginning it's this big
fxParticle:SetEndSize(60) --And at the end it's 12 times bigger, this makes it look like it's expanding
fxParticle:SetAngleVelocity(Angle(math.Rand(-5,5),0,0)) --Just to add randomness I make it rotate a bit
fxParticle:SetColor(120,20,70,255) --This will set its color, it's a dark pink
fxParticle:SetCollide(true) --This will make it collide with the world (AND ONLY WORLD)
fxParticle:SetGravity(Vector(0,0,-30)) --This will make it gradually go UP in the air, even if it spawns in being launched below it will slow down and start going up
end
end
end)
I just made the function inside of the timer.
how can i run this function?
Ok, I actually tested it in game this time, here's a simple code that you can just copy and paste it inside somewhere:
--Put this at the beginning of the code (CLIENT) or any initialization hook
local fxEmitter = ParticleEmitter(vector_origin)
--You can put it in a timer or a hook if you want to.
timer.Create("SpawnLotsOfClouds", 0.01, 5000, function()
--Let's now spawn the particle 100 units above the position you're aiming at
local startPos = LocalPlayer():GetEyeTrace().HitPos + Vector(0,0,10)
if(fxEmitter) then --We check if fxEmitter exists, who knows
local fxParticle = fxEmitter:Add("particle/smokesprites_0004", startPos) --Smokesprite_0004 is one that I use the most
if(fxParticle) then --We check if the particle was spawned succesfully, some clients do stop generating them
fxParticle:SetVelocity(VectorRand()*100) --This will make it travel in a random direction
fxParticle:SetDieTime(4) --After 1 second it will disappear
fxParticle:SetStartAlpha(70) --When it gets spawned its alpha is 150, about 2/3 visible
fxParticle:SetEndAlpha(0) --It will gradually get more invisible and at the 1 second mark it will be 0 alpha
fxParticle:SetStartSize(15) --At the beginning it's this big
fxParticle:SetEndSize(300) --And at the end it's 12 times bigger, this makes it look like it's expanding
fxParticle:SetAngleVelocity(Angle(math.Rand(-5,5),0,0)) --Just to add randomness I make it rotate a bit
fxParticle:SetColor(120,20,70,255) --This will set its color, it's a dark pink
fxParticle:SetCollide(true) --This will make it collide with the world (AND ONLY WORLD)
fxParticle:SetGravity(Vector(0,0,30)) --This will make it gradually go UP in the air, even if it spawns in being launched below it will slow down and start going up
end
end
end)
This will make some sort of gas grenade thing, it will last for 50 seconds, here's an example:
https://streamable.com/bdsae
Note that the code I gave you isn't everything you need... It's just an example of CLuaParticles
Okay, i understood, thank you)
Well, i added 4 emitters at the corners of map, now, i want they to gradually move to the center of map.
--Put this at the beginning of the code (CLIENT) or any initialization hook
local fxEmitter = ParticleEmitter(vector_origin)
--You can put it in a timer or a hook if you want to.
timer.Create("SpawnLotsOfClouds", 0.1, 5000, function()
--Let's now spawn the particle 100 units above the position you're aiming at
local startPos = ( {
Vector(13167.110,13167.110,-11135.969),
Vector(-13237.239,13185.424,-11135.969),
Vector(-13235.135,-12026.704,-11135.969),
Vector(13238.087,-13238.044,-11135.969)
})
if(fxEmitter) then --We check if fxEmitter exists, who knows
local fxParticle = fxEmitter:Add("particle/smokesprites_0004", table.Random(startPos)) --Smokesprite_0004 is one that I use the most
if(fxParticle) then --We check if the particle was spawned succesfully, some clients do stop generating them
fxParticle:SetVelocity(VectorRand()*100) --This will make it travel in a random direction
fxParticle:SetDieTime(4) --After 1 second it will disappear
fxParticle:SetStartAlpha(70) --When it gets spawned its alpha is 150, about 2/3 visible
fxParticle:SetEndAlpha(0) --It will gradually get more invisible and at the 1 second mark it will be 0 alpha
fxParticle:SetStartSize(1000) --At the beginning it's this big
fxParticle:SetEndSize(2000) --And at the end it's 12 times bigger, this makes it look like it's expanding
fxParticle:SetAngleVelocity(Angle(math.Rand(-5,5),0,0)) --Just to add randomness I make it rotate a bit
fxParticle:SetColor(50,205,50) --This will set its color, it's a dark pink
fxParticle:SetCollide(true) --This will make it collide with the world (AND ONLY WORLD)
fxParticle:SetGravity(Vector(0,0,30)) --This will make it gradually go UP in the air, even if it spawns in being launched below it will slow down and start going up
end
end
end)
Nevermind I decided to create another gamemode, cuz it's too hard for me. All scripts that i have, it's not written by myself. Thanks everyone who helped me.
Have fun with that!
Thank you, bro)
Sorry, you need to Log In to post a reply to this thread.