Skip to content

Commit b463f08

Browse files
committed
First push to github from workshop.
0 parents  commit b463f08

40 files changed

+1530
-0
lines changed

addon.txt

Whitespace-only changes.

lua/autorun/pointshop.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
if SERVER then
2+
AddCSLuaFile()
3+
AddCSLuaFile('vgui/DPointShopMenu.lua')
4+
AddCSLuaFile('vgui/DPointShopItem.lua')
5+
AddCSLuaFile('sh_pointshop.lua')
6+
AddCSLuaFile('sh_config.lua')
7+
AddCSLuaFile('cl_player_extension.lua')
8+
AddCSLuaFile('cl_pointshop.lua')
9+
10+
include('sh_pointshop.lua')
11+
include('sh_config.lua')
12+
include('sv_player_extension.lua')
13+
include('sv_pointshop.lua')
14+
end
15+
16+
if CLIENT then
17+
include('vgui/DPointShopMenu.lua')
18+
include('vgui/DPointShopItem.lua')
19+
include('sh_pointshop.lua')
20+
include('sh_config.lua')
21+
include('cl_player_extension.lua')
22+
include('cl_pointshop.lua')
23+
end
24+
25+
PS:LoadItems()

lua/cl_player_extension.lua

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
local Player = FindMetaTable('Player')
2+
3+
-- items
4+
5+
function Player:PS_GetItems()
6+
return self.PS_Items or {}
7+
end
8+
9+
function Player:PS_HasItem(item_id)
10+
return self.PS_Items[item_id] and true or false
11+
end
12+
13+
function Player:PS_HasItemEquipped(item_id)
14+
if not self:PS_HasItem(item_id) then return false end
15+
16+
return self.PS_Items[item_id].Equipped or false
17+
end
18+
19+
function Player:PS_BuyItem(item_id)
20+
if self:PS_HasItem(item_id) then return false end
21+
if not self:PS_HasPoints(PS.Items[item_id].Price) then return false end
22+
23+
net.Start('PS_BuyItem')
24+
net.WriteString(item_id)
25+
net.SendToServer()
26+
end
27+
28+
function Player:PS_SellItem(item_id)
29+
if not self:PS_HasItem(item_id) then return false end
30+
31+
net.Start('PS_SellItem')
32+
net.WriteString(item_id)
33+
net.SendToServer()
34+
end
35+
36+
function Player:PS_EquipItem(item_id)
37+
if not self:PS_HasItem(item_id) then return false end
38+
39+
net.Start('PS_EquipItem')
40+
net.WriteString(item_id)
41+
net.SendToServer()
42+
end
43+
44+
function Player:PS_HolsterItem(item_id)
45+
if not self:PS_HasItem(item_id) then return false end
46+
47+
net.Start('PS_HolsterItem')
48+
net.WriteString(item_id)
49+
net.SendToServer()
50+
end
51+
52+
-- points
53+
54+
function Player:PS_GetPoints()
55+
return self.PS_Points or 0
56+
end
57+
58+
function Player:PS_HasPoints(points)
59+
return self:PS_GetPoints() >= points
60+
end
61+
62+
-- clientside models
63+
64+
function Player:PS_AddClientsideModel(item_id)
65+
if not PS.Items[item_id] then return false end
66+
67+
local ITEM = PS.Items[item_id]
68+
69+
local mdl = ClientsideModel(ITEM.Model, RENDERGROUP_OPAQUE)
70+
mdl:SetNoDraw(true)
71+
72+
if not PS.ClientsideModels[self] then PS.ClientsideModels[self] = {} end
73+
PS.ClientsideModels[self][item_id] = mdl
74+
end
75+
76+
function Player:PS_RemoveClientsideModel(item_id)
77+
if not PS.Items[item_id] then return false end
78+
if not PS.ClientsideModels[self][item_id] then return false end
79+
80+
PS.ClientsideModels[self][item_id] = nil
81+
end

lua/cl_pointshop.lua

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
PS.ShopMenu = nil
2+
PS.ClientsideModels = {}
3+
4+
-- menu stuff
5+
6+
function PS:ToggleMenu()
7+
if not PS.ShopMenu then
8+
PS.ShopMenu = vgui.Create('DPointShopMenu')
9+
PS.ShopMenu:SetVisible(false)
10+
end
11+
12+
if PS.ShopMenu:IsVisible() then
13+
PS.ShopMenu:Hide()
14+
gui.EnableScreenClicker(false)
15+
else
16+
PS.ShopMenu:Show()
17+
gui.EnableScreenClicker(true)
18+
end
19+
end
20+
21+
-- modification stuff
22+
23+
function PS:ShowColorChooser(item, modifications)
24+
-- TODO: Do this
25+
local chooser = vgui.Create('DPointShopColorChooser')
26+
chooser:SetColor(modifications.color)
27+
28+
chooser.OnChoose = function(color)
29+
self:SendModifications(item.ID, {color = color})
30+
end
31+
end
32+
33+
function PS:SendModifications(item_id, modifications)
34+
net.Start('PS_ModifyItem')
35+
net.WriteString(item_id)
36+
net.WriteTable(modifications)
37+
net.SendToServer()
38+
end
39+
40+
-- net hooks
41+
42+
net.Receive('PS_ToggleMenu', function(length)
43+
PS:ToggleMenu()
44+
end)
45+
46+
net.Receive('PS_Items', function(length)
47+
local ply = net.ReadEntity()
48+
local items = net.ReadTable()
49+
ply.PS_Items = PS:ValidateItems(items)
50+
end)
51+
52+
net.Receive('PS_Points', function(length)
53+
local ply = net.ReadEntity()
54+
local points = net.ReadInt(32)
55+
ply.PS_Points = PS:ValidatePoints(points)
56+
end)
57+
58+
net.Receive('PS_AddClientsideModel', function(length)
59+
local ply = net.ReadEntity()
60+
local item_id = net.ReadString()
61+
62+
ply:PS_AddClientsideModel(item_id)
63+
end)
64+
65+
net.Receive('PS_RemoveClientsideModel', function(length)
66+
local ply = net.ReadEntity()
67+
local item_id = net.ReadString()
68+
69+
ply:PS_RemoveClientsideModel(item_id)
70+
end)
71+
72+
net.Receive('PS_SendClientsideModels', function(length)
73+
for ply, items in pairs(net.ReadTable()) do
74+
for _, item_id in pairs(items) do
75+
if PS.Items[item_id] then
76+
ply:PS_AddClientsideModel(item_id)
77+
end
78+
end
79+
end
80+
end)
81+
82+
-- hooks
83+
84+
hook.Add('PostPlayerDraw', 'PS_PostPlayerDraw', function(ply)
85+
if not ply:Alive() then return end
86+
if ply == LocalPlayer() and GetViewEntity():GetClass() == 'player' then return end
87+
if not PS.ClientsideModels[ply] then return end
88+
89+
for item_id, model in pairs(PS.ClientsideModels[ply]) do
90+
if not PS.Items[item_id] then PS.ClientsideModel[ply][item_id] = nil continue end
91+
92+
local ITEM = PS.Items[item_id]
93+
94+
if not ITEM.Attachment and not ITEM.Bone then PS.ClientsideModel[ply][item_id] = nil continue end
95+
96+
local pos = Vector()
97+
local ang = Angle()
98+
99+
if ITEM.Attachment then
100+
local attach = ply:GetAttachment(ply:LookupAttachment(ITEM.Attachment))
101+
pos = attach.Pos
102+
ang = attach.Ang
103+
else
104+
pos, ang = ply:GetBonePosition(ply:LookupBone(ITEM.Bone))
105+
end
106+
107+
model, pos, ang = ITEM:ModifyClientsideModel(ply, model, pos, ang)
108+
109+
model:SetPos(pos)
110+
model:SetAngles(ang)
111+
112+
model:SetRenderOrigin(pos)
113+
model:SetRenderAngles(ang)
114+
model:SetupBones()
115+
model:DrawModel()
116+
model:SetRenderOrigin()
117+
model:SetRenderAngles()
118+
end
119+
end)

lua/items/accessories/__category.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CATEGORY.Name = 'Accessories'
2+
CATEGORY.Icon = 'add'
3+
CATEGORY.AllowedEquiped = 1

lua/items/accessories/backpack.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ITEM.Name = 'Backpack'
2+
ITEM.Price = 100
3+
ITEM.Model = 'models/props_c17/SuitCase_Passenger_Physics.mdl'
4+
ITEM.Bone = 'ValveBiped.Bip01_Spine2'
5+
6+
function ITEM:OnEquip(ply, modifications)
7+
ply:PS_AddClientsideModel(self.ID)
8+
end
9+
10+
function ITEM:OnHolster(ply)
11+
ply:PS_RemoveClientsideModel(self.ID)
12+
end
13+
14+
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
15+
model:SetModelScale(0.8, 0)
16+
pos = pos + (ang:Right() * 5) + (ang:Up() * 6) + (ang:Forward() * 2)
17+
18+
return model, pos, ang
19+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CATEGORY.Name = 'Hats, Heads and Masks'
2+
CATEGORY.Icon = 'emoticon_smile'
3+
CATEGORY.AllowedEquiped = 1

lua/items/headshatsmasks/afro.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ITEM.Name = 'Afro'
2+
ITEM.Price = 200
3+
ITEM.Model = 'models/dav0r/hoverball.mdl'
4+
ITEM.Attachment = 'eyes'
5+
6+
function ITEM:OnEquip(ply, modifications)
7+
ply:PS_AddClientsideModel(self.ID)
8+
end
9+
10+
function ITEM:OnHolster(ply)
11+
ply:PS_RemoveClientsideModel(self.ID)
12+
end
13+
14+
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
15+
model:SetModelScale(1.6, 0)
16+
model:SetMaterial('models/weapons/v_stunbaton/w_shaft01a')
17+
pos = pos + (ang:Forward() * -7) + (ang:Up() * 8)
18+
ang:RotateAroundAxis(ang:Right(), 90)
19+
20+
return model, pos, ang
21+
end

lua/items/headshatsmasks/bombhead.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ITEM.Name = 'Bomb Head'
2+
ITEM.Price = 100
3+
ITEM.Model = 'models/Combine_Helicopter/helicopter_bomb01.mdl'
4+
ITEM.Attachment = 'eyes'
5+
6+
function ITEM:OnEquip(ply, modifications)
7+
ply:PS_AddClientsideModel(self.ID)
8+
end
9+
10+
function ITEM:OnHolster(ply)
11+
ply:PS_RemoveClientsideModel(self.ID)
12+
end
13+
14+
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
15+
model:SetModelScale(0.5, 0)
16+
pos = pos + (ang:Forward() * -2)
17+
ang:RotateAroundAxis(ang:Right(), 90)
18+
19+
return model, pos, ang
20+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ITEM.Name = 'Bucket Hat'
2+
ITEM.Price = 100
3+
ITEM.Model = 'models/props_junk/MetalBucket01a.mdl'
4+
ITEM.Attachment = 'eyes'
5+
6+
function ITEM:OnEquip(ply)
7+
ply:PS_AddClientsideModel(self.ID)
8+
end
9+
10+
function ITEM:OnHolster(ply)
11+
ply:PS_RemoveClientsideModel(self.ID)
12+
end
13+
14+
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
15+
model:SetModelScale(0.7, 0)
16+
pos = pos + (ang:Forward() * -5) + (ang:Up() * 5)
17+
ang:RotateAroundAxis(ang:Right(), 200)
18+
19+
return model, pos, ang
20+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ITEM.Name = 'Clock Mask'
2+
ITEM.Price = 50
3+
ITEM.Model = 'models/props_c17/clock01.mdl'
4+
ITEM.Attachment = 'eyes'
5+
6+
function ITEM:OnEquip(ply, modifications)
7+
ply:PS_AddClientsideModel(self.ID)
8+
end
9+
10+
function ITEM:OnHolster(ply)
11+
ply:PS_RemoveClientsideModel(self.ID)
12+
end
13+
14+
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
15+
ang:RotateAroundAxis(ang:Right(), -90)
16+
17+
return model, pos, ang
18+
end

lua/items/headshatsmasks/conehat.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ITEM.Name = 'Cone Hat'
2+
ITEM.Price = 100
3+
ITEM.Model = 'models/props_junk/TrafficCone001a.mdl'
4+
ITEM.Attachment = 'eyes'
5+
6+
function ITEM:OnEquip(ply)
7+
ply:PS_AddClientsideModel(self.ID)
8+
end
9+
10+
function ITEM:OnHolster(ply)
11+
ply:PS_RemoveClientsideModel(self.ID)
12+
end
13+
14+
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
15+
model:SetModelScale(0.8, 0)
16+
pos = pos + (ang:Forward() * -7) + (ang:Up() * 11)
17+
ang:RotateAroundAxis(ang:Right(), 20)
18+
19+
return model, pos, ang
20+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ITEM.Name = 'Headcrab Hat'
2+
ITEM.Price = 100
3+
ITEM.Model = 'models/headcrabclassic.mdl'
4+
ITEM.Attachment = 'eyes'
5+
ITEM.AdminOnly = true
6+
7+
function ITEM:OnEquip(ply, modifications)
8+
ply:PS_AddClientsideModel(self.ID)
9+
end
10+
11+
function ITEM:OnHolster(ply)
12+
ply:PS_RemoveClientsideModel(self.ID)
13+
end
14+
15+
function ITEM:ModifyClientsideModel(ply, model, pos, ang)
16+
model:SetModelScale(0.7, 0)
17+
pos = pos + (ang:Forward() * 2)
18+
ang:RotateAroundAxis(ang:Right(), 20)
19+
20+
return model, pos, ang
21+
end

0 commit comments

Comments
 (0)