zombiesurvival-evolved/gamemodes/zombiesurvival/entities/weapons/swep_construction_kit/shared.lua

264 lines
5.7 KiB
Lua
Raw Normal View History

2014-10-02 08:49:54 +08:00
if SERVER then
AddCSLuaFile("shared.lua")
AddCSLuaFile("client.lua")
AddCSLuaFile("glon.lua")
AddCSLuaFile("menu/tool.lua")
AddCSLuaFile("menu/weapon.lua")
AddCSLuaFile("menu/ironsights.lua")
AddCSLuaFile("menu/models.lua")
AddCSLuaFile("base_code.lua")
end
if CLIENT then
SWEP.PrintName = "SWEP Construction Kit"
SWEP.Author = "Clavus"
SWEP.Contact = "clavus@clavusstudios.com"
SWEP.Purpose = "Design SWEP ironsights and clientside models"
SWEP.Instructions = "http://tinyurl.com/swepkit"
SWEP.Slot = 5
SWEP.SlotPos = 10
SWEP.ViewModelFlip = false
2014-10-02 08:49:54 +08:00
SWEP.DrawCrosshair = false
2014-10-02 08:49:54 +08:00
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = true
2014-10-02 08:49:54 +08:00
end
local debugging = false
function SCKDebug( msg )
if !debugging then return end
MsgN("[SCK] "..msg)
end
local repmsg = {}
function SCKDebugRepeat( tag, msg )
if !debugging then return end
if !repmsg[tag] then repmsg[tag] = { last = 0, num = 0 } end
repmsg[tag].num = repmsg[tag].num + 1
if (CurTime() - repmsg[tag].last >= 1) then
MsgN("[SCK][Repeated "..repmsg[tag].num.." times in last sec] "..msg)
repmsg[tag].num = 0
repmsg[tag].last = CurTime()
end
end
SWEP.HoldType = "pistol"
SWEP.HoldTypes = { "normal", "melee", "melee2", "fist",
"knife", "smg", "ar2", "pistol", "revolver", "rpg", "physgun",
2014-10-02 08:49:54 +08:00
"grenade", "shotgun", "crossbow", "slam", "duel", "passive",
"camera" }
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.CurWorldModel = "models/weapons/w_pistol.mdl" -- this is where shit gets hacky
2014-10-02 08:49:54 +08:00
SWEP.ViewModelFOV = 70
SWEP.BobScale = 0
SWEP.SwayScale = 0
SWEP.Primary.Automatic = false
SWEP.IronsightTime = 0.2
SWEP.IronSightsPos = Vector(0, 0, 0)
SWEP.IronSightsAng = Vector(0, 0, 0)
local sck_class = ""
function SWEP:Initialize()
self:SetWeaponHoldType(self.HoldType)
2014-10-02 08:49:54 +08:00
self:SetIronSights( true )
self:ResetIronSights()
2014-10-02 08:49:54 +08:00
if CLIENT then
self:CreateWeaponWorldModel()
self:ClientInit()
if (not file.IsDir("swep_construction_kit", "DATA")) then
file.CreateDir("swep_construction_kit")
end
end
2014-10-02 08:49:54 +08:00
self.Dropped = false
2014-10-02 08:49:54 +08:00
sck_class = self:GetClass()
2014-10-02 08:49:54 +08:00
end
function SWEP:Equip()
self.Dropped = false
end
function SWEP:PrimaryAttack()
self:SetNextPrimaryFire(CurTime() + 0.2)
2014-10-02 08:49:54 +08:00
if CLIENT then
self:OpenMenu()
end
if game.SinglePlayer() then
self:GetOwner():SendLua("LocalPlayer():GetActiveWeapon():OpenMenu()")
2014-10-02 08:49:54 +08:00
end
2014-10-02 08:49:54 +08:00
end
function SWEP:SecondaryAttack()
self:SetNextSecondaryFire(CurTime() + 0.2)
2014-10-02 08:49:54 +08:00
if CLIENT then
self:OpenMenu()
end
if game.SinglePlayer() then
self:GetOwner():SendLua("LocalPlayer():GetActiveWeapon():OpenMenu()")
2014-10-02 08:49:54 +08:00
end
2014-10-02 08:49:54 +08:00
end
function SWEP:SetupDataTables()
self:DTVar( "Bool", 0, "ironsights" )
self:DTVar( "Bool", 1, "thirdperson" )
2014-10-02 08:49:54 +08:00
end
function SWEP:ToggleIronSights()
self.dt.ironsights = !self.dt.ironsights
end
function SWEP:SetIronSights( b )
self.dt.ironsights = b
end
function SWEP:GetIronSights()
return self.dt.ironsights
end
function SWEP:ResetIronSights()
RunConsoleCommand("_sp_ironsight_x", 0)
RunConsoleCommand("_sp_ironsight_y", 0)
RunConsoleCommand("_sp_ironsight_z", 0)
RunConsoleCommand("_sp_ironsight_pitch", 0)
RunConsoleCommand("_sp_ironsight_yaw", 0)
RunConsoleCommand("_sp_ironsight_roll", 0)
end
function SWEP:ToggleThirdPerson()
self:SetThirdPerson( !self.dt.thirdperson )
end
function SWEP:SetThirdPerson( b )
self.dt.thirdperson = b
local owner = self:GetOwner()
2014-10-02 08:49:54 +08:00
if (!IsValid(owner)) then owner = self.LastOwner end
if (!IsValid(owner)) then return end
if (self.dt.thirdperson) then
2014-10-02 08:49:54 +08:00
owner:SetViewEntity(game.GetWorld())
owner:CrosshairDisable()
else
2014-10-02 08:49:54 +08:00
owner:SetViewEntity(owner)
owner:CrosshairEnable()
2014-10-02 08:49:54 +08:00
end
end
function SWEP:GetThirdPerson()
return self.dt.thirdperson
end
function SWEP:GetViewModelPosition(pos, ang)
--if true then return pos, ang end
--SCKDebugRepeat( "SWEP:VMPos", "Getting viewmodel pos" )
2014-10-02 08:49:54 +08:00
local bIron = self.dt.ironsights
local fIronTime = self.fIronTime or 0
if (not bIron and fIronTime < CurTime() - self.IronsightTime) then
return pos, ang
end
2014-10-02 08:49:54 +08:00
self.IronSightsPos, self.IronSightsAng = self:GetIronSightCoordination()
local Mul = 1.0
if (fIronTime > CurTime() - self.IronsightTime) then
Mul = math.Clamp((CurTime() - fIronTime) / self.IronsightTime, 0, 1)
if not bIron then Mul = 1 - Mul end
end
local Offset = self.IronSightsPos
if (self.IronSightsAng) then
ang = ang * 1
ang:RotateAroundAxis(ang:Right(), self.IronSightsAng.x * Mul)
ang:RotateAroundAxis(ang:Up(), self.IronSightsAng.y * Mul)
ang:RotateAroundAxis(ang:Forward(), self.IronSightsAng.z * Mul)
end
local Right = ang:Right()
local Up = ang:Up()
local Forward = ang:Forward()
pos = pos + Offset.x * Right * Mul
pos = pos + Offset.y * Forward * Mul
pos = pos + Offset.z * Up * Mul
2014-10-02 08:49:54 +08:00
return pos, ang
end
SWEP.ir_x = CreateConVar( "_sp_ironsight_x", 0.0 )
SWEP.ir_y = CreateConVar( "_sp_ironsight_y", 0.0 )
SWEP.ir_z = CreateConVar( "_sp_ironsight_z", 0.0 )
SWEP.ir_p = CreateConVar( "_sp_ironsight_pitch", 0.0 )
SWEP.ir_yw = CreateConVar( "_sp_ironsight_yaw", 0.0 )
SWEP.ir_r = CreateConVar( "_sp_ironsight_roll", 0.0 )
function SWEP:GetIronSightCoordination()
2014-10-02 08:49:54 +08:00
local vec = Vector( self.ir_x:GetFloat(), self.ir_y:GetFloat(), self.ir_z:GetFloat() )
local ang = Vector( self.ir_p:GetFloat(), self.ir_yw:GetFloat(), self.ir_r:GetFloat() )
return vec, ang
2014-10-02 08:49:54 +08:00
end
function SWEP:GetHoldTypes()
return self.HoldTypes
end
SWEP.LastOwner = nil
--[[**************************
2014-10-02 08:49:54 +08:00
Helper functions
**************************]]
2014-10-02 08:49:54 +08:00
SWEP.IsSCK = true
function GetSCKSWEP( pl )
local wep = pl:GetActiveWeapon()
if (IsValid(wep) and wep.IsSCK) then
return wep
end
--Error("Not holding SWEP Construction Kit!")
2014-10-02 08:49:54 +08:00
return NULL
end
if SERVER then
include("server.lua")
end
if CLIENT then
include("client.lua")
end