mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 13:53:45 +03:00
Upload
This commit is contained in:
95
lua/entities/stormfox_oil_lamp/cl_init.lua
Normal file
95
lua/entities/stormfox_oil_lamp/cl_init.lua
Normal file
@@ -0,0 +1,95 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
include("shared.lua")
|
||||
|
||||
function ENT:Initialize()
|
||||
self.PixVis = util.GetPixelVisibleHandle()
|
||||
end
|
||||
|
||||
local ran,rand,max = math.random,math.Rand,math.max
|
||||
local function createFlame(self)
|
||||
if not self.Emitter or not IsValid(self.Emitter) then -- Recreate missing emitter
|
||||
self.Emitter = ParticleEmitter(self:GetPos(),false)
|
||||
end
|
||||
local t = table.Random({"sprites/flamelet1","sprites/flamelet2","sprites/flamelet3"})
|
||||
local p = self.Emitter:Add(t,self:LocalToWorld(Vector(0,0, 7)))
|
||||
p:SetDieTime(rand(0.5,0.9))
|
||||
p:SetStartSize(ran(1,2) / 2)
|
||||
p:SetGravity(Vector(0,0,10))
|
||||
p:SetEndAlpha(0)
|
||||
p:SetStartAlpha(200)
|
||||
p:SetVelocity(Vector(0,0,1) + self:GetVelocity() / 3 )
|
||||
p:SetRoll(ran(360))
|
||||
end
|
||||
|
||||
local broken_glass = Material("models/effects/vol_light001")
|
||||
local on_mat = Material("stormfox2/models/oillamp_on")
|
||||
function ENT:Draw()
|
||||
render.SetColorModulation(1,1,1) -- Override entity color.
|
||||
if not self:GetNWBool("broken",false) then
|
||||
if self:IsOn() then
|
||||
render.MaterialOverrideByIndex(1,on_mat)
|
||||
end
|
||||
self:DrawModel()
|
||||
else
|
||||
render.MaterialOverrideByIndex(0,broken_glass)
|
||||
self:DrawModel()
|
||||
render.MaterialOverrideByIndex()
|
||||
end
|
||||
render.MaterialOverrideByIndex()
|
||||
end
|
||||
|
||||
local function GetDis(ent)
|
||||
if (ent.time_dis or 0) > CurTime() then return ent.time_dis_v or 0 end
|
||||
ent.time_dis = CurTime() + 1
|
||||
if not LocalPlayer() then return 0 end
|
||||
ent.time_dis_v = LocalPlayer():GetShootPos():DistToSqr(ent:GetPos())
|
||||
return ent.time_dis_v
|
||||
end
|
||||
function ENT:Think()
|
||||
if GetDis(self) > 4500000 then return end
|
||||
|
||||
if (self.nextFlame or 0) > CurTime() then return end
|
||||
local ml = StormFox2.Map.GetLightRaw()
|
||||
--if ml > 18 then return end
|
||||
if self:WaterLevel() > 0 then return end
|
||||
if self:GetNWBool("broken",false) then return end
|
||||
if not self:IsOn() then return end
|
||||
-- Wind
|
||||
self.nextFlame = CurTime() + (ran(5,10) / 200)
|
||||
createFlame(self)
|
||||
if (self.t2 or 0) <= CurTime() then
|
||||
self.t2 = CurTime() + rand(0.2,0.5)
|
||||
local dlight = DynamicLight( self:EntIndex() )
|
||||
if ( dlight ) then
|
||||
local h,s,l = ColorToHSL( self:GetColor() )
|
||||
l = math.Clamp(rand(l - 0.2, l + 0.2), 0, 1)
|
||||
local c = HSVToColor(h,s,l)
|
||||
dlight.pos = self:LocalToWorld(Vector(rand(-0.6,0.6), rand(-0.6,0.6), 10))
|
||||
dlight.r = c.r
|
||||
dlight.g = c.g
|
||||
dlight.b = c.b
|
||||
dlight.brightness = 1 - ml / 200
|
||||
dlight.Decay = 0
|
||||
dlight.Size = 256 * 1.5
|
||||
dlight.DieTime = self.t2 + 0.5
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:OnRemove( )
|
||||
if not IsValid(self.Emitter) then return end
|
||||
self.Emitter:Finish()
|
||||
end
|
||||
|
||||
function ENT:DrawTranslucent()
|
||||
|
||||
end
|
||||
119
lua/entities/stormfox_oil_lamp/init.lua
Normal file
119
lua/entities/stormfox_oil_lamp/init.lua
Normal file
@@ -0,0 +1,119 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
AddCSLuaFile("cl_init.lua")
|
||||
AddCSLuaFile("shared.lua")
|
||||
|
||||
include("shared.lua")
|
||||
|
||||
function ENT:Initialize()
|
||||
self:SetModel( "models/stormfox2/oillamp.mdl" )
|
||||
self:PhysicsInit( SOLID_VPHYSICS )
|
||||
--self:SetMoveType( MOVETYPE_NONE )
|
||||
|
||||
self.RenderMode = 1
|
||||
|
||||
self:SetRenderMode(RENDERMODE_TRANSALPHA)
|
||||
self:SetColor(Color(255,185,0))
|
||||
self.on = false
|
||||
self.lastT = SysTime() + 7
|
||||
self.hp = 10
|
||||
self.respawn = -1
|
||||
self:SetKeyValue("fademindist", 2000)
|
||||
self:SetKeyValue("fademaxdist", 2000)
|
||||
self:SetNWInt("on",1)
|
||||
self:SetUseType( SIMPLE_USE )
|
||||
self.on = 1
|
||||
end
|
||||
|
||||
function ENT:OnTakeDamage(cmd)
|
||||
if self.hp <= 0 then return end
|
||||
self.hp = (self.hp or 0) - cmd:GetDamage()
|
||||
if self.hp > 0 then return end
|
||||
if WireAddon then
|
||||
Wire_TriggerOutput(self, "IsBroken", 1)
|
||||
end
|
||||
self:EmitSound("physics/glass/glass_largesheet_break1.wav")
|
||||
self:SetNWBool("broken",true)
|
||||
self.respawn = CurTime() + 30
|
||||
for i = 1,5 do
|
||||
local effectdata = EffectData()
|
||||
effectdata:SetOrigin( self:LocalToWorld(Vector(0,0,7)) )
|
||||
effectdata:SetNormal(self:GetAngles():Up())
|
||||
util.Effect("GlassImpact",effectdata)
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:SpawnFunction( ply, tr, ClassName )
|
||||
|
||||
if ( not tr.Hit ) then return end
|
||||
|
||||
local SpawnPos = tr.HitPos + tr.HitNormal * 0.1
|
||||
|
||||
local ent = ents.Create( ClassName )
|
||||
local ang = (ply:GetPos() - SpawnPos):Angle().y
|
||||
ent:SetPos( SpawnPos )
|
||||
ent:SetAngles(Angle(0,ang,0))
|
||||
ent:Spawn()
|
||||
ent:Activate()
|
||||
return ent
|
||||
|
||||
end
|
||||
|
||||
-- Tells clients to render flame or not
|
||||
function ENT:SetOn(boolean)
|
||||
if self.on == boolean then return end
|
||||
self:SetNWInt("on",boolean and 1 or 0)
|
||||
self.on = boolean
|
||||
if boolean then
|
||||
self:EmitSound("ambient/fire/mtov_flame2.wav", 50, 110, 0.2)
|
||||
else
|
||||
self:EmitSound("ambient/atmosphere/hole_hit4.wav", 50, 50,0.4)
|
||||
end
|
||||
end
|
||||
|
||||
local function sendMsg( act, msg )
|
||||
if type(act) ~= "Player" then return end
|
||||
act:PrintMessage( HUD_PRINTTALK, "Lamp: " .. msg )
|
||||
end
|
||||
|
||||
function ENT:Use( act )
|
||||
if self:WaterLevel() < 1 and not self:IsOn() then
|
||||
self:SetOn(true)
|
||||
sendMsg( act, "Always on" )
|
||||
elseif self:IsOn() then
|
||||
self:SetOn(false)
|
||||
sendMsg( act, "On at night" )
|
||||
end
|
||||
end
|
||||
|
||||
local function respawnThink( self )
|
||||
if self.respawn < 0 then return end
|
||||
if self.respawn > CurTime() then return end
|
||||
self.respawn = -1
|
||||
self.hp = 10
|
||||
self:SetNWBool("broken",false)
|
||||
end
|
||||
|
||||
function ENT:Think()
|
||||
self:NextThink( CurTime() + 7 )
|
||||
-- Respawn
|
||||
respawnThink(self)
|
||||
if self:IsOn() then return end -- On 24h
|
||||
local on = (StormFox2.Time.IsNight() and self:WaterLevel() < 1) and 1 or 0
|
||||
if self:GetNWInt("on") == on then return end
|
||||
self:SetNWInt("on",on )
|
||||
if on == 1 then
|
||||
self:EmitSound("ambient/fire/mtov_flame2.wav", 50, 110, 0.2)
|
||||
else
|
||||
self:EmitSound("ambient/atmosphere/hole_hit4.wav", 50, 50,0.4)
|
||||
end
|
||||
return true
|
||||
end
|
||||
34
lua/entities/stormfox_oil_lamp/shared.lua
Normal file
34
lua/entities/stormfox_oil_lamp/shared.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
ENT.Type = "anim"
|
||||
ENT.Base = "base_anim"
|
||||
|
||||
ENT.PrintName = "Oil Lamp"
|
||||
ENT.Author = "Nak"
|
||||
ENT.Purpose = "An old lamp with a moden sun-sensor."
|
||||
ENT.Instructions = "Place it somewhere"
|
||||
ENT.Category = "StormFox2"
|
||||
|
||||
ENT.WireDebugName = "Oil Lamp"
|
||||
|
||||
ENT.Editable = true
|
||||
ENT.Spawnable = true
|
||||
ENT.AdminOnly = false --true
|
||||
|
||||
ENT.RenderGroup = RENDERGROUP_BOTH
|
||||
|
||||
function ENT:IsOn()
|
||||
if SERVER then
|
||||
return self.on
|
||||
else
|
||||
return self:GetNWInt("on",0) > 0
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user