Files
VnUtest/garrysmod/addons/molotok/lua/entities/item_scrap1.lua
2026-03-31 10:27:04 +03:00

178 lines
4.3 KiB
Lua

AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_anim"
ENT.PrintName = "Scrap"
ENT.Category = "Other"
ENT.Spawnable = true
ENT.AdminOnly = false
ENT.DoNotDuplicate = false
ENT.AlreadyUsed = false
if SERVER then
util.AddNetworkString("DisplayScrap")
function ENT:SpawnFunction(ply, tr, cls)
if (!tr.Hit) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 20
local SpawnAng = ply:EyeAngles()
local ent = ents.Create(cls)
ent:SetPos(SpawnPos)
ent:SetAngles(SpawnAng)
ent:Spawn()
ent:Activate()
return ent
end
local mdltbl = {
"models/combine_turrets/floor_turret_gib1.mdl",
"models/combine_turrets/floor_turret_gib2.mdl",
"models/combine_turrets/floor_turret_gib3.mdl",
"models/combine_turrets/floor_turret_gib4.mdl",
"models/combine_turrets/floor_turret_gib5.mdl",
"models/gibs/manhack_gib01.mdl",
"models/gibs/manhack_gib02.mdl",
"models/gibs/manhack_gib04.mdl",
"models/props_c17/TrapPropeller_Lever.mdl",
"models/props_c17/utilityconnecter005.mdl",
"models/props_c17/utilityconnecter006.mdl",
"models/props_wasteland/gear01.mdl",
"models/props_wasteland/gear02.mdl"
}
function ENT:Initialize()
self:SetModel(table.Random(mdltbl))
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:DrawShadow(true)
self:SetTrigger(true)
self:UseTriggerBounds(true,14)
self:SetCollisionGroup(COLLISION_GROUP_WEAPON)
self:SetUseType(SIMPLE_USE)
local phys = self:GetPhysicsObject()
if IsValid(phys) then
phys:Wake()
phys:SetMass(25)
phys:SetMaterial( "metal" )
end
--SafeRemoveEntityDelayed( self, 30 )
end
function ENT:OnTakeDamage( damage )
self:TakePhysicsDamage(damage)
end
function ENT:PhysicsCollide(data, phys)
if data.DeltaTime > 0.2 then
if data.Speed > 250 then
self:EmitSound("debris/metal" .. math.random(1, 3) .. ".wav", 75, math.random(90,110), 0.5)
else
self:EmitSound("debris/metal" .. math.random(3, 6) .. ".wav", 75, math.random(90,110), 0.3)
end
end
end
function ENT:StartTouch( activator )
if activator:IsPlayer() then self:Use( activator ) end
end
function ENT:Use(activator, caller)
if self.AlreadyUsed then return end
if activator:IsPlayer() then
activator:SetNWInt("Scrap",activator:GetNWInt("Scrap",0)+math.random(25,75))
self:EmitSound("ui/item_metal_scrap_pickup.wav")
self:EmitSound("misc/scrap_sound/scrap_rebel.wav",75,math.random(95,105))
self:Remove()
net.Start("DisplayScrap")
net.WriteInt(1000,11)
net.Send(activator)
self.AlreadyUsed = true
end
end
end
if CLIENT then
function ENT:OnRemove()
local ed = EffectData()
ed:SetOrigin(self:GetPos())
ed:SetEntity(self)
util.Effect( "entity_remove", ed, true, true )
end
net.Receive("DisplayScrap", function(len, ply)
LocalPlayer().UIScrapFade = net.ReadInt(11)
end)
function ENT:BeingLookedAtByLocalPlayer()
local lp = LocalPlayer()
local trace = util.TraceHull( {
start = lp:GetShootPos(),
endpos = lp:GetShootPos() + lp:GetAimVector() * 200,
filter = lp,
mins = Vector( -3, -3, -3 ),
maxs = Vector( 3, 3, 3 ),
mask = MASK_SHOT,
} )
if trace.Entity ~= self then return false end
if trace.HitPos:Distance(LocalPlayer():GetShootPos()) > 200 then return false end
return true
end
local halos = {}
local halos_inv = {}
function ENT:DrawEntityOutline()
if halos_inv[self] then return end
halos[#halos+1] = self
halos_inv[self] = true
end
hook.Add("PreDrawHalos", "ScrapPickup", function()
if #halos == 0 then return end
halo.Add(halos, Color(255,255,255), 1, 1, 2, true, true)
halos = {}
halos_inv = {}
end)
local Mat = Material( "sprites/light_ignorez" )
function ENT:Draw()
self:DrawModel()
if self:BeingLookedAtByLocalPlayer() then
if self.RenderGroup == RENDERGROUP_OPAQUE then
self.OldRenderGroup = self.RenderGroup
self.RenderGroup = RENDERGROUP_TRANSLUCENT
end
self:DrawEntityOutline()
self:DrawModel()
AddWorldTip( nil, "Scrap", nil, self:WorldSpaceCenter(), nil )
else
if self.OldRenderGroup then
self.RenderGroup = self.OldRenderGroup
self.OldRenderGroup = nil
end
self:DrawModel()
render.SetMaterial( Mat ) render.DrawSprite( self:WorldSpaceCenter(), 32 +math.sin( SysTime()*2 )*4, 32 +math.sin( SysTime()*2 )*4, Color( 255, 255, 255, 192 ) )
render.DrawSprite( self:WorldSpaceCenter(), 8 +math.cos( SysTime()*2 )*2, 64 +math.cos( SysTime()*2 )*4, Color( 255, 255, 255, 192 ) )
end
end
end