Advertisement
Guest User

Untitled

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