local EntityMeta = FindMetaTable( "Entity" ) function EntityMeta:SetResourceDropInfo( strType, int ) timer.Simple( 0.5, function() self:SetResourceDropInfoInstant( strType, int ) end ) end function EntityMeta:SetResourceDropInfoInstant( strType, int ) for k, v in pairs( player.GetAll() ) do local strType = strType or "Error" umsg.Start( "gms_SetResourceDropInfo", v ) umsg.String( self:EntIndex() ) umsg.String( string.gsub( strType, "_", " " ) ) umsg.Short( self.Amount ) umsg.End() end end function EntityMeta:SetResPackInfo( strType, int ) for k, v in pairs( player.GetAll() ) do local strType = strType or "Error" umsg.Start( "gms_SetResPackInfo", v ) umsg.String( self:EntIndex() ) umsg.String( string.gsub( strType, "_", " " ) ) umsg.Short( int ) umsg.End() end end function EntityMeta:SetFoodInfo( strType ) timer.Simple( 0.5, function() self:SetFoodInfoInstant( strType ) end ) end function EntityMeta:SetFoodInfoInstant( strType ) for k, v in pairs( player.GetAll() ) do local strType = strType or "Error" umsg.Start( "gms_SetFoodDropInfo", v ) umsg.String( self:EntIndex() ) umsg.String( string.gsub( strType, "_", " " ) ) umsg.End() end end function EntityMeta:DropToGround() local trace = {} trace.start = self:GetPos() trace.endpos = trace.start + Vector( 0, 0, -100000 ) trace.mask = MASK_SOLID_BRUSHONLY trace.filter = self local tr = util.TraceLine( trace ) self:SetPos( tr.HitPos ) end GMS.LootableNPCs = { "npc_antlion", "npc_antlionguard", "npc_crow", "npc_seagull", "npc_pigeon", "npc_zombie" } function EntityMeta:IsLootableNPC() return table.HasValue( GMS.LootableNPCs, self:GetClass() ) end function EntityMeta:MakeCampfire() if ( GetConVarNumber( "gms_campfire" ) <= 0 ) then return end local min, max = self:OBBMins(), self:OBBMaxs() local vol = math.abs( max.x - min.x ) * math.abs( max.y - min.y ) * math.abs( max.z - min.z ) local mul = math.min( math.sqrt( vol ) / 200, 1 ) if ( !self.CampFire ) then self:SetHealth( 1337 ) end self.CampFire = true timer.Create( "gms_removecampfire_" .. self:EntIndex(), 480 * mul, 1, function() if ( IsValid( self ) ) then self:Fadeout() end end ) if ( GetConVarNumber( "gms_SpreadFire" ) >= 1 ) then self:Ignite( 360, ( self:OBBMins() - self:OBBMaxs() ):Length() + 10 ) else self:Ignite( 360, 0.001 ) end end /* ---------------------------------------------------------------------------------------------------- Entity Fading ---------------------------------------------------------------------------------------------------- */ GMS.FadingOutProps = {} GMS.FadingInProps = {} print("GMS_FadingInProps initalized") function EntityMeta:Fadeout( speed ) if ( !IsValid( self ) ) then return end local speed = speed or 1 for k, v in pairs( player.GetAll() ) do umsg.Start( "gms_CreateFadingProp", v ) umsg.String( self:GetModel() ) umsg.Vector( self:GetPos() ) local ang = self:GetAngles() umsg.Vector( Vector( ang.p, ang.y, ang.r ) ) local col = self:GetColor() umsg.Vector( Vector( col.r, col.g, col.b ) ) umsg.Short( math.Round( speed ) ) umsg.End() end self:Remove() end --Fadein is serverside function EntityMeta:Fadein( speed ) self.AlphaFade = 0 self:SetRenderMode( RENDERMODE_TRANSALPHA ) self:SetColor( Color( 255, 255, 255, 0 ) ) self.FadeInSpeed = speed or 4 table.insert( GMS.FadingInProps, self ) end hook.Add( "Think", "gms_FadePropsThink", function() if(GMS.FadingInProps == nil) then return end for k, ent in pairs( GMS.FadingInProps ) do if ( !ent or ent == NULL ) then table.remove( GMS.FadingInProps, k ) elseif ( !IsValid( ent ) ) then table.remove( GMS.FadingInProps, k ) elseif ( ent.AlphaFade >= 255 ) then table.remove( GMS.FadingInProps, k ) else ent.AlphaFade = ent.AlphaFade + ent.FadeInSpeed ent:SetColor( Color( 255, 255, 255, ent.AlphaFade ) ) end end end ) /* ---------------------------------------------------------------------------------------------------- Entity rising / lowering ( Used by gms_seed ) ---------------------------------------------------------------------------------------------------- */ GM.RisingProps = {} GM.SinkingProps = {} function EntityMeta:RiseFromGround( speed, altmax ) local speed = speed or 1 local max; if ( !altmax ) then min, max = self:WorldSpaceAABB() max = max.z else max = altmax end local tbl = {} tbl.Origin = self:GetPos().z tbl.Speed = speed tbl.Entity = self self:SetPos( self:GetPos() + Vector( 0, 0, -max + 10 ) ) table.insert( GAMEMODE.RisingProps, tbl ) end function EntityMeta:SinkIntoGround( speed ) local speed = speed or 1 local tbl = {} tbl.Origin = self:GetPos().z tbl.Speed = speed tbl.Entity = self tbl.Height = max table.insert( GAMEMODE.SinkingProps, tbl ) end hook.Add( "Think", "gms_RiseAndSinkPropsHook", function() for k, tbl in pairs( GAMEMODE.RisingProps ) do if ( !IsValid( tbl.Entity ) || tbl.Entity:GetPos().z >= tbl.Origin ) then table.remove( GAMEMODE.RisingProps, k ) else tbl.Entity:SetPos( tbl.Entity:GetPos() + Vector( 0, 0, 1 * tbl.Speed ) ) end end for k, tbl in pairs( GAMEMODE.SinkingProps ) do if ( !IsValid( tbl.Entity ) || tbl.Entity:GetPos().z <= tbl.Origin - tbl.Height ) then table.remove( GAMEMODE.SinkingProps, k ) tbl.Entity:Remove() else tbl.Entity:SetPos( tbl.Entity:GetPos() + Vector( 0, 0, -1 * tbl.Speed ) ) end end end )