mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-02 00:42:29 +00:00
init
This commit is contained in:
472
lua/weapons/train_key/cl_init.lua
Normal file
472
lua/weapons/train_key/cl_init.lua
Normal file
@@ -0,0 +1,472 @@
|
||||
include("shared.lua")
|
||||
|
||||
SWEP.PrintName = "Key"
|
||||
SWEP.Slot = 3
|
||||
SWEP.SlotPos = 2
|
||||
SWEP.DrawAmmo = false
|
||||
SWEP.DrawCrosshair = true
|
||||
|
||||
SWEP.HoldType = "normal"
|
||||
SWEP.ViewModelFOV = 53
|
||||
SWEP.ViewModelFlip = false
|
||||
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
|
||||
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
|
||||
SWEP.ShowViewModel = true
|
||||
SWEP.ShowWorldModel = false
|
||||
SWEP.ViewModelBoneMods = {
|
||||
["ValveBiped.eject"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
|
||||
["ValveBiped.base"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
|
||||
["ValveBiped.muzzle"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
|
||||
["ValveBiped.Bip01_R_Finger12"] = { scale = Vector(1, 1, 1), pos = Vector(-0.172, -1.084, 0), angle = Angle(0, -58.672, 0) },
|
||||
["ValveBiped.square"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
|
||||
["ValveBiped.hammer"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
|
||||
["ValveBiped.clip"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
|
||||
}
|
||||
--Ironsights
|
||||
SWEP.IronSightsPos = Vector(3.64, 0, 2.2)
|
||||
SWEP.IronSightsAng = Vector(0, 0, 0)
|
||||
--ViewModel
|
||||
SWEP.VElements = {
|
||||
["Reverser"] = { type = "Model", model = "models/metrostroi/81-717/reverser.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.93, 1.121, -7.674), angle = Angle(86.043, 163.841, 0), size = Vector(1.7, 1.7, 1.7), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
|
||||
}
|
||||
--WorldModel
|
||||
SWEP.WElements = {
|
||||
["Reverser"] = { type = "Model", model = "models/metrostroi/81-717/reverser.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.177, 1.758, -6.042), angle = Angle(90, 0, 0), size = Vector(1.722, 1.722, 1.722), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
|
||||
}
|
||||
|
||||
|
||||
function SWEP:ResetBonePositions(vm)
|
||||
if (not vm:GetBoneCount()) then return end
|
||||
for i=0, vm:GetBoneCount() do
|
||||
vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
|
||||
vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
|
||||
vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
|
||||
end
|
||||
end
|
||||
function SWEP:Initialize()
|
||||
--self.VElements = table.FullCopy( self.VElements )
|
||||
--self.WElements = table.FullCopy( self.WElements )
|
||||
--self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
|
||||
|
||||
self:CreateModels(self.VElements) --create viewmodels
|
||||
self:CreateModels(self.WElements) --create worldmodels
|
||||
|
||||
if IsValid(self.Owner) then
|
||||
local vm = self.Owner:GetViewModel()
|
||||
if IsValid(vm) then
|
||||
--self:ResetBonePositions(vm)
|
||||
|
||||
if (self.ShowViewModel == nil or self.ShowViewModel) then
|
||||
vm:SetColor(color_white)
|
||||
else
|
||||
vm:SetColor(color_transparent)
|
||||
|
||||
vm:SetMaterial("Debug/hsv")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SWEP:Holster()
|
||||
|
||||
if CLIENT and IsValid(self.Owner) then
|
||||
local vm = self.Owner:GetViewModel()
|
||||
if IsValid(vm) then
|
||||
self:ResetBonePositions(vm)
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function SWEP:OnRemove()
|
||||
self:Holster()
|
||||
end
|
||||
|
||||
SWEP.vRenderOrder = nil
|
||||
function SWEP:ViewModelDrawn()
|
||||
|
||||
local vm = self.Owner:GetViewModel()
|
||||
if not IsValid(vm) then return end
|
||||
|
||||
if (not self.VElements) then return end
|
||||
|
||||
self:UpdateBonePositions(vm)
|
||||
|
||||
if (not self.vRenderOrder) then
|
||||
|
||||
--we build a render order because sprites need to be drawn after models
|
||||
self.vRenderOrder = {}
|
||||
|
||||
for k, v in pairs( self.VElements ) do
|
||||
if (v.type == "Model") then
|
||||
table.insert(self.vRenderOrder, 1, k)
|
||||
elseif (v.type == "Sprite" or v.type == "Quad") then
|
||||
table.insert(self.vRenderOrder, k)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, name in ipairs( self.vRenderOrder ) do
|
||||
|
||||
local v = self.VElements[name]
|
||||
if (not v) then self.vRenderOrder = nil break end
|
||||
if (v.hide) then continue end
|
||||
if not IsValid(v.modelEnt) then
|
||||
self:CreateModels(self.VElements) --create viewmodels
|
||||
end
|
||||
local model = v.modelEnt
|
||||
local sprite = v.spriteMaterial
|
||||
if (not v.bone) then continue end
|
||||
|
||||
local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
|
||||
|
||||
if (not pos) then continue end
|
||||
|
||||
if (v.type == "Model" and IsValid(model)) then
|
||||
|
||||
model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
|
||||
ang:RotateAroundAxis(ang:Up(), v.angle.y)
|
||||
ang:RotateAroundAxis(ang:Right(), v.angle.p)
|
||||
ang:RotateAroundAxis(ang:Forward(), v.angle.r)
|
||||
|
||||
model:SetAngles(ang)
|
||||
--model:SetModelScale(v.size)
|
||||
local matrix = Matrix()
|
||||
matrix:Scale(v.size)
|
||||
model:EnableMatrix( "RenderMultiply", matrix )
|
||||
|
||||
if (v.material == "") then
|
||||
model:SetMaterial("")
|
||||
elseif (model:GetMaterial() ~= v.material) then
|
||||
model:SetMaterial( v.material )
|
||||
end
|
||||
|
||||
if (v.skin and v.skin ~= model:GetSkin()) then
|
||||
model:SetSkin(v.skin)
|
||||
end
|
||||
|
||||
if (v.bodygroup) then
|
||||
for k, v in pairs( v.bodygroup ) do
|
||||
if (model:GetBodygroup(k) ~= v) then
|
||||
model:SetBodygroup(k, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (v.surpresslightning) then
|
||||
render.SuppressEngineLighting(true)
|
||||
end
|
||||
|
||||
render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
|
||||
render.SetBlend(v.color.a/255)
|
||||
model:DrawModel()
|
||||
render.SetBlend(1)
|
||||
render.SetColorModulation(1, 1, 1)
|
||||
|
||||
if (v.surpresslightning) then
|
||||
render.SuppressEngineLighting(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SWEP.wRenderOrder = nil
|
||||
function SWEP:DrawWorldModel()
|
||||
|
||||
if (self.ShowWorldModel == nil or self.ShowWorldModel) then
|
||||
self:DrawModel()
|
||||
end
|
||||
|
||||
if (not self.WElements) then return end
|
||||
|
||||
if (not self.wRenderOrder) then
|
||||
|
||||
self.wRenderOrder = {}
|
||||
|
||||
for k, v in pairs( self.WElements ) do
|
||||
if (v.type == "Model") then
|
||||
table.insert(self.wRenderOrder, 1, k)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if (IsValid(self.Owner)) then
|
||||
bone_ent = self.Owner
|
||||
else
|
||||
--when the weapon is dropped
|
||||
bone_ent = self
|
||||
end
|
||||
|
||||
for k, name in pairs( self.wRenderOrder ) do
|
||||
|
||||
local v = self.WElements[name]
|
||||
if (not v) then self.wRenderOrder = nil break end
|
||||
if (v.hide) then continue end
|
||||
|
||||
local pos, ang
|
||||
|
||||
if (v.bone) then
|
||||
pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
|
||||
else
|
||||
pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
|
||||
end
|
||||
|
||||
if (not pos) then continue end
|
||||
|
||||
if not IsValid(v.modelEnt) then
|
||||
self:CreateModels(self.WElements) --create worldmodels
|
||||
end
|
||||
local model = v.modelEnt
|
||||
local sprite = v.spriteMaterial
|
||||
|
||||
if (v.type == "Model" and IsValid(model)) then
|
||||
|
||||
model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
|
||||
ang:RotateAroundAxis(ang:Up(), v.angle.y)
|
||||
ang:RotateAroundAxis(ang:Right(), v.angle.p)
|
||||
ang:RotateAroundAxis(ang:Forward(), v.angle.r)
|
||||
|
||||
model:SetAngles(ang)
|
||||
--model:SetModelScale(v.size)
|
||||
local matrix = Matrix()
|
||||
matrix:Scale(v.size)
|
||||
model:EnableMatrix( "RenderMultiply", matrix )
|
||||
|
||||
if (v.material == "") then
|
||||
model:SetMaterial("")
|
||||
elseif (model:GetMaterial() ~= v.material) then
|
||||
model:SetMaterial( v.material )
|
||||
end
|
||||
|
||||
if (v.skin and v.skin ~= model:GetSkin()) then
|
||||
model:SetSkin(v.skin)
|
||||
end
|
||||
|
||||
if (v.bodygroup) then
|
||||
for k, v in pairs( v.bodygroup ) do
|
||||
if (model:GetBodygroup(k) ~= v) then
|
||||
model:SetBodygroup(k, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (v.surpresslightning) then
|
||||
render.SuppressEngineLighting(true)
|
||||
end
|
||||
|
||||
render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
|
||||
render.SetBlend(v.color.a/255)
|
||||
model:DrawModel()
|
||||
render.SetBlend(1)
|
||||
render.SetColorModulation(1, 1, 1)
|
||||
|
||||
if (v.surpresslightning) then
|
||||
render.SuppressEngineLighting(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
|
||||
|
||||
local bone, pos, ang
|
||||
if (tab.rel and tab.rel ~= "") then
|
||||
|
||||
local v = basetab[tab.rel]
|
||||
|
||||
if (not v) then return end
|
||||
|
||||
--Technically, if there exists an element with the same name as a bone
|
||||
--you can get in an infinite loop. Let's just hope nobody's that stupid.
|
||||
pos, ang = self:GetBoneOrientation( basetab, v, ent )
|
||||
|
||||
if (not pos) then return end
|
||||
|
||||
pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
|
||||
ang:RotateAroundAxis(ang:Up(), v.angle.y)
|
||||
ang:RotateAroundAxis(ang:Right(), v.angle.p)
|
||||
ang:RotateAroundAxis(ang:Forward(), v.angle.r)
|
||||
|
||||
else
|
||||
|
||||
bone = ent:LookupBone(bone_override or tab.bone)
|
||||
|
||||
if (not bone) then return end
|
||||
|
||||
pos, ang = Vector(0,0,0), Angle(0,0,0)
|
||||
local m = ent:GetBoneMatrix(bone)
|
||||
if (m) then
|
||||
pos, ang = m:GetTranslation(), m:GetAngles()
|
||||
end
|
||||
|
||||
if (IsValid(self.Owner) and self.Owner:IsPlayer() and
|
||||
ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
|
||||
ang.r = -ang.r --Fixes mirrored models
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return pos, ang
|
||||
end
|
||||
|
||||
function SWEP:CreateModels( tab )
|
||||
|
||||
if (not tab) then return end
|
||||
|
||||
--Create the clientside models here because Garry says we can't do it in the render hook
|
||||
for k, v in pairs( tab ) do
|
||||
if (v.type == "Model" and v.model and v.model ~= "" and (not IsValid(v.modelEnt) or v.createdModel ~= v.model) and
|
||||
string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
|
||||
|
||||
v.modelEnt = ents.CreateClientProp("models/metrostroi/81-717/reverser.mdl")
|
||||
v.modelEnt:SetModel(v.model)
|
||||
if (IsValid(v.modelEnt)) then
|
||||
v.modelEnt:SetPos(self:GetPos())
|
||||
v.modelEnt:SetAngles(self:GetAngles())
|
||||
v.modelEnt:SetParent(self)
|
||||
v.modelEnt:SetNoDraw(true)
|
||||
v.createdModel = v.model
|
||||
else
|
||||
v.modelEnt = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local allbones
|
||||
local hasGarryFixedBoneScalingYet = false
|
||||
|
||||
function SWEP:UpdateBonePositions(vm)
|
||||
if (not vm:GetBoneCount()) then return end
|
||||
|
||||
--not not WORKAROUND not not --
|
||||
--We need to check all model names :/
|
||||
local loopthrough = self.ViewModelBoneMods
|
||||
if (not hasGarryFixedBoneScalingYet) then
|
||||
allbones = {}
|
||||
for i=0, vm:GetBoneCount() do
|
||||
local bonename = vm:GetBoneName(i)
|
||||
if (self.ViewModelBoneMods[bonename]) then
|
||||
allbones[bonename] = self.ViewModelBoneMods[bonename]
|
||||
else
|
||||
allbones[bonename] = {
|
||||
scale = Vector(1,1,1),
|
||||
pos = Vector(0,0,0),
|
||||
angle = Angle(0,0,0)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
loopthrough = allbones
|
||||
end
|
||||
--not not ----------- not not --
|
||||
|
||||
for k, v in pairs( loopthrough ) do
|
||||
local bone = vm:LookupBone(k)
|
||||
if (not bone) then continue end
|
||||
|
||||
--not not WORKAROUND not not --
|
||||
local s = Vector(v.scale.x,v.scale.y,v.scale.z)
|
||||
local p = Vector(v.pos.x,v.pos.y,v.pos.z)
|
||||
local ms = Vector(1,1,1)
|
||||
if (not hasGarryFixedBoneScalingYet) then
|
||||
local cur = vm:GetBoneParent(bone)
|
||||
while(cur >= 0) do
|
||||
local pscale = loopthrough[vm:GetBoneName(cur)].scale
|
||||
ms = ms * pscale
|
||||
cur = vm:GetBoneParent(cur)
|
||||
end
|
||||
end
|
||||
|
||||
s = s * ms
|
||||
--not not ----------- not not --
|
||||
|
||||
if vm:GetManipulateBoneScale(bone) ~= s then
|
||||
vm:ManipulateBoneScale( bone, s )
|
||||
end
|
||||
if vm:GetManipulateBoneAngles(bone) ~= v.angle then
|
||||
vm:ManipulateBoneAngles( bone, v.angle )
|
||||
end
|
||||
if vm:GetManipulateBonePosition(bone) ~= p then
|
||||
vm:ManipulateBonePosition( bone, p )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Global utility code
|
||||
|
||||
--Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
|
||||
--Does not copy entities of course, only copies their reference.
|
||||
--WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
|
||||
function table.FullCopy( tab )
|
||||
if (not tab) then return nil end
|
||||
|
||||
local res = {}
|
||||
for k, v in pairs( tab ) do
|
||||
if (type(v) == "table") then
|
||||
res[k] = table.FullCopy(v) --recursion honot
|
||||
elseif (type(v) == "Vector") then
|
||||
res[k] = Vector(v.x, v.y, v.z)
|
||||
elseif (type(v) == "Angle") then
|
||||
res[k] = Angle(v.p, v.y, v.r)
|
||||
else
|
||||
res[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
]]--
|
||||
SWEP.Choosed = 1
|
||||
function SWEP:Precache()
|
||||
end
|
||||
|
||||
function SWEP:Initialize()
|
||||
self:SetWeaponHoldType("melee")
|
||||
end
|
||||
|
||||
function SWEP:Reload()
|
||||
|
||||
end
|
||||
|
||||
function SWEP:PrimaryAttack()
|
||||
if IsFirstTimePredicted() then
|
||||
end
|
||||
self:SetNextPrimaryFire( CurTime() + 10 )
|
||||
end
|
||||
|
||||
function SWEP:SecondaryAttack()
|
||||
--[[
|
||||
if IsFirstTimePredicted() then
|
||||
if LocalPlayer() == self.Owner then
|
||||
self.Choosed = self.Choosed + 1
|
||||
print(self.Choosed)
|
||||
if self.Choosed > #self.Modes then
|
||||
self.Choosed = 1
|
||||
end
|
||||
end
|
||||
self.Weapon:EmitSound("buttons/button17.wav")
|
||||
end
|
||||
]]
|
||||
self:SetNextSecondaryFire( CurTime() + 0.5 )
|
||||
end
|
||||
|
||||
function SWEP:Deploy()
|
||||
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
|
||||
end
|
||||
|
||||
function SWEP:Think()
|
||||
|
||||
end
|
||||
function SWEP:DrawHUD()
|
||||
--draw.SimpleText("Choose mode:","Trebuchet24",ScrW()/2, ScrH()-70,color_white,1)
|
||||
--draw.RoundedBox(3, ScrW()/2 - 180/2, ScrH()-40, 180, 30, Color(25,25,25,255))
|
||||
if self:GetNW2Int("Type") == 1 then
|
||||
draw.SimpleText("You can use this key","Trebuchet24",ScrW()/2, ScrH()-40,color_white,1)
|
||||
end
|
||||
end
|
||||
31
lua/weapons/train_key/init.lua
Normal file
31
lua/weapons/train_key/init.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
AddCSLuaFile( "cl_init.lua" )
|
||||
AddCSLuaFile( "shared.lua" )
|
||||
|
||||
include( "shared.lua" )
|
||||
|
||||
SWEP.Weight = 1
|
||||
SWEP.AutoSwitchTo = false
|
||||
SWEP.AutoSwitchFrom = true
|
||||
|
||||
|
||||
function SWEP:Initialize()
|
||||
end
|
||||
function SWEP:Think()
|
||||
local tr = util.GetPlayerTrace( self.Owner )
|
||||
tr.ignoreworld = true
|
||||
tr.filter = function(ent) if (ent:GetClass() == "func_door" or ent:GetClass() == "func_button") and ent:GetName():find("adminlock") then return true end end
|
||||
local trace = util.TraceLine( tr )
|
||||
if not trace.Hit or not IsValid(trace.Entity) then self:SetNW2Int("Type",0) return end
|
||||
self:SetNW2Int("Type",1)
|
||||
end
|
||||
function SWEP:PrimaryAttack()
|
||||
local tr = util.GetPlayerTrace( self.Owner )
|
||||
tr.ignoreworld = true
|
||||
tr.filter = function(ent) if (ent:GetClass() == "func_door" or ent:GetClass() == "func_button") and ent:GetName():find("adminlock") then return true end end
|
||||
local trace = util.TraceLine( tr )
|
||||
if not trace.Hit or not IsValid(trace.Entity) then return end
|
||||
trace.Entity:Fire("Toggle","","")
|
||||
trace.Entity:Fire("Press","","")
|
||||
|
||||
self:SetNextPrimaryFire( CurTime()+0.5)
|
||||
end
|
||||
23
lua/weapons/train_key/shared.lua
Normal file
23
lua/weapons/train_key/shared.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
--include("shared.lua")
|
||||
--AddCSLuaFile("shared.lua")
|
||||
--AddCSLuaFile("cl_init.lua")
|
||||
SWEP.Author = "glebqip"
|
||||
SWEP.Contact = ""
|
||||
SWEP.Purpose = "Key for use some locked things on map"
|
||||
SWEP.Instructions = "Use key on admin-locked things"
|
||||
SWEP.Spawnable = true
|
||||
SWEP.AdminOnly = true
|
||||
SWEP.Category = "Metrostroi"
|
||||
|
||||
|
||||
SWEP.UseHands = false
|
||||
|
||||
SWEP.Primary.ClipSize = -1
|
||||
SWEP.Primary.DefaultClip = -1
|
||||
SWEP.Primary.Automatic = false
|
||||
SWEP.Primary.Ammo = "none"
|
||||
|
||||
SWEP.Secondary.ClipSize = -1
|
||||
SWEP.Secondary.DefaultClip = -1
|
||||
SWEP.Secondary.Automatic = false
|
||||
SWEP.Secondary.Ammo = "none"
|
||||
Reference in New Issue
Block a user