Script Help !

Hello,
I recode the PermaProps and I have a problem adding it bug PermaProps.

example:
I added and added it is added or not.

So here is the script:



if not glon then require("glon") end

PERMA = {}
PERMA.Pos = {}
PERMA.File = "permaprops.txt"
PERMA.Blacklist = {
	"player",
	"world",
	"func_brush",
}

//cleanup.Register("permaprops")

if SERVER then
	AddCSLuaFile("permaprops.lua");

	function PERMA:Initialize()
		self:LoadFromFile()
		
		for _,v in pairs( ents.GetAll() ) do
			if v:GetNWBool("isperma") then v:Remove() end
		end
		
		for _,v in pairs( self.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
		
		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( self.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
				self:UpdateEnt( e ) 
				pl:ChatPrint("Tu as mis à jour le " .. e:GetClass() .. " que vous avez sélectionné.")
			else 
				self: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(self.File)))
		end)
		
		concommand.Add("perma_reload",function()
		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( self.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
	end)
		
		concommand.Add("perma_printcurrent",function()
			PrintTable( self.Pos )
		end)
		
		concommand.Add("perma_remove",function( pl )
			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
			
			self: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_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)
		
	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()]
		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
	
	function PERMA:RemoveEnt( ent )
		local name = ent:GetName()
		if not self.Pos[name] then return end
		self.Pos[name] = nil
		self:SaveToFile()
		ent:Remove()
		RunConsoleCommand("perma_reload")
	end
	
	function PERMA:LoadFromFile()
		if not file.Exists(self.File) then file.Write(self.File,glon.encode({}))
		else self.Pos = glon.decode(file.Read(self.File)) end
	end
	
	function PERMA:SaveToFile()
		file.Write(self.File,glon.encode(self.Pos))
	end
	
	hook.Add("InitPostEntity","InitializePermaProps",function() PERMA:Initialize() end)
end

Ps: sorry i speak French =)

Here is it fixed, remember to save the file as permaprops_modified.lua and put it inside “garrysmod/lua/autorun”



if SERVER then
	AddCSLuaFile("autorun/permaprops_modified.lua");
end

PERMA = {}
PERMA.Pos = {}
PERMA.File = "permaprops_v2.txt"
PERMA.Blacklist = {
	"player",
	"world",
	"func_brush",
}

if SERVER then

	function PERMA:Initialize()
	
		Msg("Starting PERMA...
")
	
		self:LoadFromFile()
		
		for _,v in pairs( ents.GetAll() ) do
			if v:GetNWBool("isperma") then v:Remove() end
		end
		
		for _,v in pairs( self.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_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 sélectionné.")
		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()]
		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
	
	function PERMA:RemoveEnt( ent )
		local name = ent:GetName()
		if not self.Pos[name] then return end
		self.Pos[name] = nil
		self:SaveToFile()
		ent:Remove()
		RunConsoleCommand("perma_reload")
	end
	
	function PERMA:LoadFromFile()
		if not file.Exists(self.File) then
			file.Write(self.File,glon.encode({}))
		else
			self.Pos = glon.decode(file.Read(self.File))
		end
	end
	
	function PERMA:SaveToFile()
		file.Write(self.File,glon.encode(self.Pos))
	end
	
	hook.Add("InitPostEntity","InitializePermaProps",function() PERMA:Initialize() end)
	
end

if 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
(" .. v.model .. ")", "TargetID", zPoint.x, zPoint.y - 20, Color(255, 255, 255, 200), 1)
			draw.DrawText("Perma Prop
(" .. 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


Also I added a new command perma_toggle_2d, to show where the props are when they are not spawned :slight_smile:

Have fun with it.

The bug is when you delete a permaprops, I saw not long ago.

UP !

I’m sorry what are you trying to accomplish. What happens when you delete a permaprop? What is the bug?

When I add a world props at a time its deleted for no raison

if not give me your steam name and I add you

And if I can have faster response to his super will

Please stop using google translator.

Sorry, but my English is not great good, it is for his that I use a translator :slight_smile:

UP !

OMG ! Help me !

Up ?!