• Weather
    20 replies, posted
I have a weather mod: [url]http://www.garrysmod.org/downloads/?a=view&id=76878[/url] And i have found 2 snipits of code in it: "lua/effects/rain/init/lua" The code: [lua] local density=CreateClientConVar("cs_raindensity","1",false,false) function EFFECT:Init(data) self.Particles=data:GetMagnitude()*density:GetInt() self.DieTime=CurTime()+1 self.Emitter=ParticleEmitter(LocalPlayer():GetPos()) end local function ParticleCollides(particle, pos, norm) particle:SetDieTime(0) local effectdata = EffectData() effectdata:SetStart(pos) effectdata:SetOrigin(pos) --effectdata:SetScale(2) effectdata:SetScale( math.random( 1,3 ) ) util.Effect( "watersplash", effectdata ) end function EFFECT:Think() if CurTime()>self.DieTime then return false end local emitter = self.Emitter for i=1, self.Particles do local spawnpos = LocalPlayer():GetPos()+Vector(math.random(-700,700)+LocalPlayer():GetVelocity().x*1,math.random(-700,700)+LocalPlayer():GetVelocity().y*1,900) local particle = emitter:Add("particle/Water/WaterDrop_001a", spawnpos) --local particle = emitter:Add("effects/rain", spawnpos) --local particle = emitter:Add("particle/rprain", spawnpos) if (particle) then particle:SetVelocity(Vector(math.sin(CurTime()/4)*20,30,-100)) particle:SetLifeTime(0) particle:SetDieTime(4) particle:SetEndAlpha(255) particle:SetStartSize(0) --particle:SetEndSize(10) particle:SetEndSize(math.random( 10,20 )) particle:SetAirResistance(0) particle:SetStartAlpha(128) particle:SetCollide(true) particle:SetBounce(0) particle:SetCollideCallback(ParticleCollides) end end return true end function EFFECT:Render() end [/lua] and i want to change the hight of the rain to fit rp_downtown's skybox. How? This is the other bit of code: "lua/autorun/client/cl_weather" THe code: [lua] WEATHER={ ["sunny"]={ Brightness=0, Contrast=1, Colour=1, Precipitation=0, SoundLevel=3.9, Pitch=100, }, ["cloudy"]={ Brightness=0, Contrast=1, Colour=0.6, Precipitation=0, SoundLevel=3.9, Pitch=100, }, ["rain"]={ Brightness=-0.07, Contrast=0.9, Colour=0.4, Precipitation=10, SoundLevel=3.9, Pitch=100, Sound="ambient/weather/rumble_rain_nowind.wav", }, ["heavyrain"]={ Brightness=-0.07, Contrast=0.9, Colour=0.4, Precipitation=15, SoundLevel=3.9, Pitch=100, Sound="ambient/weather/rumble_rain_nowind.wav", }, ["sunnyrain"]={ Brightness=0, Contrast=0.7, Colour=1.2, Precipitation=10, SoundLevel=3.9, Pitch=100, Sound="ambient/weather/rumble_rain_nowind.wav", }, ["storm"]={ --Brightness=-0.15, --Contrast=0.7, --Colour=0.1, Brightness=0, Contrast=0.3, Colour=1, Precipitation=30, SoundLevel=2.9, Pitch=100, Sound="ambient/weather/rumble_rain.wav", }, ["dark"]={ Brightness=0, Contrast=0.3, Colour=1, Precipitation=0, SoundLevel=2.9, Pitch=100, }, ["darkrain"]={ Brightness=0, Contrast=0.3, Colour=1, Precipitation=5, SoundLevel=3.9, Pitch=100, Sound="ambient/weather/rumble_rain_nowind.wav", }, } local CurWeather={ Brightness=0, Contrast=1, Colour=1, Precipitation=0, Pitch=100, SoundLevel=3.9, Pitch=100, } SetGlobalString("weather","sunny") local WeatherSound=nil local PrevWeather="sunny" local LastLightning=0 function WeatherOverlay() if render.GetDXLevel() < 80 then return end local WeatherName=GetGlobalString("weather") if not WeatherName or not WEATHER[WeatherName] then WeatherName="sunny" end local traced = {} traced.start = LocalPlayer():GetPos() traced.endpos = LocalPlayer():GetPos()+Vector(0,0,700) traced.mask = MASK_NPCWORLDSTATIC local tr=util.TraceLine(traced) if tr.HitWorld then CurWeather.Brightness=math.Approach( CurWeather.Brightness, math.Clamp(WEATHER[WeatherName].Brightness,0,5), 0.01 ) CurWeather.Contrast=math.Approach( CurWeather.Contrast, math.Clamp(WEATHER[WeatherName].Contrast,1,5), 0.01 ) CurWeather.Colour=math.Approach( CurWeather.Colour, math.Clamp(WEATHER[WeatherName].Colour,1,5), 0.01 ) else CurWeather.Brightness=math.Approach( CurWeather.Brightness, WEATHER[WeatherName].Brightness, 0.01 ) CurWeather.Contrast=math.Approach( CurWeather.Contrast, WEATHER[WeatherName].Contrast, 0.01 ) CurWeather.Colour=math.Approach( CurWeather.Colour, WEATHER[WeatherName].Colour, 0.01 ) end CurWeather.Precipitation=math.Approach( CurWeather.Precipitation, math.Clamp(WEATHER[WeatherName].Precipitation,0,25), 0.01 ) local ScrColTab = {} ScrColTab[ "$pp_colour_addr" ] = 0 ScrColTab[ "$pp_colour_addg" ] = 0 ScrColTab[ "$pp_colour_addb" ] = 0 ScrColTab[ "$pp_colour_brightness" ]= CurWeather.Brightness ScrColTab[ "$pp_colour_contrast" ] = CurWeather.Contrast ScrColTab[ "$pp_colour_colour" ] = CurWeather.Colour ScrColTab[ "$pp_colour_mulr" ] = 0 ScrColTab[ "$pp_colour_mulg" ] = 0 ScrColTab[ "$pp_colour_mulb" ] = 0 DrawColorModify(ScrColTab) if not PrevWeather or PrevWeather~=WeatherName then if WeatherSound then WeatherSound:Stop() end if WEATHER[WeatherName].Sound then WeatherSound=CreateSound(LocalPlayer(),WEATHER[WeatherName].Sound) WeatherSound:Play() PrevWeather=WeatherName else WeatherSound=nil end end if CurTime()>LastLightning and CurWeather.Precipitation>10 then if math.random(1,20)==10 then LastLightning=CurTime()+30 CurWeather.Contrast=5 timer.Simple(0.2,function() CurWeather.Contrast=WEATHER[WeatherName].Contrast end) timer.Simple(3,function() surface.PlaySound(Format("ambient/atmosphere/thunder%i.wav",math.random(1,4))) end) end end if WeatherSound and tr.HitWorld or (WeatherSound and LocalPlayer():InVehicle()) then CurWeather.SoundLevel=math.Approach( CurWeather.SoundLevel, 2, 0.195 ) CurWeather.Pitch=math.Approach( CurWeather.Pitch, 50, 2 ) WeatherSound:SetSoundLevel(CurWeather.SoundLevel) WeatherSound:ChangePitch(CurWeather.Pitch) elseif WeatherSound then CurWeather.SoundLevel=math.Approach( CurWeather.SoundLevel, 3.9, 0.195 ) CurWeather.Pitch=math.Approach( CurWeather.Pitch, 100, 2 ) WeatherSound:SetSoundLevel(CurWeather.SoundLevel) WeatherSound:ChangePitch(CurWeather.Pitch) end end hook.Add("RenderScreenspaceEffects", "WeatherOverlay", WeatherOverlay) local LastEffect=0 function WeatherThink() local WeatherName=GetGlobalString("weather") if not WeatherName or not WEATHER[WeatherName] then WeatherName="sunny" end if CurWeather.Precipitation>0 then if CurTime()>LastEffect then LastEffect=CurTime()+1 local eff=EffectData() eff:SetMagnitude(CurWeather.Precipitation) util.Effect("rain",eff) end end end hook.Add("Think","",WeatherThink) [/lua] Thanks guys!
And... what do you want us to do?
[QUOTE=The Spie;25028299]And... what do you want us to do?[/QUOTE] [QUOTE=OP]and i want to change the hight of the rain to fit rp_downtown's skybox. How?[/QUOTE] It was hidden in there between all that code.
the funny part about this is... the skybox isnt made by the LUA. Skyboxs are from the .bsp file.
[code] tags are your [I]friend[/I]
Use [code] and [/code ] (Without the space) or [lua] and [/lua ] Also, what do you want us to do, exactly?
The rain is spawned around the local player. It's not supposed to spawn in the skybox or anything. It's done this way because it's the most efficent way. Spawning rain all over the map is going to make the game reach the particle limit in no time and it's going to drop your fps.
Speaking of weather mods, I can't seem to find one that works serverside.
Someone needs to make a weathermod that both detects the skybox above the player [b]AND[/b] actually works when in practice. As I recall, the current rain mod sometimes has the rain pass through rooftops and it's very annoying. And support for angled rain, definitely.
[QUOTE=Wombo194;25029468]Use [code] and [/code ] (Without the space) or [lua] and [/lua ] Also, what do you want us to do, exactly?[/QUOTE] I want the altitude lowered on the rain because it rAINS out side the skybox D;
Find this line: local spawnpos = LocalPlayer():GetPos()+Vector(math.random(-700,700)+LocalPlayer():GetVelocity().x*1,math.random(-700,700)+LocalPlayer():GetVelocity().y*1,900) Probably adjust 1,900 at the end to match the skybox. Rp_downtown probably uses something similar to 1,400. Remember to not modify the math.random bits, they just spawn the rain particles randomly on the x and y plane it appears. Either that or THIS: local traced = {} traced.start = LocalPlayer():GetPos() traced.endpos = LocalPlayer():GetPos()+Vector(0,0,[b]700[/b]) traced.mask = MASK_NPCWORLDSTATIC local tr=util.TraceLine(traced) In the second file, try modifying that 700.
[QUOTE=DireAvenger;25036931]Find this line: local spawnpos = LocalPlayer():GetPos()+Vector(math.random(-700,700)+LocalPlayer():GetVelocity().x*1,math.random(-700,700)+LocalPlayer():GetVelocity().y*1,900) Probably adjust 1,900 at the end to match the skybox. Rp_downtown probably uses something similar to 1,400. Remember to not modify the math.random bits, they just spawn the rain particles randomly on the x and y plane it appears. Either that or THIS: local traced = {} traced.start = LocalPlayer():GetPos() traced.endpos = LocalPlayer():GetPos()+Vector(0,0,[b]700[/b]) traced.mask = MASK_NPCWORLDSTATIC local tr=util.TraceLine(traced) In the second file, try modifying that 700.[/QUOTE] Ah thanks im pretty sure that would work. I just couldnt find the Z axis. After all i am a noob to lua....
[QUOTE=DireAvenger;25035827]Someone needs to make a weathermod that both detects the skybox above the player [b]AND[/b] actually works when in practice. As I recall, the current rain mod sometimes has the rain pass through rooftops and it's very annoying. And support for angled rain, definitely.[/QUOTE] Yeah I already did this, but you first had to precalculate a point cloud of the outside geometry, and also needed a dll to search through the points about 5 times a second. But I ended up with perfect rain on all maps(no lag as well). You can even see it raining outside when your inside.
[QUOTE=haza55;25039053]Yeah I already did this, but you first had to precalculate a point cloud of the outside geometry, and also needed a dll to search through the points about 5 times a second. But I ended up with perfect rain on all maps(no lag as well). You can even see it raining outside when your inside.[/QUOTE] That would be nice to get hold of.
[QUOTE=Jamie932;25039163]That would be nice to get hold of.[/QUOTE] Clientside module I'm guessing.
The code tags are still broke. You put a space after the [/lua
[QUOTE=CapsAdmin;25029524]The rain is spawned around the local player. It's not supposed to spawn in the skybox or anything[/QUOTE] ^ This
Weird
[QUOTE=SGTNAPALM;25032202]Speaking of weather mods, I can't seem to find one that works serverside.[/QUOTE] A weather mod is just effect rendering, and rendering is always done on the client. Why would you want it to be serverside?
He means that the weather is triggered serverside so the clients can see it. Unless he has crazy ideas of physical weather particles that bounce off things and make puddles, which would be insane, both in fun and possibility to code without intense framerate rape.
[QUOTE=DireAvenger;25075414]He means that the weather is triggered serverside so the clients can see it. Unless he has crazy ideas of physical weather particles that bounce off things and make puddles, which would be insane, both in fun and possibility to code without intense framerate rape.[/QUOTE] Then that's as simple as sending a usermessage. :xd:
Sorry, you need to Log In to post a reply to this thread.