Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoke changes #100

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lua/acf/shared/sv_ace_networking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ util.AddNetworkString( "acf_smokewind" )
util.AddNetworkString( "ACE_CamOverride" )
util.AddNetworkString( "ACE_DPStatus" )
util.AddNetworkString( "ACE_Scalable_Network" )
util.AddNetworkString( "ACE_SendMessage" )
util.AddNetworkString( "ACE_SendMessage" )
util.AddNetworkString( "ACE_Wind" )
25 changes: 24 additions & 1 deletion lua/autorun/acf_globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CreateConVar("acf_explosions_scaled_he_max", 100, FCVAR_ARCHIVE)
CreateConVar("acf_explosions_scaled_ents_max", 5, FCVAR_ARCHIVE)

--Smoke
CreateConVar("acf_wind", 300, FCVAR_ARCHIVE)
CreateConVar("acf_wind", 300, FCVAR_ARCHIVE + FCVAR_REPLICATED)


if CLIENT then
Expand Down Expand Up @@ -474,6 +474,29 @@ do

end


if CLIENT then
ACF.Wind = Vector(math.Rand(-1, 1), math.Rand(-1, 1), 0):GetNormalized()

net.Receive("ACE_Wind", function()
ACF.Wind = Vector(net.ReadFloat(), net.ReadFloat(), 0)
end)
else
local curveFactor = 2.5
local reset_timer = 60

timer.Create("ACE_Wind", reset_timer, 0, function()
local smokeDir = Vector(math.Rand(-1, 1), math.Rand(-1, 1), 0):GetNormalized()
local wind = (math.random() ^ curveFactor) * smokeDir * GetConVar("acf_wind"):GetFloat()
net.Start("ACE_Wind")
net.WriteFloat(wind.x)
net.WriteFloat(wind.y)
net.Broadcast()
end)
end



cleanup.Register( "aceexplosives" )

AddCSLuaFile("autorun/acf_missile/folder.lua")
Expand Down
44 changes: 8 additions & 36 deletions lua/effects/acf_smoke/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,15 @@ local smokes = {
"particle/smokesprites_0008"
}

local lastWindUpdateTime = 0
local windDirection = Vector(0, 0, 0) -- Initialize with a default wind direction

local lastWindUpdateTime = 0
local windStrength = 0 -- Initialize windStrength to 0
local curveFactor = 2.5 -- How biased the wind strength to 0 is (curvature!!)

local function smokePuff(self, Ground, ShootVector, Radius, RadiusMod, Density, i, SmokeColor, DeploySpeed, Lifetime)
local currentTime = CurTime()
local wind = GetConVar("acf_wind"):GetFloat()
-- Check if it's time to update the wind direction and windStrength
local reset_timer = 60 -- Update wind direction every n seconds (adjust the time interval as needed)
if currentTime - lastWindUpdateTime > reset_timer then
lastWindUpdateTime = currentTime

-- Generate a new random wind direction
windDirection = Vector(math.Rand(-1, 1), math.Rand(-1, 1), 0):GetNormalized()

local randValue = math.Rand(0, 1)
windStrength = (randValue ^ curveFactor) * wind
end
local function smokePuff(self, Ground, ShootVector, Radius, RadiusMod, SmokeColor, DeploySpeed, Lifetime)

local Smoke = self.Emitter:Add(smokes[math.random(1, #smokes)], Ground.HitPos)
if Smoke then
-- Calculate the wind effect on velocity and gravity
local velocity = (ShootVector + Vector(0, 0, 0.2)) * (Radius * RadiusMod) * DeploySpeed
local gravity = Vector(0, 0, math.Rand(5, 15))

-- Apply wind effect based on wind direction and windStrength
local windEffect = windDirection * (windStrength * math.Rand(0.5, 1.5))
velocity = velocity + windEffect * (i / Density)
gravity = gravity + windEffect * 0.2
local velocity = (ShootVector + Vector(0, 0, 0.2)) * DeploySpeed
local gravity = Vector(0, 0, 0) + ACF.Wind * 0.2


Smoke:SetVelocity(velocity)
Smoke:SetLifeTime(0)
Expand All @@ -95,7 +72,7 @@ local function smokePuff(self, Ground, ShootVector, Radius, RadiusMod, Density,
Smoke:SetEndSize(math.Clamp(Radius * RadiusMod * 4, 150, 4000))
Smoke:SetRoll(math.Rand(0, 360))
Smoke:SetRollDelta(math.Rand(-0.2, 0.2))
Smoke:SetAirResistance(100 * DeploySpeed)
Smoke:SetAirResistance(100)
Smoke:SetGravity(gravity)
Smoke:SetColor(SmokeColor.x, SmokeColor.y, SmokeColor.z)
end
Expand All @@ -104,21 +81,16 @@ end








function EFFECT:SmokeFiller( Ground, SmokeColor, Radius, DeploySpeed, Lifetime )

local Density = Radius / 18
local Angle = Ground.HitNormal:Angle()
local ShootVector = Ground.HitNormal * 0.5
--print(Radius .. ", " .. Density)

smokePuff(self, Ground, Vector(0, 0, 0.3), Radius, 1.5, Density, 0, SmokeColor, DeploySpeed, Lifetime) --smoke filler initial upward puff
for i = 0, math.floor(Density) do
smokePuff(self, Ground, ShootVector, Radius, 1, Density, i, SmokeColor, DeploySpeed, Lifetime)
smokePuff(self, Ground, Vector(0, 0, 0.3), Radius, 1.5, SmokeColor, DeploySpeed, Lifetime) --smoke filler initial upward puff
for _ = 0, math.floor(Density) do
smokePuff(self, Ground, ShootVector, Radius, 1, SmokeColor, DeploySpeed, Lifetime)

ShootVector = Angle and Angle:Up()
Angle:RotateAroundAxis(Angle:Forward(), 360 / Density)
Expand Down
Loading