o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
Сделай рефакторинг, улучши код, улучши алгоритм и работу, оптимизируй код, структурируй,…
- User
Сделай рефакторинг, улучши код, улучши алгоритм и работу, оптимизируй код, структурируй, сделай единый стиль, исправь нерабочий сплэш воды когда туда падает рэгдолл, исправь баги:
-- server side if SERVER then util.AddNetworkString("SmashRagdollBloodEffects") util.AddNetworkString("HeadHitGlassShardEffect") util.AddNetworkString("WaterSplashEffect") local function IsHeadCollision(target, hitPos) local headBone = target:LookupBone("ValveBiped.Bip01_Head1") if not headBone then return false end local headPos = target:GetBonePosition(headBone) return hitPos:Distance(headPos) < 20 end local function HandleRagdollHit(target, dmginfo) if not target:IsRagdoll() then return end local force = dmginfo:GetDamageForce():Length() local forceDirection = dmginfo:GetDamageForce():GetNormalized() local hitPos = dmginfo:GetDamagePosition() if force > 500 then net.Start("SmashRagdollBloodEffects") net.WriteEntity(target) net.WriteVector(target:GetPos()) net.WriteVector(forceDirection) net.Broadcast() end if IsHeadCollision(target, hitPos) then net.Start("HeadHitGlassShardEffect") net.WriteVector(hitPos) net.Broadcast() end local tr = util.TraceHull({ start = target:GetPos(), endpos = target:GetPos() - Vector(0, 0, 10), mins = Vector(-10, -10, -10), maxs = Vector(10, 10, 10), filter = target }) if tr.Hit and tr.MatType == MAT_SLOSH then print("Ragdoll hit water") -- Debug line net.Start("WaterSplashEffect") net.WriteVector(target:GetPos()) net.Broadcast() end end hook.Add("EntityTakeDamage", "SmashRagdollEffects", HandleRagdollHit) end-- client side if CLIENT then local breakSounds = { "physics/body/body_medium_break1.wav", "physics/body/body_medium_break2.wav", "physics/body/body_medium_break3.wav", "physics/body/body_medium_break4.wav", "physics/body/body_medium_break5.wav", "physics/body/body_medium_break6.wav", "physics/body/body_medium_break_hard1.wav", "physics/body/body_medium_break_hard2.wav" } local function HandleBloodEffects() local target = net.ReadEntity() local position = net.ReadVector() local forceDirection = net.ReadVector() local selectedSound = breakSounds[math.random(#breakSounds)] target:EmitSound(selectedSound, 75, 100) local emitter = ParticleEmitter(position) if not emitter then return end for i = 1, 20 do local particle = emitter:Add("effects/blood", position) if particle then particle:SetVelocity(VectorRand() * math.random(10, 150) + forceDirection * math.random(10, 30)) particle:SetDieTime(0.5 + math.Rand(0, 0.5)) particle:SetStartAlpha(255) particle:SetEndAlpha(0) particle:SetStartSize(5) particle:SetEndSize(15) particle:SetRoll(math.Rand(0, 360)) particle:SetRollDelta(math.Rand(-2, 2)) particle:SetColor(255, 0, 0) particle:SetGravity(Vector(0, 0, -600)) particle:SetAirResistance(50) end end emitter:Finish() local trace = util.TraceLine({ start = position, endpos = position - Vector(0, 0, 100), filter = target }) if trace.Hit then util.Decal("Blood", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal) local wallTrace = util.TraceLine({ start = position, endpos = position + forceDirection * 100, filter = target }) if wallTrace.Hit then util.Decal("Blood", wallTrace.HitPos + wallTrace.HitNormal, wallTrace.HitPos - wallTrace.HitNormal) end end end local function HandleGlassShardEffect() local hitPos = net.ReadVector() local emitter = ParticleEmitter(hitPos) if not emitter then return end for i = 1, 20 do local particle = emitter:Add("effects/fleck_glass1", hitPos) if particle then particle:SetVelocity(VectorRand() * math.random(100, 300)) particle:SetDieTime(1) particle:SetStartAlpha(255) particle:SetEndAlpha(0) particle:SetStartSize(1) particle:SetEndSize(0) particle:SetRoll(math.Rand(0, 360)) particle:SetRollDelta(math.Rand(-2, 2)) particle:SetColor(255, 255, 255) particle:SetGravity(Vector(0, 0, -600)) particle:SetAirResistance(20) end end emitter:Finish() end local function CreateWaterSplashEffect() local pos = net.ReadVector() local splashParticle = ParticleEmitter(pos) if not splashParticle then return end for i = 1, 30 do local particle = splashParticle:Add("effects/splash1", pos + VectorRand() * 5) if particle then particle:SetVelocity(VectorRand() * math.random(20, 50) + Vector(0, 0, math.random(10, 20))) particle:SetDieTime(0.5 + math.Rand(0, 0.3)) particle:SetStartAlpha(255) particle:SetEndAlpha(0) particle:SetStartSize(math.random(5, 7)) particle:SetEndSize(math.random(10, 15)) particle:SetRoll(math.Rand(0, 360)) particle:SetRollDelta(math.Rand(-2, 2)) particle:SetColor(255, 255, 255) particle:SetGravity(Vector(0, 0, -300)) particle:SetAirResistance(15) end end splashParticle:Finish() sound.Play("ambient/water/water_splash1.wav", pos, 75, 100) end -- Регистрация получения сетевых сообщений net.Receive("SmashRagdollBloodEffects", HandleBloodEffects) net.Receive("HeadHitGlassShardEffect", HandleGlassShardEffect) net.Receive("WaterSplashEffect", CreateWaterSplashEffect) end - Assistant