mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-02 00:42:29 +00:00
init
This commit is contained in:
46
lua/weapons/button_presser/cl_init.lua
Normal file
46
lua/weapons/button_presser/cl_init.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
include("shared.lua")
|
||||
|
||||
SWEP.PrintName = "Button presser"
|
||||
SWEP.Slot = 3
|
||||
SWEP.SlotPos = 2
|
||||
SWEP.DrawAmmo = false
|
||||
SWEP.DrawCrosshair = true
|
||||
|
||||
SWEP.HoldType = "normal"
|
||||
|
||||
|
||||
function SWEP:Holster()
|
||||
return true
|
||||
end
|
||||
|
||||
function SWEP:OnRemove()
|
||||
end
|
||||
|
||||
function SWEP:Initialize()
|
||||
end
|
||||
|
||||
function SWEP:Reload()
|
||||
|
||||
end
|
||||
|
||||
function SWEP:PrimaryAttack()
|
||||
if IsFirstTimePredicted() then
|
||||
end
|
||||
self:SetNextPrimaryFire( CurTime() + 10 )
|
||||
end
|
||||
|
||||
function SWEP:SecondaryAttack()
|
||||
self:SetNextSecondaryFire( CurTime() + 0.5 )
|
||||
end
|
||||
|
||||
function SWEP:Deploy()
|
||||
end
|
||||
|
||||
function SWEP:Think()
|
||||
|
||||
end
|
||||
function SWEP:DrawHUD()
|
||||
if self:GetNW2Int("Type") == 1 then
|
||||
draw.SimpleText("Current button:"..self:GetNW2String("Name","Unknown"),"CloseCaption_Bold",ScrW()/2, 0,Color(127,255,0),1)
|
||||
end
|
||||
end
|
||||
50
lua/weapons/button_presser/init.lua
Normal file
50
lua/weapons/button_presser/init.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
AddCSLuaFile( "cl_init.lua" )
|
||||
AddCSLuaFile( "shared.lua" )
|
||||
|
||||
include( "shared.lua" )
|
||||
|
||||
SWEP.Weight = 1
|
||||
SWEP.PrimAttack = false
|
||||
|
||||
function SWEP:Initialize()
|
||||
end
|
||||
function SWEP:Think()
|
||||
local tr = util.GetPlayerTrace( self.Owner )
|
||||
tr.ignoreworld = true
|
||||
tr.filter = function(ent) if (ent:GetClass() == "func_button" or ent:GetClass() == "momentary_rot_button") and not ent:GetName():find("adminlock") then return true end end
|
||||
|
||||
if self.PrimAttack and IsValid(self.Entity) and self.Entity:GetClass() == "momentary_rot_button" then
|
||||
self.Entity:Fire("Use")
|
||||
end
|
||||
|
||||
if self.PrimAttack ~= self.OldPrimAttack then
|
||||
local trace = util.TraceLine( tr )
|
||||
local rot
|
||||
if IsValid(trace.Entity) then
|
||||
rot = trace.Entity:GetClass() == "momentary_rot_button"
|
||||
end
|
||||
if trace.Hit and rot ~= nil and not IsValid(self.Entity) then
|
||||
self.Entity = trace.Entity
|
||||
if not rot then
|
||||
self.Entity:Fire("Press")
|
||||
end
|
||||
elseif not self.PrimAttack and IsValid(self.Entity) then
|
||||
self.Entity = nil
|
||||
end
|
||||
self.OldPrimAttack = self.PrimAttack
|
||||
end
|
||||
self.PrimAttack = false
|
||||
|
||||
local trace = util.TraceLine( tr )
|
||||
if not trace.Hit or not IsValid(trace.Entity) then
|
||||
self:SetNW2String("Name","")
|
||||
self:SetNW2Int("Type",0)
|
||||
return
|
||||
end
|
||||
self:SetNW2Int("Type",1)
|
||||
self:SetNW2String("Name",trace.Entity:GetName())
|
||||
end
|
||||
function SWEP:PrimaryAttack()
|
||||
self.PrimAttack = true
|
||||
|
||||
end
|
||||
23
lua/weapons/button_presser/shared.lua
Normal file
23
lua/weapons/button_presser/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 = "Button presser"
|
||||
SWEP.Instructions = "Button presser"
|
||||
SWEP.Spawnable = true
|
||||
SWEP.AdminSpawnable = true
|
||||
SWEP.Category = "Metrostroi"
|
||||
|
||||
|
||||
SWEP.UseHands = false
|
||||
|
||||
SWEP.Primary.ClipSize = -1
|
||||
SWEP.Primary.DefaultClip = -1
|
||||
SWEP.Primary.Automatic = true
|
||||
SWEP.Primary.Ammo = ""
|
||||
|
||||
SWEP.Secondary.ClipSize = -1
|
||||
SWEP.Secondary.DefaultClip = -1
|
||||
SWEP.Secondary.Automatic = false
|
||||
SWEP.Secondary.Ammo = "none"
|
||||
1513
lua/weapons/gmod_tool/stools/signalling.lua
Normal file
1513
lua/weapons/gmod_tool/stools/signalling.lua
Normal file
File diff suppressed because it is too large
Load Diff
107
lua/weapons/gmod_tool/stools/switch.lua
Normal file
107
lua/weapons/gmod_tool/stools/switch.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
TOOL.Category = "Metro"
|
||||
TOOL.Name = "Switch Tool"
|
||||
TOOL.Command = nil
|
||||
TOOL.ConfigName = ""
|
||||
if SERVER then util.AddNetworkString "metrostroi-stool-switch" end
|
||||
TOOL.ClientConVar["name"] = ""
|
||||
TOOL.ClientConVar["channel"] = 1
|
||||
TOOL.ClientConVar["locked"] = 0
|
||||
TOOL.ClientConVar["controllable"] = 1
|
||||
TOOL.ClientConVar["invert"] = 0
|
||||
if CLIENT then
|
||||
language.Add("Tool.switch.name", "Switch Tool")
|
||||
language.Add("Tool.switch.desc", "Sets switch tool channel")
|
||||
language.Add("Tool.switch.0", "Primary: Set channel 1\nSecondary: Set channel 2\nReload: Lock switch")
|
||||
end
|
||||
|
||||
function TOOL:LeftClick(trace)
|
||||
if CLIENT then return true end
|
||||
|
||||
local ply = self:GetOwner()
|
||||
if (ply:IsValid()) and (not ply:IsAdmin()) then return false end
|
||||
if not trace then return false end
|
||||
if trace.Entity and trace.Entity:IsPlayer() then return false end
|
||||
|
||||
local entlist = ents.FindInSphere(trace.HitPos,64)
|
||||
for k,v in pairs(entlist) do
|
||||
if v:GetClass() == "gmod_track_switch" then
|
||||
v.Name = self:GetClientInfo("name") ~= "" and self:GetClientInfo("name") or nil
|
||||
v:SetChannel(self:GetClientNumber("channel"))
|
||||
v.LockedSignal = self:GetClientNumber("lock") == 1 and self:GetClientNumber("channel") or nil
|
||||
v.NotChangePos = self:GetClientNumber("controllable") == 0
|
||||
v.Invertred = self:GetClientNumber("invert") == 1
|
||||
print(Format("Name:%s, Channel:%d, It's %slocked, %scontrllable and %sinverted",self:GetClientInfo("name") ~= "" and self:GetClientInfo("name") or "track index",self:GetClientNumber("channel"),self:GetClientNumber("lock") == 1 and "not " or "",self:GetClientNumber("controllable") == 0 and "not " or "",self:GetClientNumber("invert") == 0 and "not " or ""))
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function TOOL:RightClick(trace)
|
||||
if CLIENT then return true end
|
||||
--[[
|
||||
local ply = self:GetOwner()
|
||||
if (ply:IsValid()) and (not ply:IsAdmin()) then return false end
|
||||
if not trace then return false end
|
||||
if trace.Entity and trace.Entity:IsPlayer() then return false end
|
||||
|
||||
local entlist = ents.FindInSphere(trace.HitPos,64)
|
||||
for k,v in pairs(entlist) do
|
||||
if v:GetClass() == "gmod_track_switch" then
|
||||
v:SetChannel(2)
|
||||
print("Set channel 2")
|
||||
end
|
||||
end]]
|
||||
return true
|
||||
end
|
||||
|
||||
function TOOL:Reload(trace)
|
||||
if CLIENT then return true end
|
||||
|
||||
local ply = self:GetOwner()
|
||||
if (ply:IsValid()) and (not ply:IsAdmin()) then return false end
|
||||
if not trace then return false end
|
||||
if trace.Entity and trace.Entity:IsPlayer() then return false end
|
||||
|
||||
local entlist = ents.FindInSphere(trace.HitPos,64)
|
||||
for k,v in pairs(entlist) do
|
||||
if v:GetClass() == "gmod_track_switch" then
|
||||
net.Start("metrostroi-stool-switch")
|
||||
net.WriteString(v.Name or "")
|
||||
net.WriteUInt(v:GetChannel(),2)
|
||||
net.WriteBool(v.LockedSignal)
|
||||
net.WriteBool(not v.NotChangePos)
|
||||
net.WriteBool(v.Invertred)
|
||||
net.Send(self:GetOwner())
|
||||
|
||||
--if self:GetClientNumber("lock") == 1 then
|
||||
--if v.LockedSignal then v.LockedSignal = nil else v.LockedSignal = v.LastSignal end
|
||||
--print("Locked switch signal",v.LockedSignal)
|
||||
--else
|
||||
--not v.NotChangePos
|
||||
--print(v.NotChangePos and "Disabled" or "Enabled")
|
||||
--end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function TOOL.BuildCPanel(panel)
|
||||
panel = panel or controlpanel.Get("switch")
|
||||
panel:AddControl("Header", { Text = "#Tool.switch.name", Description = "#Tool.switch.desc" })
|
||||
panel:AddControl("TextBox", { Label = "Name", Command = "switch_name" })
|
||||
panel:AddControl("ComboBox", { Label = "Channel", Options = {None={switch_channel = 0},["1"] ={switch_channel = 1},["2"] ={switch_channel = 2}}})
|
||||
panel:AddControl("Checkbox", { Label = "Locked", Command = "switch_locked" })
|
||||
panel:AddControl("Checkbox", { Label = "Controllable", Command = "switch_controllable" })
|
||||
panel:AddControl("Checkbox", { Label = "Invert", Command = "switch_invert" })
|
||||
end
|
||||
|
||||
|
||||
net.Receive("metrostroi-stool-switch", function(_, ply)
|
||||
local TOOL = LocalPlayer and LocalPlayer():GetTool("signalling") or ply:GetTool("signalling")
|
||||
|
||||
RunConsoleCommand("switch_name",net.ReadString())
|
||||
RunConsoleCommand("switch_channel",net.ReadUInt(2))
|
||||
RunConsoleCommand("switch_locked",net.ReadBool() and 1 or 0)
|
||||
RunConsoleCommand("switch_controllable",net.ReadBool() and 1 or 0)
|
||||
RunConsoleCommand("switch_invert",net.ReadBool() and 1 or 0)
|
||||
end)
|
||||
518
lua/weapons/gmod_tool/stools/train_spawner.lua
Normal file
518
lua/weapons/gmod_tool/stools/train_spawner.lua
Normal file
@@ -0,0 +1,518 @@
|
||||
|
||||
--local TOOL = player.GetBySteamID("STEAM_0:1:31566374"):GetTool("train_spawner")
|
||||
TOOL.AddToMenu = false
|
||||
|
||||
if CLIENT then
|
||||
language.Add("Tool.train_spawner.name", "Train Spawner")
|
||||
language.Add("Tool.train_spawner.desc", "Spawn a train")
|
||||
language.Add("Tool.train_spawner.0", "Primary: Spawns a full train. Secondary: Reverse facing (yellow ed when facing the opposite side).")
|
||||
language.Add("Undone_81-7036", "Undone 81-7036 (does not work)")
|
||||
language.Add("Undone_81-7037", "Undone 81-7037 (does not work)")
|
||||
language.Add("Undone_81-717", "Undone 81-717")
|
||||
language.Add("Undone_81-714", "Undone 81-714")
|
||||
language.Add("Undone_Ezh3", "Undone Ezh3")
|
||||
language.Add("Undone_Ema508T", "Undone Em508T")
|
||||
language.Add("SBoxLimit_spawner_wrong_pos","Wrong train position! Can't spawn")
|
||||
language.Add("SBoxLimit_spawner_restrict","This train is restricted for you")
|
||||
end
|
||||
|
||||
local function Trace(ply,tr)
|
||||
local verticaloffset = 5 -- Offset for the train model
|
||||
local distancecap = 2000 -- When to ignore hitpos and spawn at set distanace
|
||||
local pos, ang = nil
|
||||
local inhibitrerail = false
|
||||
|
||||
--TODO: Make this work better for raw base ent
|
||||
|
||||
if tr.Hit then
|
||||
-- Setup trace to find out of this is a track
|
||||
local tracesetup = {}
|
||||
tracesetup.start=tr.HitPos
|
||||
tracesetup.endpos=tr.HitPos+tr.HitNormal*80
|
||||
tracesetup.filter=ply
|
||||
|
||||
local tracedata = util.TraceLine(tracesetup)
|
||||
|
||||
if tracedata.Hit then
|
||||
-- Trackspawn
|
||||
pos = (tr.HitPos + tracedata.HitPos)/2 + Vector(0,0,verticaloffset)
|
||||
ang = tracedata.HitNormal
|
||||
ang:Rotate(Angle(0,90,0))
|
||||
ang = ang:Angle()
|
||||
-- Bit ugly because Rotate() messes with the orthogonal vector | Orthogonal? I wrote "origional?!" :V
|
||||
else
|
||||
-- Regular spawn
|
||||
if tr.HitPos:Distance(tr.StartPos) > distancecap then
|
||||
-- Spawnpos is far away, put it at distancecap instead
|
||||
pos = tr.StartPos + tr.Normal * distancecap
|
||||
inhibitrerail = true
|
||||
else
|
||||
-- Spawn is near
|
||||
pos = tr.HitPos + tr.HitNormal * verticaloffset
|
||||
end
|
||||
ang = Angle(0,tr.Normal:Angle().y,0)
|
||||
end
|
||||
else
|
||||
-- Trace didn't hit anything, spawn at distancecap
|
||||
pos = tr.StartPos + tr.Normal * distancecap
|
||||
ang = Angle(0,tr.Normal:Angle().y,0)
|
||||
end
|
||||
return {pos,ang,inhibitrerail}
|
||||
end
|
||||
|
||||
function UpdateGhostPos(pl)
|
||||
local trace = util.TraceLine(util.GetPlayerTrace(pl))
|
||||
local tbl = Metrostroi.RerailGetTrackData(trace.HitPos,pl:GetAimVector())
|
||||
|
||||
if not tbl then tbl = Trace(pl, trace) end
|
||||
local class = IsValid(trace.Entity) and trace.Entity:GetClass()
|
||||
|
||||
local pos,ang = Vector(0,0,0),Angle(0,0,0)
|
||||
if tbl[3] ~= nil then
|
||||
pos = tbl[1]+Vector(0,0,55)
|
||||
ang = tbl[2]
|
||||
return pos,ang,false,not class or (class == "func_door" or class == "prop_door_rotating")
|
||||
else
|
||||
pos = tbl.centerpos + Vector(0,0,112)
|
||||
ang = tbl.right:Angle()+Angle(0,90,0)
|
||||
return pos,ang,true,not class or (class == "func_door" or class == "prop_door_rotating")
|
||||
end
|
||||
end
|
||||
|
||||
function UpdateWagPos(pl)
|
||||
local trace = util.TraceLine(util.GetPlayerTrace(pl))
|
||||
local tbl = Metrostroi.RerailGetTrackData(trace.HitPos,pl:GetAimVector())
|
||||
|
||||
if not tbl then tbl = Trace(pl, trace) end
|
||||
local pos,ang = Vector(0,0,0),Angle(0,0,0)
|
||||
if tbl[3] ~= nil then
|
||||
pos = tbl[1]
|
||||
ang = tbl[2]
|
||||
return pos,ang,false
|
||||
else
|
||||
pos = tbl.centerpos + Vector(0,0,112-55)
|
||||
ang = tbl.right:Angle()+Angle(0,90,0)
|
||||
return pos,ang,true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function TOOL:UpdateGhost()
|
||||
local good,canDraw
|
||||
for i,e in ipairs(self.GhostEntities) do
|
||||
local t = self.Model[i]
|
||||
local pos,ang
|
||||
if i==1 then
|
||||
pos,ang,good,canDraw = UpdateGhostPos(self:GetOwner())
|
||||
if self:GetOwner():GetNW2Bool("metrostroi_train_spawner_rev") then
|
||||
ang = ang+Angle(0,180,0)
|
||||
end
|
||||
elseif type(t) ~= "string" then
|
||||
pos,ang = self.GhostEntities[1]:LocalToWorld(t.pos or Vector(0,0,0)),self.GhostEntities[1]:LocalToWorldAngles(self.Model[i].ang or Angle(0,0,0))
|
||||
else
|
||||
pos,ang = self.GhostEntities[1]:GetPos(),self.GhostEntities[1]:GetAngles()
|
||||
end
|
||||
e:SetNoDraw(not canDraw)
|
||||
--if not pos then bad = true else pos,ang = rpos,rang end
|
||||
if not good then
|
||||
e:SetColor(Color(255,150,150,255))
|
||||
elseif self:GetOwner():GetNW2Bool("metrostroi_train_spawner_rev") then
|
||||
e:SetColor(Color(255,255,150,255))
|
||||
else
|
||||
e:SetColor(Color(255,255,255,255))
|
||||
end
|
||||
e:SetPos(pos)
|
||||
e:SetAngles(ang)
|
||||
end
|
||||
end
|
||||
|
||||
function TOOL:Holster()
|
||||
if not IsFirstTimePredicted() or SERVER then return end
|
||||
end
|
||||
|
||||
--local owner
|
||||
function TOOL:Think()
|
||||
if not self.Train then return end
|
||||
--owner = self:GetOwner()
|
||||
--self.tbl = self:GetConvar()
|
||||
--self.int = self.tbl.Prom > 0 or !Trains[self.tbl.Train][1]:find("Ezh3")
|
||||
if CLIENT and self.Train.Spawner.model then
|
||||
if not self.GhostEntities then self.GhostEntities = {} end
|
||||
if not IsValid(self.GhostEntities[1]) or self.Model ~= self.Train.Spawner.model then
|
||||
self.Model = self.Train.Spawner.model
|
||||
for _,e in pairs(self.GhostEntities) do SafeRemoveEntity(e) end
|
||||
self.GhostEntities = {}
|
||||
if type(self.Model) == "string" then
|
||||
self.GhostEntities[1] = ClientsideModel(self.Model,RENDERGROUP_OPAQUE)
|
||||
self.GhostEntities[1]:SetModel(self.Model)
|
||||
else
|
||||
for i,t in pairs(self.Model) do
|
||||
if type(t) == "string" then
|
||||
self.GhostEntities[i] = ClientsideModel(t,RENDERGROUP_OPAQUE)
|
||||
self.GhostEntities[i]:SetModel(t)
|
||||
else
|
||||
self.GhostEntities[i] = ClientsideModel(t[1],RENDERGROUP_OPAQUE)
|
||||
self.GhostEntities[i]:SetModel(t[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
for i,e in pairs(self.GhostEntities) do
|
||||
e:SetRenderMode(RENDERMODE_TRANSALPHA)
|
||||
e.GetBodyColor = function() return Vector(1,1,1) end
|
||||
e.GetDirtLevel = function() return 0.25 end
|
||||
end
|
||||
hook.Add("Think",self.GhostEntities[1],function()
|
||||
if not IsValid(self.Owner:GetActiveWeapon()) or self.Owner:GetActiveWeapon():GetClass()~="gmod_tool" or GetConVarString("gmod_toolmode") ~= "train_spawner" then
|
||||
self:OnRemove()
|
||||
end
|
||||
end)
|
||||
|
||||
local oldOR = self.GhostEntities[1].OnRemove
|
||||
self.GhostEntities[1].OnRemove = function(ent)
|
||||
hook.Remove("Think",ent)
|
||||
oldOR(ent)
|
||||
end
|
||||
else
|
||||
self:UpdateGhost()
|
||||
end
|
||||
end
|
||||
---if SERVER then self.Rev = self.Rev end
|
||||
end
|
||||
|
||||
function TOOL:SetSettings(ent, ply, i,inth)
|
||||
local rot = false
|
||||
if i > 1 then
|
||||
rot = i == self.tbl.WagNum and true or math.random() > 0.5
|
||||
end
|
||||
end
|
||||
|
||||
local function SetValue(ent,id,val)
|
||||
if type(val) == "number" then
|
||||
ent:SetNW2Int(id,val)
|
||||
elseif type(val) == "string" then
|
||||
ent:SetNW2String(id,val)
|
||||
elseif type(val) == "boolean" then
|
||||
ent:SetNW2Bool(id,val)
|
||||
end
|
||||
end
|
||||
|
||||
function TOOL:SpawnWagon(trace)
|
||||
if CLIENT then return end
|
||||
local ply = self:GetOwner()
|
||||
|
||||
local FIXFIXFIX = {}
|
||||
for i=1,math.random(12) do
|
||||
FIXFIXFIX[i] = ents.Create("env_sprite")
|
||||
FIXFIXFIX[i]:Spawn()
|
||||
end
|
||||
|
||||
local LastRot,LastEnt = false
|
||||
local trains = {}
|
||||
for i=1,self.Settings.WagNum do
|
||||
local spawnfunc = self.Train.Spawner.spawnfunc
|
||||
local ent
|
||||
if i == 1 then
|
||||
if spawnfunc then
|
||||
ent = self.Train:SpawnFunction(ply,trace,spawnfunc(i,self.Settings,self.Train),self:GetOwner():GetNW2Bool("metrostroi_train_spawner_rev"),UpdateWagPos)
|
||||
else
|
||||
ent = self.Train:SpawnFunction(ply,trace,self.Train.Spawner.head or self.Train.ClassName,self:GetOwner():GetNW2Bool("metrostroi_train_spawner_rev"),UpdateWagPos)
|
||||
end
|
||||
--nil,self:GetOwner():GetNW2Bool("metrostroi_train_spawner_rev") and Angle(0,180,0) or Angle(0,0,0)) --Create a first entity in queue
|
||||
if ent then
|
||||
undo.Create(self.Train.Spawner.head or self.Train.ClassName)
|
||||
else
|
||||
self:GetOwner():LimitHit("spawner_wrong_pos")
|
||||
return false
|
||||
end
|
||||
--if self:GetOwner():GetNW2Bool("metrostroi_train_spawner_rev") then
|
||||
--ent:SetAngles(ent:LocalToWorldAngles(Angle(0,180,0)))
|
||||
--end
|
||||
--if self.Rot then
|
||||
end
|
||||
if i > 1 then
|
||||
local rot = (i==self.Settings.WagNum or math.random() > 0.5) -- Rotate last wagon or rotate it randomly
|
||||
if spawnfunc then
|
||||
ent = ents.Create(spawnfunc(i,self.Settings,self.Train))
|
||||
else
|
||||
ent = ents.Create(i~=self.Settings.WagNum and self.Train.Spawner.interim or self.Train.Spawner.head or self.Train.ClassName)
|
||||
end
|
||||
ent.Owner = ply
|
||||
ent:Spawn()
|
||||
-- Invert bogeys by rotation
|
||||
local bogeyL1,bogeyE1,bogeyE2
|
||||
local couplL1,couplE1,couplE2
|
||||
if LastRot then
|
||||
bogeyL1 = LastEnt.FrontBogey
|
||||
couplL1 = LastEnt.FrontCouple
|
||||
else
|
||||
bogeyL1 = LastEnt.RearBogey
|
||||
couplL1 = LastEnt.RearCouple
|
||||
end
|
||||
if rot then
|
||||
bogeyE1,bogeyE2 = ent.RearBogey,ent.FrontBogey
|
||||
couplE1,couplE2 = ent.FrontCouple,ent.RearCouple
|
||||
else
|
||||
bogeyE1,bogeyE2 = ent.FrontBogey,ent.RearBogey
|
||||
couplE1,couplE2 = ent.RearCouple,ent.FrontCouple
|
||||
end
|
||||
local haveCoupler = couplL1 ~= nil
|
||||
if haveCoupler then
|
||||
bogeyE1:SetAngles(ent:LocalToWorldAngles(bogeyE1.SpawnAng))
|
||||
bogeyE2:SetAngles(ent:LocalToWorldAngles(bogeyE1.SpawnAng))
|
||||
-- Set bogey position by our bogey couple offset and lastent bogey couple offset
|
||||
couplE1:SetPos(
|
||||
couplL1:LocalToWorld(
|
||||
Vector(
|
||||
couplL1.CouplingPointOffset.x*1.1+couplE1.CouplingPointOffset.x*1.1,
|
||||
couplL1.CouplingPointOffset.y-couplE1.CouplingPointOffset.y,
|
||||
couplL1.CouplingPointOffset.z-couplE1.CouplingPointOffset.z
|
||||
)
|
||||
)
|
||||
)
|
||||
-- Set bogey angles
|
||||
couplE1:SetAngles(couplL1:LocalToWorldAngles(Angle(0,180,0)))
|
||||
-- Set entity position by bogey pos and bogey offset
|
||||
couplE2:SetAngles(couplE1:LocalToWorldAngles(Angle(0,180,0)))
|
||||
ent:SetPos(couplE1:LocalToWorld(couplE1.SpawnPos*Vector(rot and -1 or 1,-1,-1)))
|
||||
-- Set entity angles by last ent and rotation
|
||||
ent:SetAngles(LastEnt:LocalToWorldAngles(Angle(0,rot ~= LastRot and 180 or 0,0)))
|
||||
|
||||
-- Set bogey pos
|
||||
bogeyE1:SetPos(ent:LocalToWorld(bogeyE1.SpawnPos))
|
||||
bogeyE2:SetPos(ent:LocalToWorld(bogeyE2.SpawnPos))
|
||||
-- Set bogey angles
|
||||
bogeyE1:SetAngles(ent:LocalToWorldAngles(bogeyE1.SpawnAng))
|
||||
bogeyE2:SetAngles(ent:LocalToWorldAngles(bogeyE1.SpawnAng))
|
||||
else
|
||||
-- Set bogey position by our bogey couple offset and lastent bogey couple offset
|
||||
bogeyE1:SetPos(
|
||||
bogeyL1:LocalToWorld(
|
||||
Vector(bogeyL1.CouplingPointOffset.x*1.1+bogeyE1.CouplingPointOffset.x*1.05,bogeyL1.CouplingPointOffset.y-bogeyE1.CouplingPointOffset.y,bogeyL1.CouplingPointOffset.z-bogeyE1.CouplingPointOffset.z)
|
||||
)
|
||||
)
|
||||
-- Set bogey angles
|
||||
bogeyE1:SetAngles(bogeyL1:LocalToWorldAngles(Angle(0,180,0)))
|
||||
-- Set entity position by bogey pos and bogey offset
|
||||
bogeyE2:SetAngles(bogeyE1:LocalToWorldAngles(Angle(0,180,0)))
|
||||
ent:SetPos(bogeyE1:LocalToWorld(bogeyE1.SpawnPos*Vector(rot and -1 or 1,-1,-1)))
|
||||
-- Set entity angles by last ent and rotation
|
||||
ent:SetAngles(LastEnt:LocalToWorldAngles(Angle(0,rot ~= LastRot and 180 or 0,0)))
|
||||
-- Set second bogey pos
|
||||
bogeyE2:SetPos(ent:LocalToWorld(bogeyE2.SpawnPos))
|
||||
end
|
||||
|
||||
Metrostroi.RerailTrain(ent) --Rerail train
|
||||
--LastEnt:LocalToWorld(bogeyL1:WorldToLocal(Vector))))
|
||||
|
||||
LastRot = rot
|
||||
end
|
||||
table.insert(trains,ent)
|
||||
undo.AddEntity(ent)
|
||||
--[[
|
||||
ent:SetMoveType(MOVETYPE_NONE)
|
||||
ent.FrontBogey:SetMoveType(MOVETYPE_NONE)
|
||||
ent.RearBogey:SetMoveType(MOVETYPE_NONE)
|
||||
if IsValid(ent.FrontCouple) then
|
||||
ent.FrontCouple:SetMoveType(MOVETYPE_NONE)
|
||||
ent.RearCouple:SetMoveType(MOVETYPE_NONE)
|
||||
end]]
|
||||
|
||||
for _, set in ipairs(self.Train.Spawner) do
|
||||
local val = self.Settings[set[1]]
|
||||
if set[3] == "List" then
|
||||
if set[6] and type(set[6]) == "function" then set[6](ent,val,LastRot,i,self.Settings.WagNum) else SetValue(ent,set[1],val) end
|
||||
elseif set[3] == "Boolean" then
|
||||
if set[5] and type(set[5]) == "function" then set[5](ent,val,LastRot,i,self.Settings.WagNum) else ent:SetNW2Bool(set[1],val) end
|
||||
elseif set[3] == "Slider" then
|
||||
if set[8] and type(set[8]) == "function" then set[8](ent,val,LastRot,i,self.Settings.WagNum) else ent:SetNW2Int(set[1],val) end
|
||||
end
|
||||
end
|
||||
if self.Train.Spawner.func then self.Train.Spawner.func(ent,i,self.Settings.WagNum,LastRot) end
|
||||
if self.Train.Spawner.wagfunc then ent:GenerateWagonNumber(function(_,number) return self.Train.Spawner.wagfunc(ent,i,number) end) end
|
||||
if ent.TrainSpawnerUpdate then ent:TrainSpawnerUpdate() end
|
||||
for k,v in pairs(ent.CustomSpawnerUpdates) do if k ~= "BaseClass" then v(ent) end end
|
||||
hook.Run("MetrostroiSpawnerUpdate",ent,self.Settings)
|
||||
ent:UpdateTextures()
|
||||
ent.FrontAutoCouple = i > 1 and i < self.Settings.WagNum
|
||||
ent.RearAutoCouple = true
|
||||
LastEnt = ent
|
||||
end
|
||||
undo.SetPlayer(ply)
|
||||
undo.SetCustomUndoText("Undone a train")
|
||||
undo.Finish()
|
||||
if self.Train.Spawner.postfunc then self.Train.Spawner.postfunc(trains,self.Settings.WagNum) end
|
||||
--if self.Settings.AutoCouple and #trains > 1 then
|
||||
local CoupledTrains,WagNum = 0,self.Settings.WagNum
|
||||
local function StopCoupling()
|
||||
if not IsValid(trains[1]) or not trains[1].IgnoreEngine then return end
|
||||
for _,train in ipairs(trains) do
|
||||
train.FrontBogey.BrakeCylinderPressure = 3
|
||||
train.RearBogey.BrakeCylinderPressure = 3
|
||||
train.FrontBogey.MotorPower = 0
|
||||
train.RearBogey.MotorPower = 0
|
||||
train.OnCoupled = nil
|
||||
end
|
||||
timer.Simple(1,function() for i,train in ipairs(trains) do train.IgnoreEngine = false end end)
|
||||
end
|
||||
for i,train in ipairs(trains) do
|
||||
train.IgnoreEngine = true
|
||||
train.RearBogey.MotorForce = 40000
|
||||
train.FrontBogey.MotorForce = 40000
|
||||
train.RearBogey.PneumaticBrakeForce = 50000
|
||||
train.FrontBogey.PneumaticBrakeForce = 50000
|
||||
if i==#trains then
|
||||
train.RearBogey.MotorPower = 1
|
||||
train.FrontBogey.MotorPower = 0
|
||||
else
|
||||
train.RearBogey.MotorPower = 0
|
||||
train.FrontBogey.MotorPower = 0
|
||||
end
|
||||
if i==1 then
|
||||
train.FrontBogey.BrakeCylinderPressure = 3
|
||||
train.RearBogey.BrakeCylinderPressure = 3
|
||||
else
|
||||
train.FrontBogey.BrakeCylinderPressure = 0
|
||||
train.RearBogey.BrakeCylinderPressure = 0
|
||||
end
|
||||
train.OnCoupled = function(ent)
|
||||
CoupledTrains = CoupledTrains + 0.5
|
||||
if CoupledTrains==WagNum-1 then StopCoupling() end
|
||||
end
|
||||
end
|
||||
timer.Simple(3+1*#trains,StopCoupling)
|
||||
--end
|
||||
--self.rot = false
|
||||
for k,v in pairs(FIXFIXFIX) do SafeRemoveEntity(v) end
|
||||
end
|
||||
|
||||
function TOOL:OnRemove()
|
||||
self:Finish()
|
||||
end
|
||||
function TOOL:Finish()
|
||||
for _,e in pairs(self.GhostEntities) do SafeRemoveEntity(e) end
|
||||
self.GhostEntities = {}
|
||||
end
|
||||
|
||||
function TOOL:Reload(trace)
|
||||
if CLIENT then return end
|
||||
local spawner = ents.Create("gmod_train_spawner")
|
||||
spawner:SpawnFunction(self:GetOwner())
|
||||
end
|
||||
function TOOL:LeftClick(trace)
|
||||
if not self.Train then return end
|
||||
local class = IsValid(trace.Entity) and trace.Entity:GetClass()
|
||||
if class and (trace.Entity.Spawner or class ~= "func_door" and class ~= "prop_door_rotating") then
|
||||
if SERVER then
|
||||
if trace.Entity.ClassName == (self.Train.Spawner.head or self.Train.ClassName) or trace.Entity.ClassName == self.Train.Spawner.interim then
|
||||
local LastEnt
|
||||
local trains = {}
|
||||
for k,ent in ipairs(trace.Entity.WagonList) do
|
||||
--[[
|
||||
local rot = ent.RearTrain and ent.RearTrain.FrontTrain == ent or ent.FrontTrain and ent.FrontTrain.RearTrain == ent
|
||||
if not LastRot then
|
||||
rot = ent.RearTrain and ent.RearTrain.RearTrain == ent or ent.FrontTrain and ent.FrontTrain.FrontTrain == ent
|
||||
end]]
|
||||
local rot = ent.RearTrain == LastEnt
|
||||
LastEnt = ent
|
||||
for i, set in ipairs(self.Train.Spawner) do
|
||||
local val = self.Settings[set[1]]
|
||||
if set[3] == "List" then
|
||||
if set[6] and type(set[6]) == "function" then set[6](ent,val,rot,k,self.Settings.WagNum) else SetValue(ent,set[1],val) end
|
||||
elseif set[3] == "Boolean" then
|
||||
if set[5] and type(set[5]) == "function" then set[5](ent,val,rot,k,self.Settings.WagNum) else ent:SetNW2Bool(set[1],val) end
|
||||
elseif set[3] == "Slider" then
|
||||
if set[8] and type(set[8]) == "function" then set[8](ent,val,rot,k,self.Settings.WagNum) else ent:SetNW2Int(set[1],val) end
|
||||
end
|
||||
end
|
||||
if self.Train.Spawner.func then self.Train.Spawner.func(ent,k,self.Settings.WagNum,rot) end
|
||||
ent:GenerateWagonNumber(self.Train.Spawner.wagfunc)
|
||||
if ent.TrainSpawnerUpdate then ent:TrainSpawnerUpdate() end
|
||||
for k,v in pairs(ent.CustomSpawnerUpdates) do if k ~= "BaseClass" then v(ent) end end
|
||||
hook.Run("MetrostroiSpawnerUpdate",ent,self.Settings)
|
||||
ent:UpdateTextures()
|
||||
table.insert(trains,ent)
|
||||
|
||||
end
|
||||
if self.Train.Spawner.postfunc then self.Train.Spawner.postfunc(trains,self.Settings.WagNum) end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
if not self.AllowSpawn or not self.Train then return end
|
||||
if SERVER then
|
||||
if self.Settings.WagNum > GetConVarNumber("metrostroi_maxwagons") then
|
||||
self.Settings.WagNum = GetConVarNumber("metrostroi_maxwagons")
|
||||
end
|
||||
|
||||
if Metrostroi.TrainCountOnPlayer(self:GetOwner()) + self.Settings.WagNum > GetConVarNumber("metrostroi_maxtrains_onplayer")*GetConVarNumber("metrostroi_maxwagons")
|
||||
or Metrostroi.TrainCount() + self.Settings.WagNum > GetConVarNumber("metrostroi_maxtrains")*GetConVarNumber("metrostroi_maxwagons") then
|
||||
self:GetOwner():LimitHit("train_limit")
|
||||
return true
|
||||
end
|
||||
if hook.Run("MetrostroiSpawnerRestrict",self:GetOwner(),self.Settings) then
|
||||
self:GetOwner():LimitHit("spawner_restrict")
|
||||
return true
|
||||
end
|
||||
end
|
||||
self:SpawnWagon(trace)
|
||||
return
|
||||
end
|
||||
|
||||
function TOOL:RightClick(trace)
|
||||
if not self.Train then return end
|
||||
if IsValid(trace.Entity) then
|
||||
if SERVER then
|
||||
if trace.Entity.ClassName == (self.Train.Spawner.head or self.Train.ClassName) or trace.Entity.ClassName == self.Train.Spawner.interim then
|
||||
local LastEnt
|
||||
local trains = {}
|
||||
for k,ent in pairs(trace.Entity.WagonList) do
|
||||
local rot = ent.RearTrain == LastEnt
|
||||
LastEnt = ent
|
||||
if ent ~= trace.Entity then continue end
|
||||
for i, set in ipairs(self.Train.Spawner) do
|
||||
local val = self.Settings[set[1]]
|
||||
if set[3] == "List" then
|
||||
if set[6] and type(set[6]) == "function" then set[6](ent,val,rot,k,self.Settings.WagNum,true) else SetValue(ent,set[1],val) end
|
||||
elseif set[3] == "Boolean" then
|
||||
if set[5] and type(set[5]) == "function" then set[5](ent,val,rot,k,self.Settings.WagNum,true) else ent:SetNW2Bool(set[1],val) end
|
||||
elseif set[3] == "Slider" then
|
||||
if set[8] and type(set[8]) == "function" then set[8](ent,val,rot,k,self.Settings.WagNum,true) else ent:SetNW2Int(set[1],val) end
|
||||
end
|
||||
end
|
||||
if self.Train.Spawner.func then self.Train.Spawner.func(ent,k,self.Settings.WagNum,rot) end
|
||||
ent:GenerateWagonNumber(self.Train.Spawner.wagfunc)
|
||||
if ent.TrainSpawnerUpdate then ent:TrainSpawnerUpdate() end
|
||||
for k,v in pairs(ent.CustomSpawnerUpdates) do if k ~= "BaseClass" then v(ent) end end
|
||||
hook.Run("MetrostroiSpawnerUpdate",ent,self.Settings)
|
||||
ent:UpdateTextures()
|
||||
table.insert(trains,ent)
|
||||
if self.Train.Spawner.postfunc then self.Train.Spawner.postfunc(trains,self.Settings.WagNum) end
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
if not self.AllowSpawn or not self.Train then return end
|
||||
if CLIENT then return end
|
||||
self.Rev = not self.Rev
|
||||
self:GetOwner():SetNW2Bool("metrostroi_train_spawner_rev",self.Rev)
|
||||
|
||||
end
|
||||
|
||||
function TOOL.BuildCPanel(panel)
|
||||
panel:AddControl("Header", { Text = "#Tool.train_spawner.name", Description = "#Tool.train_spawner.desc" })
|
||||
end
|
||||
|
||||
if SERVER then
|
||||
util.AddNetworkString "train_spawner_open"
|
||||
net.Receive("train_spawner_open",function(len,ply)
|
||||
ply:ConCommand("gmod_tool train_spawner")
|
||||
ply:SelectWeapon("gmod_tool")
|
||||
local tool = ply:GetTool("train_spawner")
|
||||
tool.AllowSpawn = true
|
||||
tool.Settings = net.ReadTable()
|
||||
local ENT = scripted_ents.Get(tool.Settings.Train)
|
||||
if not ENT then tool.AllowSpawn = false else tool.Train = ENT end
|
||||
end)
|
||||
return
|
||||
end
|
||||
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"
|
||||
524
lua/weapons/train_kv_wrench/cl_init.lua
Normal file
524
lua/weapons/train_kv_wrench/cl_init.lua
Normal file
@@ -0,0 +1,524 @@
|
||||
include("shared.lua")
|
||||
|
||||
SWEP.PrintName = "Train Reverser Wrench"
|
||||
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_train/reversor/reversor_classic.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.93, 1.421, -7), angle = Angle(-4, 96, -95), size = Vector(1.1, 1.1, 1.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
|
||||
}
|
||||
SWEP.VDigits = {
|
||||
Vector(0.3,-4.25-0.65+(-1)*0.3,0.9+0+0*0.005),
|
||||
Vector(0.3,-4.25-0.65+(-0)*0.3,0.9+0+1*0.005),
|
||||
Vector(0.3,-4.25-0.65+( 1)*0.3,0.9+0+2*0.005),
|
||||
Vector(0.3,-4.25-0.65+( 2)*0.3,0.9+0+3*0.005),
|
||||
Vector(0.3,-4.25-0.65+( 3)*0.3,0.9+0+4*0.005),
|
||||
}
|
||||
for i,v in pairs(SWEP.VDigits) do
|
||||
local reverser = SWEP.VElements.Reverser
|
||||
local pos,ang = LocalToWorld(v,Angle(0,-91,-91),reverser.pos,reverser.angle)
|
||||
SWEP.VElements["Digit"..i] = {
|
||||
type = "Model",
|
||||
model = "models/metrostroi_train/reversor/revers_number10.mdl",
|
||||
bone = "ValveBiped.Bip01_R_Hand", rel = "",
|
||||
pos = pos,
|
||||
angle = ang,
|
||||
size = Vector(1.1, 1.1, 1.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}
|
||||
}
|
||||
end
|
||||
--WorldModel
|
||||
SWEP.WElements = {
|
||||
["Reverser"] = { type = "Model", model = "models/metrostroi_train/reversor/reversor_classic.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.93-1, 1.421+1.5, -6.374+1), angle = Angle(-106+90+180, 175, -111+190), size = Vector(1, 1, 1), 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
|
||||
SWEP.Sounds = {
|
||||
"subway_trains/717/kv70/reverser_0-b_2.mp3",
|
||||
"subway_trains/717/kv70/reverser_0-f_1.mp3",
|
||||
"subway_trains/717/kv70/reverser_0-f_2.mp3",
|
||||
"subway_trains/717/kv70/reverser_b-0_1.mp3",
|
||||
"subway_trains/717/kv70/reverser_b-0_2.mp3",
|
||||
"subway_trains/717/kv70/reverser_f-0_1.mp3",
|
||||
"subway_trains/717/kv70/reverser_f-0_2.mp3",
|
||||
"subway_trains/717/kv70/reverser_0-b_1.mp3",
|
||||
}
|
||||
function SWEP:Precache()
|
||||
for _,v in pairs(self.Sounds) do
|
||||
util.PrecacheSound(v)
|
||||
end
|
||||
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()
|
||||
local count = 0
|
||||
if self.Code ~= self:GetNW2Int("Code",-1) then
|
||||
local code = self:GetNW2Int("Code",-1)
|
||||
if code > 0 then
|
||||
for k,v in pairs(self.VElements) do
|
||||
local ent = v.modelEnt
|
||||
if k=="Reverser" or not IsValid(ent) then continue end
|
||||
local i = tonumber(k:sub(6,-1))-1
|
||||
local num = math.floor(code%(10^(i+1))/10^i)
|
||||
ent:SetModel("models/metrostroi_train/reversor/revers_number1"..num..".mdl")
|
||||
count = count + 1
|
||||
end
|
||||
for k,v in pairs(self.WElements) do
|
||||
local ent = v.modelEnt
|
||||
if k=="Reverser" or not IsValid(ent) then continue end
|
||||
local i = tonumber(k:sub(6,-1))-1
|
||||
local num = math.floor(code%(10^(i+1))/10^i)
|
||||
ent:SetModel("models/metrostroi_train/reversor/revers_number1"..num..".mdl")
|
||||
end
|
||||
else
|
||||
count=5
|
||||
end
|
||||
end
|
||||
if count==5 then
|
||||
self.Code = self:GetNW2Int("Code",-1)
|
||||
end
|
||||
end
|
||||
function SWEP:DrawHUD()
|
||||
end
|
||||
69
lua/weapons/train_kv_wrench/init.lua
Normal file
69
lua/weapons/train_kv_wrench/init.lua
Normal file
@@ -0,0 +1,69 @@
|
||||
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:SetCode(code)
|
||||
self.Code = code
|
||||
self:SetNW2Int("Code",code or 0)
|
||||
--print(Format("Your reverser wrench is %05d",self.Code or 0))
|
||||
end
|
||||
function SWEP:Equip(ply)
|
||||
local reverser = ply:GetWeapon("train_kv_wrench_gold")
|
||||
if IsValid(reverser) and not reverser.Removing then
|
||||
ply:StripWeapon("train_kv_wrench_gold")
|
||||
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
|
||||
]]
|
||||
function SWEP:Think()
|
||||
end
|
||||
function SWEP:PrimaryAttack()
|
||||
self:SetNextPrimaryFire( CurTime()+0.5)
|
||||
end
|
||||
|
||||
function SWEP:Reload()
|
||||
if self.LastCheck and CurTime()-self.LastCheck<1 then return end
|
||||
self.LastCheck = CurTime()
|
||||
local owner = self:GetOwner()
|
||||
local ID = Metrostroi.GetReverserID(owner,true)
|
||||
if ID then
|
||||
owner:Give("train_kv_wrench_gold")
|
||||
owner:SelectWeapon("train_kv_wrench_gold")
|
||||
local reverser = owner:GetWeapon("train_kv_wrench_gold")
|
||||
if IsValid(reverser) then
|
||||
reverser:SetCode(ID)
|
||||
end
|
||||
owner:StripWeapon("train_kv_wrench")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function SWEP:OwnerChanged()
|
||||
Metrostroi.GetReverserID(self:GetOwner(),function(code)
|
||||
if not IsValid(self) then return end
|
||||
self:SetCode(code)
|
||||
end)
|
||||
end
|
||||
23
lua/weapons/train_kv_wrench/shared.lua
Normal file
23
lua/weapons/train_kv_wrench/shared.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
--include("shared.lua")
|
||||
--AddCSLuaFile("shared.lua")
|
||||
--AddCSLuaFile("cl_init.lua")
|
||||
SWEP.Author = "TP Hunter NL"
|
||||
SWEP.Contact = "http:--facepunch.com/showthread.php?t=1328089"
|
||||
SWEP.Purpose = "Sit inside train and put it into reverser slot, turn reverser to forward, drive the train"
|
||||
SWEP.Instructions = "test"
|
||||
SWEP.Spawnable = true
|
||||
SWEP.AdminSpawnable = false
|
||||
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"
|
||||
509
lua/weapons/train_kv_wrench_gold/cl_init.lua
Normal file
509
lua/weapons/train_kv_wrench_gold/cl_init.lua
Normal file
@@ -0,0 +1,509 @@
|
||||
include("shared.lua")
|
||||
|
||||
SWEP.PrintName = "Train Reverser Wrench"
|
||||
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_train/reversor/reversor_gold.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.93, 1.421, -7), angle = Angle(-4, 96, -95), size = Vector(1.1, 1.1, 1.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
|
||||
}
|
||||
--WorldModel
|
||||
SWEP.WElements = {
|
||||
["Reverser"] = { type = "Model", model = "models/metrostroi_train/reversor/reversor_gold.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.93-1, 1.421+1.5, -6.374+2), angle = Angle(-106+90+180, 175, -111+190), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
|
||||
}
|
||||
SWEP.VDigits = {
|
||||
Vector(0.3,-4.25-0.65+0*0.3,0.9+0+0*0.005),
|
||||
Vector(0.3,-4.25-0.65+1*0.3,0.9+0+1*0.005),
|
||||
Vector(0.3,-4.25-0.65+2*0.3,0.9+0+2*0.005),
|
||||
}
|
||||
for i,v in pairs(SWEP.VDigits) do
|
||||
local reverser = SWEP.VElements.Reverser
|
||||
local pos,ang = LocalToWorld(v,Angle(0,-91,-91),reverser.pos,reverser.angle)
|
||||
SWEP.VElements["Digit"..i] = {
|
||||
type = "Model",
|
||||
model = "models/metrostroi_train/reversor/revers_number00.mdl",
|
||||
bone = "ValveBiped.Bip01_R_Hand", rel = "",
|
||||
pos = pos,
|
||||
angle = ang,
|
||||
size = Vector(1.1, 1.1, 1.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}
|
||||
}
|
||||
end
|
||||
--[[ SWEP.WDigits = {
|
||||
Vector(0,0+0.9+0.005*0,0),
|
||||
Vector(1,0+0.9+0.005*1,0),
|
||||
Vector(2,0+0.9+0.005*2,0),
|
||||
--Vector(0.3,-4.25-0.65+0*0.3,0.9+0+0*0.005),
|
||||
--Vector(0.3,-4.25-0.65+1*0.3,0.9+0+1*0.005),
|
||||
--Vector(0.3,-4.25-0.65+2*0.3,0.9+0+2*0.005),
|
||||
}
|
||||
for i,v in pairs(SWEP.WDigits) do
|
||||
local reverser = SWEP.WElements.Reverser
|
||||
local pos,ang = LocalToWorld(v,Angle(0,180,0),reverser.pos,reverser.angle)
|
||||
SWEP.WElements["Digit"..i] = {
|
||||
type = "Model",
|
||||
model = "models/metrostroi_train/reversor/revers_number0"..i..".mdl",
|
||||
bone = "ValveBiped.Bip01_R_Hand", rel = "",
|
||||
pos = pos,
|
||||
angle = ang,
|
||||
size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}
|
||||
}
|
||||
end--]]
|
||||
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
|
||||
|
||||
]]--
|
||||
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()
|
||||
self:SetNextSecondaryFire( CurTime() + 0.5 )
|
||||
end
|
||||
|
||||
function SWEP:Deploy()
|
||||
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
|
||||
end
|
||||
|
||||
function SWEP:Think()
|
||||
local count = 0
|
||||
if self.Code ~= self:GetNW2Int("Code",-1) then
|
||||
local code = self:GetNW2Int("Code",-1)
|
||||
if code > 0 then
|
||||
for k,v in pairs(self.VElements) do
|
||||
local ent = v.modelEnt
|
||||
if k=="Reverser" or not IsValid(ent) then continue end
|
||||
local i = tonumber(k:sub(6,-1))-1
|
||||
local num = math.floor(code%(10^(i+1))/10^i)
|
||||
ent:SetModel("models/metrostroi_train/reversor/revers_number0"..num..".mdl")
|
||||
count = count + 1
|
||||
end
|
||||
for k,v in pairs(self.WElements) do
|
||||
local ent = v.modelEnt
|
||||
if k=="Reverser" or not IsValid(ent) then continue end
|
||||
local i = tonumber(k:sub(6,-1))-1
|
||||
local num = math.floor(code%(10^(i+1))/10^i)
|
||||
ent:SetModel("models/metrostroi_train/reversor/revers_number0"..num..".mdl")
|
||||
end
|
||||
else
|
||||
count=5
|
||||
end
|
||||
end
|
||||
if count==5 then
|
||||
self.Code = self:GetNW2Int("Code",-1)
|
||||
end
|
||||
end
|
||||
65
lua/weapons/train_kv_wrench_gold/init.lua
Normal file
65
lua/weapons/train_kv_wrench_gold/init.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
AddCSLuaFile( "cl_init.lua" )
|
||||
AddCSLuaFile( "shared.lua" )
|
||||
|
||||
include( "shared.lua" )
|
||||
|
||||
SWEP.Weight = 1
|
||||
SWEP.AutoSwitchTo = false
|
||||
SWEP.AutoSwitchFrom = true
|
||||
|
||||
function SWEP:Initialize()
|
||||
if not self.Code then
|
||||
Metrostroi.GetReverserID(self.Owner,function(code)
|
||||
if not IsValid(self) then return end
|
||||
self:SetCode(code)
|
||||
end,true)
|
||||
end
|
||||
self.LastCheck = CurTime()
|
||||
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
|
||||
]]
|
||||
function SWEP:Think()
|
||||
end
|
||||
function SWEP:PrimaryAttack()
|
||||
end
|
||||
|
||||
function SWEP:Equip(ply)
|
||||
if self.Code and CurTime()-self.LastCheck > 30 then
|
||||
Metrostroi.GetReverserID(ply,function(code)
|
||||
if not IsValid(self) then return end
|
||||
self:SetCode(code)
|
||||
end,true)
|
||||
end
|
||||
end
|
||||
function SWEP:SetCode(code)
|
||||
if not code or code <=0 then
|
||||
self:Reload()
|
||||
--print("Your don't own a reverser wrench")
|
||||
else
|
||||
self.Code = code
|
||||
self:SetNW2Int("Code",code)
|
||||
--print(Format("Your gold reverser wrench is %03d",self.Code or 0))
|
||||
end
|
||||
end
|
||||
|
||||
function SWEP:Reload()
|
||||
self.Removing = true
|
||||
self.Owner:Give("train_kv_wrench")
|
||||
self.Owner:SelectWeapon("train_kv_wrench")
|
||||
self.Owner:StripWeapon("train_kv_wrench_gold")
|
||||
end
|
||||
23
lua/weapons/train_kv_wrench_gold/shared.lua
Normal file
23
lua/weapons/train_kv_wrench_gold/shared.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
--include("shared.lua")
|
||||
--AddCSLuaFile("shared.lua")
|
||||
--AddCSLuaFile("cl_init.lua")
|
||||
SWEP.Author = "TP Hunter NL"
|
||||
SWEP.Contact = "http:--facepunch.com/showthread.php?t=1328089"
|
||||
SWEP.Purpose = "Sit inside train and put it into reverser slot, turn reverser to forward, drive the train"
|
||||
SWEP.Instructions = "Used as a key and reverser handle for the subway trains"
|
||||
SWEP.Spawnable = false
|
||||
SWEP.AdminSpawnable = false
|
||||
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