forked from TheWhichDoctor/pointshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b463f08
Showing
40 changed files
with
1,530 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
if SERVER then | ||
AddCSLuaFile() | ||
AddCSLuaFile('vgui/DPointShopMenu.lua') | ||
AddCSLuaFile('vgui/DPointShopItem.lua') | ||
AddCSLuaFile('sh_pointshop.lua') | ||
AddCSLuaFile('sh_config.lua') | ||
AddCSLuaFile('cl_player_extension.lua') | ||
AddCSLuaFile('cl_pointshop.lua') | ||
|
||
include('sh_pointshop.lua') | ||
include('sh_config.lua') | ||
include('sv_player_extension.lua') | ||
include('sv_pointshop.lua') | ||
end | ||
|
||
if CLIENT then | ||
include('vgui/DPointShopMenu.lua') | ||
include('vgui/DPointShopItem.lua') | ||
include('sh_pointshop.lua') | ||
include('sh_config.lua') | ||
include('cl_player_extension.lua') | ||
include('cl_pointshop.lua') | ||
end | ||
|
||
PS:LoadItems() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
local Player = FindMetaTable('Player') | ||
|
||
-- items | ||
|
||
function Player:PS_GetItems() | ||
return self.PS_Items or {} | ||
end | ||
|
||
function Player:PS_HasItem(item_id) | ||
return self.PS_Items[item_id] and true or false | ||
end | ||
|
||
function Player:PS_HasItemEquipped(item_id) | ||
if not self:PS_HasItem(item_id) then return false end | ||
|
||
return self.PS_Items[item_id].Equipped or false | ||
end | ||
|
||
function Player:PS_BuyItem(item_id) | ||
if self:PS_HasItem(item_id) then return false end | ||
if not self:PS_HasPoints(PS.Items[item_id].Price) then return false end | ||
|
||
net.Start('PS_BuyItem') | ||
net.WriteString(item_id) | ||
net.SendToServer() | ||
end | ||
|
||
function Player:PS_SellItem(item_id) | ||
if not self:PS_HasItem(item_id) then return false end | ||
|
||
net.Start('PS_SellItem') | ||
net.WriteString(item_id) | ||
net.SendToServer() | ||
end | ||
|
||
function Player:PS_EquipItem(item_id) | ||
if not self:PS_HasItem(item_id) then return false end | ||
|
||
net.Start('PS_EquipItem') | ||
net.WriteString(item_id) | ||
net.SendToServer() | ||
end | ||
|
||
function Player:PS_HolsterItem(item_id) | ||
if not self:PS_HasItem(item_id) then return false end | ||
|
||
net.Start('PS_HolsterItem') | ||
net.WriteString(item_id) | ||
net.SendToServer() | ||
end | ||
|
||
-- points | ||
|
||
function Player:PS_GetPoints() | ||
return self.PS_Points or 0 | ||
end | ||
|
||
function Player:PS_HasPoints(points) | ||
return self:PS_GetPoints() >= points | ||
end | ||
|
||
-- clientside models | ||
|
||
function Player:PS_AddClientsideModel(item_id) | ||
if not PS.Items[item_id] then return false end | ||
|
||
local ITEM = PS.Items[item_id] | ||
|
||
local mdl = ClientsideModel(ITEM.Model, RENDERGROUP_OPAQUE) | ||
mdl:SetNoDraw(true) | ||
|
||
if not PS.ClientsideModels[self] then PS.ClientsideModels[self] = {} end | ||
PS.ClientsideModels[self][item_id] = mdl | ||
end | ||
|
||
function Player:PS_RemoveClientsideModel(item_id) | ||
if not PS.Items[item_id] then return false end | ||
if not PS.ClientsideModels[self][item_id] then return false end | ||
|
||
PS.ClientsideModels[self][item_id] = nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
PS.ShopMenu = nil | ||
PS.ClientsideModels = {} | ||
|
||
-- menu stuff | ||
|
||
function PS:ToggleMenu() | ||
if not PS.ShopMenu then | ||
PS.ShopMenu = vgui.Create('DPointShopMenu') | ||
PS.ShopMenu:SetVisible(false) | ||
end | ||
|
||
if PS.ShopMenu:IsVisible() then | ||
PS.ShopMenu:Hide() | ||
gui.EnableScreenClicker(false) | ||
else | ||
PS.ShopMenu:Show() | ||
gui.EnableScreenClicker(true) | ||
end | ||
end | ||
|
||
-- modification stuff | ||
|
||
function PS:ShowColorChooser(item, modifications) | ||
-- TODO: Do this | ||
local chooser = vgui.Create('DPointShopColorChooser') | ||
chooser:SetColor(modifications.color) | ||
|
||
chooser.OnChoose = function(color) | ||
self:SendModifications(item.ID, {color = color}) | ||
end | ||
end | ||
|
||
function PS:SendModifications(item_id, modifications) | ||
net.Start('PS_ModifyItem') | ||
net.WriteString(item_id) | ||
net.WriteTable(modifications) | ||
net.SendToServer() | ||
end | ||
|
||
-- net hooks | ||
|
||
net.Receive('PS_ToggleMenu', function(length) | ||
PS:ToggleMenu() | ||
end) | ||
|
||
net.Receive('PS_Items', function(length) | ||
local ply = net.ReadEntity() | ||
local items = net.ReadTable() | ||
ply.PS_Items = PS:ValidateItems(items) | ||
end) | ||
|
||
net.Receive('PS_Points', function(length) | ||
local ply = net.ReadEntity() | ||
local points = net.ReadInt(32) | ||
ply.PS_Points = PS:ValidatePoints(points) | ||
end) | ||
|
||
net.Receive('PS_AddClientsideModel', function(length) | ||
local ply = net.ReadEntity() | ||
local item_id = net.ReadString() | ||
|
||
ply:PS_AddClientsideModel(item_id) | ||
end) | ||
|
||
net.Receive('PS_RemoveClientsideModel', function(length) | ||
local ply = net.ReadEntity() | ||
local item_id = net.ReadString() | ||
|
||
ply:PS_RemoveClientsideModel(item_id) | ||
end) | ||
|
||
net.Receive('PS_SendClientsideModels', function(length) | ||
for ply, items in pairs(net.ReadTable()) do | ||
for _, item_id in pairs(items) do | ||
if PS.Items[item_id] then | ||
ply:PS_AddClientsideModel(item_id) | ||
end | ||
end | ||
end | ||
end) | ||
|
||
-- hooks | ||
|
||
hook.Add('PostPlayerDraw', 'PS_PostPlayerDraw', function(ply) | ||
if not ply:Alive() then return end | ||
if ply == LocalPlayer() and GetViewEntity():GetClass() == 'player' then return end | ||
if not PS.ClientsideModels[ply] then return end | ||
|
||
for item_id, model in pairs(PS.ClientsideModels[ply]) do | ||
if not PS.Items[item_id] then PS.ClientsideModel[ply][item_id] = nil continue end | ||
|
||
local ITEM = PS.Items[item_id] | ||
|
||
if not ITEM.Attachment and not ITEM.Bone then PS.ClientsideModel[ply][item_id] = nil continue end | ||
|
||
local pos = Vector() | ||
local ang = Angle() | ||
|
||
if ITEM.Attachment then | ||
local attach = ply:GetAttachment(ply:LookupAttachment(ITEM.Attachment)) | ||
pos = attach.Pos | ||
ang = attach.Ang | ||
else | ||
pos, ang = ply:GetBonePosition(ply:LookupBone(ITEM.Bone)) | ||
end | ||
|
||
model, pos, ang = ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
|
||
model:SetPos(pos) | ||
model:SetAngles(ang) | ||
|
||
model:SetRenderOrigin(pos) | ||
model:SetRenderAngles(ang) | ||
model:SetupBones() | ||
model:DrawModel() | ||
model:SetRenderOrigin() | ||
model:SetRenderAngles() | ||
end | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CATEGORY.Name = 'Accessories' | ||
CATEGORY.Icon = 'add' | ||
CATEGORY.AllowedEquiped = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ITEM.Name = 'Backpack' | ||
ITEM.Price = 100 | ||
ITEM.Model = 'models/props_c17/SuitCase_Passenger_Physics.mdl' | ||
ITEM.Bone = 'ValveBiped.Bip01_Spine2' | ||
|
||
function ITEM:OnEquip(ply, modifications) | ||
ply:PS_AddClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:OnHolster(ply) | ||
ply:PS_RemoveClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
model:SetModelScale(0.8, 0) | ||
pos = pos + (ang:Right() * 5) + (ang:Up() * 6) + (ang:Forward() * 2) | ||
|
||
return model, pos, ang | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CATEGORY.Name = 'Hats, Heads and Masks' | ||
CATEGORY.Icon = 'emoticon_smile' | ||
CATEGORY.AllowedEquiped = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
ITEM.Name = 'Afro' | ||
ITEM.Price = 200 | ||
ITEM.Model = 'models/dav0r/hoverball.mdl' | ||
ITEM.Attachment = 'eyes' | ||
|
||
function ITEM:OnEquip(ply, modifications) | ||
ply:PS_AddClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:OnHolster(ply) | ||
ply:PS_RemoveClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
model:SetModelScale(1.6, 0) | ||
model:SetMaterial('models/weapons/v_stunbaton/w_shaft01a') | ||
pos = pos + (ang:Forward() * -7) + (ang:Up() * 8) | ||
ang:RotateAroundAxis(ang:Right(), 90) | ||
|
||
return model, pos, ang | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ITEM.Name = 'Bomb Head' | ||
ITEM.Price = 100 | ||
ITEM.Model = 'models/Combine_Helicopter/helicopter_bomb01.mdl' | ||
ITEM.Attachment = 'eyes' | ||
|
||
function ITEM:OnEquip(ply, modifications) | ||
ply:PS_AddClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:OnHolster(ply) | ||
ply:PS_RemoveClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
model:SetModelScale(0.5, 0) | ||
pos = pos + (ang:Forward() * -2) | ||
ang:RotateAroundAxis(ang:Right(), 90) | ||
|
||
return model, pos, ang | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ITEM.Name = 'Bucket Hat' | ||
ITEM.Price = 100 | ||
ITEM.Model = 'models/props_junk/MetalBucket01a.mdl' | ||
ITEM.Attachment = 'eyes' | ||
|
||
function ITEM:OnEquip(ply) | ||
ply:PS_AddClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:OnHolster(ply) | ||
ply:PS_RemoveClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
model:SetModelScale(0.7, 0) | ||
pos = pos + (ang:Forward() * -5) + (ang:Up() * 5) | ||
ang:RotateAroundAxis(ang:Right(), 200) | ||
|
||
return model, pos, ang | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ITEM.Name = 'Clock Mask' | ||
ITEM.Price = 50 | ||
ITEM.Model = 'models/props_c17/clock01.mdl' | ||
ITEM.Attachment = 'eyes' | ||
|
||
function ITEM:OnEquip(ply, modifications) | ||
ply:PS_AddClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:OnHolster(ply) | ||
ply:PS_RemoveClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
ang:RotateAroundAxis(ang:Right(), -90) | ||
|
||
return model, pos, ang | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ITEM.Name = 'Cone Hat' | ||
ITEM.Price = 100 | ||
ITEM.Model = 'models/props_junk/TrafficCone001a.mdl' | ||
ITEM.Attachment = 'eyes' | ||
|
||
function ITEM:OnEquip(ply) | ||
ply:PS_AddClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:OnHolster(ply) | ||
ply:PS_RemoveClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
model:SetModelScale(0.8, 0) | ||
pos = pos + (ang:Forward() * -7) + (ang:Up() * 11) | ||
ang:RotateAroundAxis(ang:Right(), 20) | ||
|
||
return model, pos, ang | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
ITEM.Name = 'Headcrab Hat' | ||
ITEM.Price = 100 | ||
ITEM.Model = 'models/headcrabclassic.mdl' | ||
ITEM.Attachment = 'eyes' | ||
ITEM.AdminOnly = true | ||
|
||
function ITEM:OnEquip(ply, modifications) | ||
ply:PS_AddClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:OnHolster(ply) | ||
ply:PS_RemoveClientsideModel(self.ID) | ||
end | ||
|
||
function ITEM:ModifyClientsideModel(ply, model, pos, ang) | ||
model:SetModelScale(0.7, 0) | ||
pos = pos + (ang:Forward() * 2) | ||
ang:RotateAroundAxis(ang:Right(), 20) | ||
|
||
return model, pos, ang | ||
end |
Oops, something went wrong.