if SERVER then AddCSLuaFile("autorun/permaprops_modified.lua");endPERMA = {}PERMA.Pos = {}PERMA.File = "permaprops.txt"PERMA.Blacklist = { "player", "world", "func_brush",}if SERVER then function PERMA_Initialize() Msg("Starting PERMA...\n") PERMA:LoadFromFile() for _,v in pairs( ents.GetAll() ) do if v:GetNWBool("isperma") then v:Remove() end end for _,v in pairs( PERMA.Pos ) do if game.GetMap() == v.map then local e = ents.Create( v.class ) e:SetNWBool( "isperma", true ) e:SetPos( v.pos ) e:SetAngles( v.ang ) e:SetColor( v.color.r, v.color.g, v.color.b, v.color.a ) e:SetModel( v.model ) e:SetMaterial( v.material ) e:SetSkin( v.skin ) e:SetSolid( v.solid ) e:SetName( v.name ) e:Spawn() e:Activate() local phys = e:GetPhysicsObject() if IsValid( phys ) then phys:EnableMotion(false) end end end umsg.Start("Perma_RevicePosses") umsg.String("start_revicing") umsg.End() for k,v in pairs(PERMA.Pos) do umsg.Start("Perma_RevicePosses") umsg.String("revicing") umsg.Vector(v.pos) umsg.String(v.model) umsg.End() end end hook.Add("InitPostEntity","InitializePermaProps",function() PERMA_Initialize() end) concommand.Add("perma_save",function(pl,cmd,args) if not pl:IsSuperAdmin() then return end local update = tobool(args[1]) local e = pl:GetEyeTrace().Entity if not ValidEntity( e ) then pl:ChatPrint("Ce n'est pas une entite valide!") return end if table.HasValue( PERMA.Blacklist, e ) then pl:ChatPrint("C'est une entite de la liste noire!") return end if e:GetNWBool("isperma") and not update then pl:ChatPrint("Cette entite est deja en World Props!") return end if update then if not e:GetNWBool("isperma") then pl:ChatPrint("Cette entite n'est pas encore en World Props.") return end PERMA:UpdateEnt( e ) pl:ChatPrint("Tu as mis jour le " .. e:GetClass() .. " que vous avez slectionn.") else PERMA:SaveEnt( e ) pl:ChatPrint("Tu as ajouter " .. e:GetClass() .. " avec le model ".. e:GetModel() .. " en World Props.") end end) concommand.Add("perma_printfile",function() PrintTable( glon.decode(file.Read(PERMA.File))) end) concommand.Add("perma_reload",function(pl,cmd,args) if not pl:IsSuperAdmin() then return end for _,v in pairs( ents.GetAll() ) do if v:GetNWBool("isperma") then v:Remove() end end for _,v in pairs( PERMA.Pos ) do if game.GetMap() == v.map then local e = ents.Create( v.class ) e:SetNWBool( "isperma", true ) e:SetPos( v.pos ) e:SetAngles( v.ang ) e:SetColor( v.color.r, v.color.g, v.color.b, v.color.a ) e:SetModel( v.model ) e:SetMaterial( v.material ) e:SetSkin( v.skin ) e:SetSolid( v.solid ) e:SetName( v.name ) e:Spawn() e:Activate() local phys = e:GetPhysicsObject() if IsValid( phys ) then phys:EnableMotion(false) end end end umsg.Start("Perma_RevicePosses") umsg.String("start_revicing") umsg.End() for k,v in pairs(PERMA.Pos) do umsg.Start("Perma_RevicePosses") umsg.String("revicing") umsg.Vector(v.pos) umsg.String(v.model) umsg.End() end end) concommand.Add("perma_printcurrent",function() PrintTable( PERMA.Pos ) end) concommand.Add("perma_toggle_2d",function(pl,cmd,args) if not pl:IsSuperAdmin() then return end pl.Perma_Toggled = pl.Perma_Toggled or false if not pl.Perma_Toggled then pl.Perma_Toggled = true PERMA.Pos = PERMA.Pos or {} umsg.Start("Perma_RevicePosses",pl) umsg.String("start_revicing") umsg.End() for k,v in pairs(PERMA.Pos) do umsg.Start("Perma_RevicePosses",pl) umsg.String("revicing") umsg.Vector(v.pos) umsg.String(v.model) umsg.End() end umsg.Start("Perma_RevicePosses",pl) umsg.String("enable_vision") umsg.End() elseif pl.Perma_Toggled then pl.Perma_Toggled = false umsg.Start("Perma_RevicePosses",pl) umsg.String("disable_vision") umsg.End() end end) concommand.Add("perma_remove",function( pl,cmd,args ) if not pl:IsSuperAdmin() then return end local e = pl:GetEyeTrace().Entity if not ValidEntity( e ) then pl:ChatPrint("Ce n'est pas une entite valide!") return end if not e:GetNWBool("isperma") then pl:ChatPrint("Ce n'est pas un WorldProp!") return end PERMA:RemoveEnt( e ) e:SetNWBool("isperma",false) pl:ChatPrint("Tu as effaces " .. e:GetClass() .. " avec un modele de " .. e:GetModel() .. " de la base de donnees.") end) concommand.Add("perma_delete_all",function( pl,cmd,args ) if not pl:IsSuperAdmin() then return end for _,v in pairs( ents.GetAll() ) do if v:GetNWBool("isperma") then v:Remove() end end end) concommand.Add("perma_isperma",function(pl) local e = pl:GetEyeTrace().Entity if not ValidEntity( e ) then pl:ChatPrint("Ce n'est pas une entite valide!") return end pl:ChatPrint( "Cette entit est" .. ( not e:GetNWBool("isperma") && " pas " || " " ) .. "un World Prop.") end) function PERMA:SaveEnt( ent ) local col = { ent:GetColor() } local info = { name = "perma"..table.Count(self.Pos), class = ent:GetClass(), pos = ent:GetPos(), ang = ent:GetAngles(), color = Color(col[1],col[2],col[3],col[4]), model = ent:GetModel(), material = ent:GetMaterial(), skin = ent:GetSkin(), solid = ent:GetSolid(), map = game.GetMap(), } local effectdata = EffectData() effectdata:SetMagnitude(2) effectdata:SetScale(2) effectdata:SetRadius(3) util.Effect("Sparks", effectdata) ent:SetName( info.name ) ent:SetNWBool("isperma", true ) self.Pos[info.name] = info self:SaveToFile() ent:Remove() RunConsoleCommand("perma_reload") end function PERMA:UpdateEnt( ent ) local col = { ent:GetColor() } local info = self.Pos[ent:GetName()] if info then info.pos = ent:GetPos() info.ang = ent:GetAngles() info.color = Color(col[1],col[2],col[3],col[4]) // does this break? info.model = ent:GetModel() info.material = ent:GetMaterial() info.skin = ent:GetSkin() info.solid = ent:GetSolid() self.Pos[ent:GetName()] = info self:SaveToFile() end end function PERMA:RemoveEnt( ent ) local name = ent:GetName() if not self.Pos[name] then return end table.remove(self.Pos,name) self:SaveToFile() ent:Remove() RunConsoleCommand("perma_reload") end function PERMA:LoadFromFile() if not file.Exists(self.File) then Msg("Wasen't able to find old Permas!") file.Write(self.File,glon.encode({})) else Msg("Perma's loaded from last time.") self.Pos = glon.decode(file.Read(self.File)) end end function PERMA:SaveToFile() Msg("Perma's saved.") file.Write(self.File,glon.encode(self.Pos)) endendif CLIENT then function ThePermaHUDPaint() PERMA = PERMA or {} PERMA.Pos = PERMA.Pos or {} for _,v in pairs( PERMA.Pos ) do zPoint = v.pos:ToScreen() draw.DrawText("Perma Prop\n(" .. v.model .. ")", "TargetID", zPoint.x, zPoint.y - 20, Color(255, 255, 255, 200), 1) draw.DrawText("Perma Prop\n(" .. v.model .. ")", "TargetID", zPoint.x + 1, zPoint.y - 21, Color(255, 0, 0, 255), 1) end end function RevicePermaPosses( um ) local state = um:ReadString() if state == "start_revicing" then PERMA = PERMA or {} PERMA.Pos = {} elseif state == "revicing" then local the_vector = um:ReadVector() or Vector(0,0,0) local the_string = um:ReadString() or "" local new_table = {pos = the_vector,model = the_string} table.insert(PERMA.Pos,new_table) elseif state == "enable_vision" then hook.Add("HUDPaint","PERMA_HUDPaint", ThePermaHUDPaint) elseif state == "disable_vision" then hook.Remove("HUDPaint","PERMA_HUDPaint") end end usermessage.Hook("Perma_RevicePosses",RevicePermaPosses)end