dasdasdasddsadsa2

cid

Sep 19th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.64 KB | Source Code | 0 0
  1. --Author Information
  2. SWEP.PrintName = "CID"
  3. SWEP.Author = ""
  4. SWEP.Instructions = ""
  5. SWEP.Purpose = ""
  6.  
  7. --Spawn Settings
  8. SWEP.Spawnable = true
  9. SWEP.AdminOnly = true
  10.  
  11. --Primary Attack
  12. SWEP.Primary.ClipSize = -1
  13. SWEP.Primary.DefaultClip = -1
  14. SWEP.Primary.Automatic = false
  15. SWEP.Primary.Ammo = "none"
  16.  
  17. --Secondary Attack
  18. SWEP.Secondary.ClipSize = -1
  19. SWEP.Secondary.DefaultClip = -1
  20. SWEP.Secondary.Automatic = false
  21. SWEP.Secondary.Ammo = "none"
  22.  
  23. --Misc Settings
  24. SWEP.Weight = 5
  25. SWEP.AutoSwitchTo = true
  26. SWEP.AutoSwitchFrom = true
  27. SWEP.Slot = 5
  28. SWEP.SlotPos = 1
  29. SWEP.DrawAmmo = false
  30. SWEP.DrawCrosshair = false
  31. SWEP.Category = "CID"
  32. SWEP.FiresUnderwater = true
  33. SWEP.ViewModelFOV = 70
  34. SWEP.ViewModelFlip = false
  35. SWEP.ViewModel = Model("models/weapons/c_arms.mdl")
  36. SWEP.WorldModel = ""
  37. SWEP.ShowViewModel = true
  38. SWEP.ShowWorldModel = true
  39. SWEP.HoldType = "pistol"
  40. SWEP.ViewModelFOV = 70
  41. SWEP.ViewModelFlip = false
  42. SWEP.ViewModel = Model("models/weapons/c_arms.mdl")
  43. SWEP.WorldModel = ""
  44. SWEP.ShowViewModel = true
  45. SWEP.ShowWorldModel = true
  46. SWEP.ViewModelBoneMods = {
  47. ["Bip01 L Arm2"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
  48. ["Bip01 L Hand"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
  49. ["Bip01 L Arm1"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
  50. ["Bip01 L Arm"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(-0.556, 0, 0), angle = Angle(0, 0, 0) },
  51. ["Bip01"] = { scale = Vector(0.887, 0.887, 0.887), pos = Vector(0.555, 0.925, 0), angle = Angle(0, 0, 0) }
  52. }
  53. SWEP.ViewModelBoneMods = {
  54. ["Bip01 L Arm"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(-0.556, 0, 0), angle = Angle(0, 0, 0) },
  55. ["Bip01"] = { scale = Vector(1, 1, 1), pos = Vector(0.185, 0, 0), angle = Angle(0, 0, 0) }
  56. }
  57. SWEP.IronSightsPos = Vector(0, 0, 0)
  58. SWEP.IronSightsAng = Vector(0, 0, 0)
  59. SWEP.VElements = {
  60. ["id"] = { type = "Model", model = "models/cmz/citizenid.mdl", bone = "Bip01", rel = "", pos = Vector(19, 0.557, 25.454), angle = Angle(-90, 153.117, 0), size = Vector(1.08, 1.08, 1.08), color = Color(255, 255, 255, 255), surpresslightning = false, material = "materials/models/dorado/2textue.vtf", skin = 0, bodygroup = {} }
  61. }
  62. SWEP.WElements = {
  63. ["ide"] = { type = "Model", model = "models/cmz/citizenid.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.9, 4.596, -0.519), angle = Angle(90, -180, -3.507), size = Vector(1.34, 1.34, 1.34), color = Color(255, 255, 255, 255), surpresslightning = false, material = "materials/models/dorado/2textue.vtf", skin = 0, bodygroup = {} }
  64. }
  65.  
  66.  
  67. /********************************************************
  68. SWEP Construction Kit base code
  69. Created by Clavus
  70. Available for public use, thread at:
  71. facepunch.com/threads/1032378
  72.  
  73.  
  74. DESCRIPTION:
  75. This script is meant for experienced scripters
  76. that KNOW WHAT THEY ARE DOING. Don't come to me
  77. with basic Lua questions.
  78.  
  79. Just copy into your SWEP or SWEP base of choice
  80. and merge with your own code.
  81.  
  82. The SWEP.VElements, SWEP.WElements and
  83. SWEP.ViewModelBoneMods tables are all optional
  84. and only have to be visible to the client.
  85. ********************************************************/
  86.  
  87. function SWEP:Initialize()
  88.  
  89. // other initialize code goes here
  90.  
  91. if CLIENT then
  92.  
  93. // Create a new table for every weapon instance
  94. self.VElements = table.FullCopy( self.VElements )
  95. self.WElements = table.FullCopy( self.WElements )
  96. self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
  97.  
  98. self:CreateModels(self.VElements) // create viewmodels
  99. self:CreateModels(self.WElements) // create worldmodels
  100.  
  101. // init view model bone build function
  102. if IsValid(self.Owner) then
  103. local vm = self.Owner:GetViewModel()
  104. if IsValid(vm) then
  105. self:ResetBonePositions(vm)
  106.  
  107. // Init viewmodel visibility
  108. if (self.ShowViewModel == nil or self.ShowViewModel) then
  109. vm:SetColor(Color(255,255,255,255))
  110. else
  111. // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
  112. vm:SetColor(Color(255,255,255,1))
  113. // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
  114. // however for some reason the view model resets to render mode 0 every frame so we just apply a debug material to prevent it from drawing
  115. vm:SetMaterial("Debug/hsv")
  116. end
  117. end
  118. end
  119.  
  120. end
  121.  
  122. end
  123.  
  124. function SWEP:PrimaryAttack()
  125.  
  126. if CLIENT then
  127. local ply = LocalPlayer()
  128. RunConsoleCommand('say','/me Предоставил ID Карту | Лояльность - Низкая | Меня зовут '..ply:GetName()..'')
  129. end
  130.  
  131. end
  132.  
  133. function SWEP:Holster()
  134.  
  135. if CLIENT and IsValid(self.Owner) then
  136. local vm = self.Owner:GetViewModel()
  137. if IsValid(vm) then
  138. self:ResetBonePositions(vm)
  139. end
  140. end
  141.  
  142. return true
  143. end
  144.  
  145. function SWEP:OnRemove()
  146. self:Holster()
  147. end
  148.  
  149. if CLIENT then
  150.  
  151. SWEP.vRenderOrder = nil
  152. function SWEP:ViewModelDrawn()
  153.  
  154. local vm = self.Owner:GetViewModel()
  155. if !IsValid(vm) then return end
  156.  
  157. if (!self.VElements) then return end
  158.  
  159. self:UpdateBonePositions(vm)
  160.  
  161. if (!self.vRenderOrder) then
  162.  
  163. // we build a render order because sprites need to be drawn after models
  164. self.vRenderOrder = {}
  165.  
  166. for k, v in pairs( self.VElements ) do
  167. if (v.type == "Model") then
  168. table.insert(self.vRenderOrder, 1, k)
  169. elseif (v.type == "Sprite" or v.type == "Quad") then
  170. table.insert(self.vRenderOrder, k)
  171. end
  172. end
  173.  
  174. end
  175.  
  176. for k, name in ipairs( self.vRenderOrder ) do
  177.  
  178. local v = self.VElements[name]
  179. if (!v) then self.vRenderOrder = nil break end
  180. if (v.hide) then continue end
  181.  
  182. local model = v.modelEnt
  183. local sprite = v.spriteMaterial
  184.  
  185. if (!v.bone) then continue end
  186.  
  187. local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
  188.  
  189. if (!pos) then continue end
  190.  
  191. if (v.type == "Model" and IsValid(model)) then
  192.  
  193. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  194. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  195. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  196. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  197.  
  198. model:SetAngles(ang)
  199. //model:SetModelScale(v.size)
  200. local matrix = Matrix()
  201. matrix:Scale(v.size)
  202. model:EnableMatrix( "RenderMultiply", matrix )
  203.  
  204. if (v.material == "") then
  205. model:SetMaterial("")
  206. elseif (model:GetMaterial() != v.material) then
  207. model:SetMaterial( v.material )
  208. end
  209.  
  210. if (v.skin and v.skin != model:GetSkin()) then
  211. model:SetSkin(v.skin)
  212. end
  213.  
  214. if (v.bodygroup) then
  215. for k, v in pairs( v.bodygroup ) do
  216. if (model:GetBodygroup(k) != v) then
  217. model:SetBodygroup(k, v)
  218. end
  219. end
  220. end
  221.  
  222. if (v.surpresslightning) then
  223. render.SuppressEngineLighting(true)
  224. end
  225.  
  226. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  227. render.SetBlend(v.color.a/255)
  228. model:DrawModel()
  229. render.SetBlend(1)
  230. render.SetColorModulation(1, 1, 1)
  231.  
  232. if (v.surpresslightning) then
  233. render.SuppressEngineLighting(false)
  234. end
  235.  
  236. elseif (v.type == "Sprite" and sprite) then
  237.  
  238. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  239. render.SetMaterial(sprite)
  240. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  241.  
  242. elseif (v.type == "Quad" and v.draw_func) then
  243.  
  244. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  245. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  246. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  247. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  248.  
  249. cam.Start3D2D(drawpos, ang, v.size)
  250. v.draw_func( self )
  251. cam.End3D2D()
  252.  
  253. end
  254.  
  255. end
  256.  
  257. end
  258.  
  259. SWEP.wRenderOrder = nil
  260. function SWEP:DrawWorldModel()
  261.  
  262. if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  263. self:DrawModel()
  264. end
  265.  
  266. if (!self.WElements) then return end
  267.  
  268. if (!self.wRenderOrder) then
  269.  
  270. self.wRenderOrder = {}
  271.  
  272. for k, v in pairs( self.WElements ) do
  273. if (v.type == "Model") then
  274. table.insert(self.wRenderOrder, 1, k)
  275. elseif (v.type == "Sprite" or v.type == "Quad") then
  276. table.insert(self.wRenderOrder, k)
  277. end
  278. end
  279.  
  280. end
  281.  
  282. if (IsValid(self.Owner)) then
  283. bone_ent = self.Owner
  284. else
  285. // when the weapon is dropped
  286. bone_ent = self
  287. end
  288.  
  289. for k, name in pairs( self.wRenderOrder ) do
  290.  
  291. local v = self.WElements[name]
  292. if (!v) then self.wRenderOrder = nil break end
  293. if (v.hide) then continue end
  294.  
  295. local pos, ang
  296.  
  297. if (v.bone) then
  298. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
  299. else
  300. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
  301. end
  302.  
  303. if (!pos) then continue end
  304.  
  305. local model = v.modelEnt
  306. local sprite = v.spriteMaterial
  307.  
  308. if (v.type == "Model" and IsValid(model)) then
  309.  
  310. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  311. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  312. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  313. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  314.  
  315. model:SetAngles(ang)
  316. //model:SetModelScale(v.size)
  317. local matrix = Matrix()
  318. matrix:Scale(v.size)
  319. model:EnableMatrix( "RenderMultiply", matrix )
  320.  
  321. if (v.material == "") then
  322. model:SetMaterial("")
  323. elseif (model:GetMaterial() != v.material) then
  324. model:SetMaterial( v.material )
  325. end
  326.  
  327. if (v.skin and v.skin != model:GetSkin()) then
  328. model:SetSkin(v.skin)
  329. end
  330.  
  331. if (v.bodygroup) then
  332. for k, v in pairs( v.bodygroup ) do
  333. if (model:GetBodygroup(k) != v) then
  334. model:SetBodygroup(k, v)
  335. end
  336. end
  337. end
  338.  
  339. if (v.surpresslightning) then
  340. render.SuppressEngineLighting(true)
  341. end
  342.  
  343. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  344. render.SetBlend(v.color.a/255)
  345. model:DrawModel()
  346. render.SetBlend(1)
  347. render.SetColorModulation(1, 1, 1)
  348.  
  349. if (v.surpresslightning) then
  350. render.SuppressEngineLighting(false)
  351. end
  352.  
  353. elseif (v.type == "Sprite" and sprite) then
  354.  
  355. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  356. render.SetMaterial(sprite)
  357. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  358.  
  359. elseif (v.type == "Quad" and v.draw_func) then
  360.  
  361. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  362. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  363. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  364. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  365.  
  366. cam.Start3D2D(drawpos, ang, v.size)
  367. v.draw_func( self )
  368. cam.End3D2D()
  369.  
  370. end
  371.  
  372. end
  373.  
  374. end
  375.  
  376. function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
  377.  
  378. local bone, pos, ang
  379. if (tab.rel and tab.rel != "") then
  380.  
  381. local v = basetab[tab.rel]
  382.  
  383. if (!v) then return end
  384.  
  385. // Technically, if there exists an element with the same name as a bone
  386. // you can get in an infinite loop. Let's just hope nobody's that stupid.
  387. pos, ang = self:GetBoneOrientation( basetab, v, ent )
  388.  
  389. if (!pos) then return end
  390.  
  391. pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  392. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  393. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  394. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  395.  
  396. else
  397.  
  398. bone = ent:LookupBone(bone_override or tab.bone)
  399.  
  400. if (!bone) then return end
  401.  
  402. pos, ang = Vector(0,0,0), Angle(0,0,0)
  403. local m = ent:GetBoneMatrix(bone)
  404. if (m) then
  405. pos, ang = m:GetTranslation(), m:GetAngles()
  406. end
  407.  
  408. if (IsValid(self.Owner) and self.Owner:IsPlayer() and
  409. ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
  410. ang.r = -ang.r // Fixes mirrored models
  411. end
  412.  
  413. end
  414.  
  415. return pos, ang
  416. end
  417.  
  418. function SWEP:CreateModels( tab )
  419.  
  420. if (!tab) then return end
  421.  
  422. // Create the clientside models here because Garry says we can't do it in the render hook
  423. for k, v in pairs( tab ) do
  424. if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
  425. string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
  426.  
  427. v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  428. if (IsValid(v.modelEnt)) then
  429. v.modelEnt:SetPos(self:GetPos())
  430. v.modelEnt:SetAngles(self:GetAngles())
  431. v.modelEnt:SetParent(self)
  432. v.modelEnt:SetNoDraw(true)
  433. v.createdModel = v.model
  434. else
  435. v.modelEnt = nil
  436. end
  437.  
  438. elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  439. and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
  440.  
  441. local name = v.sprite.."-"
  442. local params = { ["$basetexture"] = v.sprite }
  443. // make sure we create a unique name based on the selected options
  444. local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  445. for i, j in pairs( tocheck ) do
  446. if (v[j]) then
  447. params["$"..j] = 1
  448. name = name.."1"
  449. else
  450. name = name.."0"
  451. end
  452. end
  453.  
  454. v.createdSprite = v.sprite
  455. v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  456.  
  457. end
  458. end
  459.  
  460. end
  461.  
  462. local allbones
  463. local hasGarryFixedBoneScalingYet = false
  464.  
  465. function SWEP:UpdateBonePositions(vm)
  466.  
  467. if self.ViewModelBoneMods then
  468.  
  469. if (!vm:GetBoneCount()) then return end
  470.  
  471. // !! WORKAROUND !! //
  472. // We need to check all model names :/
  473. local loopthrough = self.ViewModelBoneMods
  474. if (!hasGarryFixedBoneScalingYet) then
  475. allbones = {}
  476. for i=0, vm:GetBoneCount() do
  477. local bonename = vm:GetBoneName(i)
  478. if (self.ViewModelBoneMods[bonename]) then
  479. allbones[bonename] = self.ViewModelBoneMods[bonename]
  480. else
  481. allbones[bonename] = {
  482. scale = Vector(1,1,1),
  483. pos = Vector(0,0,0),
  484. angle = Angle(0,0,0)
  485. }
  486. end
  487. end
  488.  
  489. loopthrough = allbones
  490. end
  491. // !! ----------- !! //
  492.  
  493. for k, v in pairs( loopthrough ) do
  494. local bone = vm:LookupBone(k)
  495. if (!bone) then continue end
  496.  
  497. // !! WORKAROUND !! //
  498. local s = Vector(v.scale.x,v.scale.y,v.scale.z)
  499. local p = Vector(v.pos.x,v.pos.y,v.pos.z)
  500. local ms = Vector(1,1,1)
  501. if (!hasGarryFixedBoneScalingYet) then
  502. local cur = vm:GetBoneParent(bone)
  503. while(cur >= 0) do
  504. local pscale = loopthrough[vm:GetBoneName(cur)].scale
  505. ms = ms * pscale
  506. cur = vm:GetBoneParent(cur)
  507. end
  508. end
  509.  
  510. s = s * ms
  511. // !! ----------- !! //
  512.  
  513. if vm:GetManipulateBoneScale(bone) != s then
  514. vm:ManipulateBoneScale( bone, s )
  515. end
  516. if vm:GetManipulateBoneAngles(bone) != v.angle then
  517. vm:ManipulateBoneAngles( bone, v.angle )
  518. end
  519. if vm:GetManipulateBonePosition(bone) != p then
  520. vm:ManipulateBonePosition( bone, p )
  521. end
  522. end
  523. else
  524. self:ResetBonePositions(vm)
  525. end
  526.  
  527. end
  528.  
  529. function SWEP:ResetBonePositions(vm)
  530.  
  531. if (!vm:GetBoneCount()) then return end
  532. for i=0, vm:GetBoneCount() do
  533. vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
  534. vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
  535. vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
  536. end
  537.  
  538. end
  539.  
  540. /**************************
  541. Global utility code
  542. **************************/
  543.  
  544. // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
  545. // Does not copy entities of course, only copies their reference.
  546. // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
  547. function table.FullCopy( tab )
  548.  
  549. if (!tab) then return nil end
  550.  
  551. local res = {}
  552. for k, v in pairs( tab ) do
  553. if (type(v) == "table") then
  554. res[k] = table.FullCopy(v) // recursion ho!
  555. elseif (type(v) == "Vector") then
  556. res[k] = Vector(v.x, v.y, v.z)
  557. elseif (type(v) == "Angle") then
  558. res[k] = Angle(v.p, v.y, v.r)
  559. else
  560. res[k] = v
  561. end
  562. end
  563.  
  564. return res
  565.  
  566. end
  567.  
  568. end
  569.  
  570.  
Advertisement
Add Comment
Please, Sign In to add comment