Skip to content

Commit fabeef6

Browse files
committed
Add change type property
1 parent 6021ccf commit fabeef6

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

lua/entities/ucs_mineable/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function ENT:SpawnFunction( ply, tr, name )
1010
ent:SetMineableType( "rock" )
1111
ent:Spawn()
1212
ent:Activate()
13-
ply:ChatPrint( "Note: Mineable entities created from the spawn menu will always be set to the default Rock type." )
13+
ply:ChatPrint( "Note: You can change the type by right clicking the entity in the context menu." )
1414
return ent
1515
end
1616

lua/entities/ucs_table/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function ENT:SpawnFunction( ply, tr, name )
1010
ent:SetTableType( "hl2" )
1111
ent:Spawn()
1212
ent:Activate()
13-
ply:ChatPrint( "Note: Crafting tables created from the spawn menu will always be set to the default HL2 Weapon type." )
13+
ply:ChatPrint( "Note: You can change the type by right clicking the entity in the context menu." )
1414
return ent
1515
end
1616

lua/entities/ucs_table/shared.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ENT.Type = "anim"
22
ENT.PrintName = "Crafting Table"
33
ENT.Author = "OPGman"
44
ENT.Spawnable = true
5+
ENT.AdminOnly = true
56
ENT.Category = "Universal Crafting System"
67

78
function ENT:SetupDataTables()
@@ -19,5 +20,54 @@ function ENT:GetData()
1920
return CraftingTable[typ]
2021
end
2122

23+
properties.Add( "ucschangetype", {
24+
MenuLabel = "Change Type",
25+
Order = 1600,
26+
PrependSpacer = true,
27+
MenuIcon = "icon16/brick_edit.png",
28+
Filter = function( self, ent, ply )
29+
local allowed = {
30+
["ucs_table"] = true,
31+
["ucs_mineable"] = true
32+
}
33+
return IsValid( ent ) and allowed[ent:GetClass()] and ply:IsAdmin()
34+
end,
35+
MenuOpen = function( self, option, ent, tr )
36+
local sub = option:AddSubMenu()
37+
local tbl = ent:GetClass() == "ucs_table" and CraftingTable or MineableEntity
38+
for k,v in pairs( tbl ) do
39+
local opt = sub:AddOption( v.Name or "Invalid Type", function()
40+
self:SetType( ent, k )
41+
end )
42+
end
43+
end,
44+
Action = function() end,
45+
SetType = function( self, ent, typ )
46+
self:MsgStart()
47+
net.WriteEntity( ent )
48+
net.WriteString( typ )
49+
self:MsgEnd()
50+
end,
51+
Receive = function( self, len, ply )
52+
if !ply:IsAdmin() then return end
53+
local ent = net.ReadEntity()
54+
local typ = net.ReadString()
55+
local pos = ent:GetPos()
56+
local ang = ent:GetAngles()
57+
local class = ent:GetClass()
58+
ent:Remove()
59+
60+
local e = ents.Create( class )
61+
e:SetPos( pos )
62+
e:SetAngles( ang )
63+
if class == "ucs_table" then
64+
e:SetTableType( typ )
65+
else
66+
e:SetMineableType( typ )
67+
end
68+
e:Spawn()
69+
end
70+
} )
71+
2272
local version = "2.0"
2373
print( "Universal Crafting System v"..version.." by OPGman successfully loaded.\n" )

0 commit comments

Comments
 (0)