Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.40 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. if (CLIENT) then
  4. SWEP.Category = "bKeycardScanner"
  5. SWEP.PrintName = "Keycard"
  6. SWEP.Slot = 0
  7. SWEP.SlotPos = 0
  8. SWEP.DrawAmmo = false
  9. SWEP.DrawCrosshair = false
  10. SWEP.WepSelectIcon = surface.GetTextureID("weapons/bkeycard")
  11. end
  12.  
  13. SWEP.UseHands = true
  14.  
  15. SWEP.Spawnable = true
  16. SWEP.AdminOnly = false
  17.  
  18. SWEP.Primary.ClipSize = -1
  19. SWEP.Primary.DefaultClip = 0
  20. SWEP.Primary.Automatic = false
  21. SWEP.Primary.Ammo = ""
  22.  
  23. SWEP.Secondary.ClipSize = -1
  24. SWEP.Secondary.DefaultClip = -1
  25. SWEP.Secondary.Automatic = false
  26. SWEP.Secondary.Ammo = ""
  27.  
  28. SWEP.HoldType = "pistol"
  29. SWEP.ViewModelFOV = 70
  30. SWEP.ViewModelFlip = false
  31. SWEP.UseHands = true
  32. SWEP.ViewModel = "models/bkeycardscanner/c_keycard.mdl"
  33. SWEP.WorldModel = "models/bkeycardscanner/w_keycard.mdl"
  34. SWEP.ShowViewModel = true
  35. SWEP.ShowWorldModel = true
  36.  
  37. SWEP.WElements = {
  38. ["keycard"] = { type = "Model", model = "models/bkeycardscanner/w_keycard.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(5.5, 1.557, -1.3), angle = Angle(19.87, 177.143, -6), size = Vector(0.699, 0.699, 0.699), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
  39. }
  40.  
  41. function SWEP:ShouldDropOnDie() return false end
  42. function SWEP:Reload() return true end
  43. function SWEP:PrintWeaponInfo() end
  44.  
  45. local function table_FullCopy(tab)
  46. if (not tab) then return nil end
  47. local res = {}
  48. for k, v in pairs( tab ) do
  49. if (type(v) == "table") then
  50. res[k] = table_FullCopy(v)
  51. elseif (type(v) == "Vector") then
  52. res[k] = Vector(v.x, v.y, v.z)
  53. elseif (type(v) == "Angle") then
  54. res[k] = Angle(v.p, v.y, v.r)
  55. else
  56. res[k] = v
  57. end
  58. end
  59. return res
  60. end
  61.  
  62. if (CLIENT) then
  63. function SWEP:DynamicKeycard(name,color)
  64. self.PrintName = name
  65. end
  66. end
  67.  
  68. function SWEP:Initialize()
  69. self:SetHoldType(self.HoldType)
  70. if (CLIENT) then
  71. self.WElements = table_FullCopy(self.WElements)
  72. self:CreateModels(self.WElements)
  73. end
  74. end
  75.  
  76. function SWEP:Holster()
  77. hook.Remove("Think","bkeycard_dmodelpanel")
  78. if (IsValid(bKeycardScanner_ModelPanel)) then
  79. bKeycardScanner_ModelPanel:Remove()
  80. end
  81. return true
  82. end
  83.  
  84. function SWEP:SecondaryAttack()
  85. if (SERVER) then
  86. bKeycardScanner:ShowID(self:GetOwner())
  87. end
  88. self:SetNextSecondaryFire(CurTime()+3)
  89. end
  90.  
  91. function SWEP:PrimaryAttack()
  92. if (not IsFirstTimePredicted()) then return end
  93. local ply = self:GetOwner()
  94. local ent = ply:GetEyeTrace().Entity
  95. if (IsValid(ent) and not ent:IsWorld() and ent:GetClass() == "bkeycardscanner") then
  96. if (not ent:GetWaiting()) then
  97. if (ent:GetPos():Distance(ply:GetPos()) < bKeycardScanner.Config.ScanDistance) then
  98. if (SERVER) then
  99. if (bKeycardScanner.Config.TakeKeycard) then
  100. ply:StripWeapon("bkeycard")
  101. end
  102. local scanid = ent:GetScanToken()
  103. if (bKeycardScanner.Config.ScanTime > 0) then
  104. ent:SetScanningPly(ply)
  105. ent:SetText("SCANNING")
  106. ent:SetScanning(true)
  107. ent:SetWaiting(true)
  108. ent:EmitSound("buttons/button15.wav",SNDLVL_45dB)
  109. ent:ShowKeycard(true)
  110. ent:SetLights(false,false,true)
  111. end
  112. local function success()
  113. if (IsValid(ent)) then
  114. if (not ent:VerifyScan(scanid)) then return end
  115. if (not ply:HasWeapon("bkeycard") and bKeycardScanner.Config.TakeKeycard) then
  116. ply:Give("bkeycard")
  117. end
  118. ent:AccessGranted()
  119. end
  120. end
  121. if (ent:GetCreator() == ply or (not ent:GetLockdown() and ent:IsAuthorized(ply))) then
  122. timer.Simple(bKeycardScanner.Config.ScanTime,success)
  123. return
  124. end
  125. timer.Simple(bKeycardScanner.Config.ScanTime,function()
  126. if (IsValid(ent)) then
  127. if (not ent:VerifyScan(scanid)) then return end
  128. if (not ply:HasWeapon("bkeycard") and bKeycardScanner.Config.TakeKeycard) then
  129. ply:Give("bkeycard")
  130. end
  131. ent:AccessDenied()
  132. end
  133. end)
  134. end
  135. elseif (CLIENT) then
  136. bKeycardScanner:chatprint("You're too far away!","bad")
  137. end
  138. elseif (CLIENT) then
  139. bKeycardScanner:chatprint("Please wait until the keycard scanner has finished scanning.","bad")
  140. end
  141. elseif (CLIENT) then
  142. bKeycardScanner:chatprint("That's not a keycard scanner!","bad")
  143. end
  144. end
  145.  
  146. --########################################--
  147. -- SWEP CONSTRUCTION KIT CODE --
  148. --########################################--
  149.  
  150. SWEP.wRenderOrder = nil
  151. function SWEP:DrawWorldModel()
  152.  
  153. if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  154. --self:DrawModel()
  155. end
  156.  
  157. if (!self.WElements) then return end
  158.  
  159. if (!self.wRenderOrder) then
  160.  
  161. self.wRenderOrder = {}
  162.  
  163. for k, v in pairs( self.WElements ) do
  164. if (v.type == "Model") then
  165. table.insert(self.wRenderOrder, 1, k)
  166. elseif (v.type == "Sprite" or v.type == "Quad") then
  167. table.insert(self.wRenderOrder, k)
  168. end
  169. end
  170.  
  171. end
  172.  
  173. if (IsValid(self.Owner)) then
  174. bone_ent = self.Owner
  175. else
  176. bone_ent = self
  177. end
  178.  
  179. for k, name in pairs( self.wRenderOrder ) do
  180.  
  181. local v = self.WElements[name]
  182. if (!v) then self.wRenderOrder = nil break end
  183. if (v.hide) then continue end
  184.  
  185. local pos, ang
  186.  
  187. if (v.bone) then
  188. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
  189. else
  190. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
  191. end
  192.  
  193. if (!pos) then continue end
  194.  
  195. local model = v.modelEnt
  196. local sprite = v.spriteMaterial
  197.  
  198. if (v.type == "Model" and IsValid(model)) then
  199.  
  200. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  201. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  202. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  203. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  204.  
  205. model:SetAngles(ang)
  206. local matrix = Matrix()
  207. matrix:Scale(v.size)
  208. model:EnableMatrix( "RenderMultiply", matrix )
  209.  
  210. if (v.material == "") then
  211. model:SetMaterial("")
  212. elseif (model:GetMaterial() != v.material) then
  213. model:SetMaterial( v.material )
  214. end
  215.  
  216. if (v.skin and v.skin != model:GetSkin()) then
  217. model:SetSkin(v.skin)
  218. end
  219.  
  220. if (v.bodygroup) then
  221. for k, v in pairs( v.bodygroup ) do
  222. if (model:GetBodygroup(k) != v) then
  223. model:SetBodygroup(k, v)
  224. end
  225. end
  226. end
  227.  
  228. if (v.surpresslightning) then
  229. render.SuppressEngineLighting(true)
  230. end
  231.  
  232. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  233. render.SetBlend(v.color.a/255)
  234. model:DrawModel()
  235. render.SetBlend(1)
  236. render.SetColorModulation(1, 1, 1)
  237.  
  238. if (v.surpresslightning) then
  239. render.SuppressEngineLighting(false)
  240. end
  241.  
  242. elseif (v.type == "Sprite" and sprite) then
  243.  
  244. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  245. render.SetMaterial(sprite)
  246. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  247.  
  248. elseif (v.type == "Quad" and v.draw_func) then
  249.  
  250. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  251. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  252. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  253. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  254.  
  255. cam.Start3D2D(drawpos, ang, v.size)
  256. v.draw_func( self )
  257. cam.End3D2D()
  258.  
  259. end
  260.  
  261. end
  262.  
  263. end
  264.  
  265. function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
  266.  
  267. local bone, pos, ang
  268. if (tab.rel and tab.rel != "") then
  269.  
  270. local v = basetab[tab.rel]
  271.  
  272. if (!v) then return end
  273.  
  274. pos, ang = self:GetBoneOrientation( basetab, v, ent )
  275.  
  276. if (!pos) then return end
  277.  
  278. pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  279. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  280. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  281. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  282.  
  283. else
  284.  
  285. bone = ent:LookupBone(bone_override or tab.bone)
  286.  
  287. if (!bone) then return end
  288.  
  289. pos, ang = Vector(0,0,0), Angle(0,0,0)
  290. local m = ent:GetBoneMatrix(bone)
  291. if (m) then
  292. pos, ang = m:GetTranslation(), m:GetAngles()
  293. end
  294.  
  295. if (IsValid(self.Owner) and self.Owner:IsPlayer() and
  296. ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
  297. ang.r = -ang.r
  298. end
  299.  
  300. end
  301.  
  302. return pos, ang
  303. end
  304.  
  305. function SWEP:CreateModels( tab )
  306.  
  307. if (!tab) then return end
  308.  
  309. for k, v in pairs( tab ) do
  310. if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
  311. string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
  312.  
  313. v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  314. if (IsValid(v.modelEnt)) then
  315. v.modelEnt:SetPos(self:GetPos())
  316. v.modelEnt:SetAngles(self:GetAngles())
  317. v.modelEnt:SetParent(self)
  318. v.modelEnt:SetNoDraw(true)
  319. v.createdModel = v.model
  320. else
  321. v.modelEnt = nil
  322. end
  323.  
  324. elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  325. and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
  326.  
  327. local name = v.sprite.."-"
  328. local params = { ["$basetexture"] = v.sprite }
  329.  
  330. local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  331. for i, j in pairs( tocheck ) do
  332. if (v[j]) then
  333. params["$"..j] = 1
  334. name = name.."1"
  335. else
  336. name = name.."0"
  337. end
  338. end
  339.  
  340. v.createdSprite = v.sprite
  341. v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  342.  
  343. end
  344. end
  345.  
  346. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement