eprosync

MWB - Modular Attachments

Mar 5th, 2021 (edited)
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.     Regarding stackability
  3.  
  4.     Stacking attachment should be ok as long as those
  5.     who make the attachments follow the guidlines
  6.  
  7.     Also to note, the people who modify the guns through here are
  8.     held responsible on account of the person/community using the addon.
  9.    
  10.     DO NOT COME TO ME FOR HELP IF THE ATTACHMENT ISN'T EVEN MINE.
  11.     If you need help understanding the attachment system, you may do so.
  12. ]]
  13. ATTACHMENT.Name = 'BasicAtt'
  14. ATTACHMENT.Class = 'default_att'
  15. ATTACHMENT.Trivia = [[Just a basic attachment, duh]]
  16. ATTACHMENT.Icon = "icon16/picture_empty.png"
  17. ATTACHMENT.Spawnable = false -- Should it become an entity that is spawnable? (Auto generated)
  18. ATTACHMENT.Hidden = true -- Hide from the attachment menu (Basically unobtainable)
  19.  
  20. --[[
  21.     This is relative to the model of the gun.
  22.     This means within the editor, this should be specified as an attachable region.
  23.     This allows virutally any attachment to be attachable to that point.
  24.     Information such as scale and size is given out from the editor to scale up or
  25.     scale down the attachment to the gun's desired size.
  26.  
  27.     I STRONGLY RECOMMEND YOU USE A MODEL THAT SHOWS DIRECTIONS
  28.     such as "models/maxofs2d/cube_tool.mdl"
  29.     which is used for finding out what direction your facing the object.
  30. ]]
  31. ATTACHMENT.Attachables = {
  32.     "default__" -- This must exist in the gun's lua generated model to be an attachable region
  33. }
  34.  
  35. --[[
  36.     Put all your models in here to be added to the attachable area
  37.  
  38.     Attachment system will automatically scale up/down any model for every gun's attachment specification.
  39.     Making it easier for all modelers to make attachments for all guns.
  40.  
  41.     I need to find a way to scale down animation positions...
  42. ]]
  43. ATTACHMENT.Models = {
  44.     ['VM'] = {},
  45.     ['WM'] = {}
  46. }
  47.  
  48. -- Overrides "Attachables" to a different region
  49. ATTACHMENT.Models_VM_Attach = "default__region"
  50. ATTACHMENT.Models_WM_Attach = "default__region"
  51.  
  52. --[[
  53.     Modify models by their name
  54.     So let's say you wanted to change the HitMarker to be hidden.
  55.     To do so, just look down here.
  56.  
  57.     you can use the name, uid, or even the bone.
  58.     as defined in order by "name", "uid" and "bone"
  59. ]]
  60. ATTACHMENT.Models_Modify = {
  61.     ['VM'] = {
  62.         {name = 'HitMarker', effects = {
  63.             ['Hide'] = true,
  64.         }}
  65.     },
  66.     ['WM'] = {}
  67. }
  68.  
  69. --[[
  70.     Simple modification kit for players to play with.
  71.     Basically this will allow clients to modify their attachments.
  72.     For example, lets say you wanted to change the color of the reticle?
  73.     Or you wanted to change a variable stock?
  74.     This allows you to expand upon creativity.
  75.  
  76.     This data is stored in "AttachmentMetaData".
  77. ]]
  78. ATTACHMENT.Modify = {
  79.     {
  80.         Name = "Color",
  81.         Type = TYPE_COLOR,
  82.         Min = Color(0,0,0,255),
  83.         Max = Color(255,255,255,255),
  84.         Verify = function(self, uid, old, new)
  85.             if new < 0 or new > 255 then return false end
  86.             return true
  87.         end,
  88.         PreApply = function(self, uid, old, new)
  89.  
  90.         end,
  91.         ShouldReloadModels = function(self, uid, value)
  92.             return false
  93.         end,
  94.         PostApply = function(self, uid, old, new)
  95.             local object = self:GetModelByUID(VM, MWB.IndexToModelUID(uid) .. ".SomeID")
  96.             object.Color = new
  97.         end,
  98.     },
  99.     {
  100.         Name = "Size",
  101.         Type = TYPE_NUMBER,
  102.         Min = .5,
  103.         Max = 2,
  104.         Verify = function(self, uid, old, new)
  105.             if new < .5 or new > 2 then return false end
  106.             return true
  107.         end,
  108.         PreApply = function(self, uid, old, new)
  109.  
  110.         end,
  111.         ShouldReloadModels = function(self, uid, value)
  112.             return false
  113.         end,
  114.         PostApply = function(self, uid, old, new)
  115.             local object = self:GetModelByUID(VM, MWB.IndexToModelUID(uid) .. ".SomeID")
  116.             object.Size = new
  117.             object:Reconstruct()
  118.         end,
  119.     }
  120. }
  121.  
  122. --[[
  123.     I have not planned this out yet... But meh, I will eventually
  124.     Supposed to be some plans with my IK system to be auto intigrated here...
  125. ]]
  126. ATTACHMENT.Animations = {
  127.     ['VM'] = {},
  128.     ['WM'] = {}
  129. }
  130.  
  131. --[[
  132.     Basically, what this will do is grab all the bones from the attachment.
  133.     Compare the bones to it...
  134.     And then move the bones towards the attachment to be relative to it.
  135.     This works in conjuction with IK system for c_arms.
  136.     Pretty much only moving the hands to the position and letting the arms be calculated via Inverse Kinematics.
  137. ]]
  138. ATTACHMENT.BoneMergeRecalibration = false
  139. -- Recalibrates the bone positions to be relative to the bonemerge of the arms
  140. -- This can be done multiple times, just be warned that stacking same bones will cause issues with pre render processing.
  141. -- WIP, need to design a second hand system to the model processing to allow for modifications with BoneMerge.
  142. ATTACHMENT.BoneMergeTarget = '' -- UID of the object to bone merge towards.
  143.  
  144. -- This is to configure what bones should be where...
  145. ATTACHMENT.BoneMergeConfiguration = {
  146.     ['ValveBiped.Bip01_L_Hand'] = true,
  147. }
  148.  
  149. -- This will disable bonemerge when an animation is being played.
  150. ATTACHMENT.BoneMergeDisableOnAnim = {
  151.     [ACT_VM_RELOAD] = true,
  152.     [ACT_VM_RELOAD_EMPTY] = true,
  153.     [ACT_VM_RELOAD_SILENCED] = true,
  154.     [ACT_VM_RELOAD_SILENCED_EMPTY] = true
  155. }
  156.  
  157. -- Recalibrates the aimposition to be relative to the sight's attachment position and scale.
  158. -- If there seems to be something off, you can blame the guy who made the weapon for that.
  159. -- Do note that the model doesn't have to be 1:1 scale, however it is recommended for weapons that scales their attachment indexes.
  160.  
  161. -- If you don't want to use hardcoded sights, you can use target instead.
  162. -- Input a UniqueID of a pac3 object into there and the sight position will be recalibrated to there instead.
  163. ATTACHMENT.SightRecalibration = false
  164. ATTACHMENT.Sights = {
  165.     {
  166.         Position = Vector(0, 0, 0),
  167.         Angles = Angle(0, 0, 0),
  168.         Target = nil,
  169.     }
  170. }
  171.  
  172. --[[
  173.     The best part yea?
  174.     Modular weapon effects system
  175.     You can modify almost every aspect of the gun through here
  176.     From functions, to vectors and numbers, this becomes your playground, literally...
  177.     Almost all value types are supported, this includes even values that you don't
  178.     use in lua, such as CUserCmd (not sure how you would but yea)
  179.  
  180.     Let's say you wanted to modify something that is inside a table.
  181.     Most weapon bases don't do this, but this one can :D
  182.  
  183.     ATTACHMENT.Effects = {
  184.         ['Primary'] = {
  185.             ['Ammo'] = "9x19MM" -- This will change the weapon's ammo type to use 9x19MM
  186.         }
  187.     }
  188.  
  189.     or you wanted to change a function?
  190.     replacing a function will automatically convert it into an intigrated hook system via hook manager.
  191.     this ensures that if there is stackability in the function, you wont run into issues.
  192.  
  193.     ATTACHMENT.Effects = {
  194.         ['FireBullet'] = function(self, dir)
  195.             return
  196.         end
  197.     }
  198.  
  199.     If this turns out to be troublesome, there is an attachment callback system bellow all of this
  200. ]]
  201. ATTACHMENT.Effects = {}
  202.  
  203. --[[
  204.     Conditions are used to define how the effects will be added to a gun
  205.     This only for vectors, angles and numbers
  206.     In this case, "mul" means multiply and "add" is just addition
  207.  
  208.     Conditions goes as follows
  209.         set - set a value
  210.         mul - multiplies value
  211.         add - adds to the value
  212.  
  213.     These are only for things like, numbers, vectors and angles.
  214.     They follow an applying order of "set" -> "mul" -> "add"
  215.     This is to prevent conflicting modifications of the weapons.
  216.  
  217.     So let's say we want to multiply the damage
  218.     ATTACHMENT.Effects = {
  219.         ['MaxDamage'] = 2
  220.     }
  221.  
  222.     This would be the condition
  223.     ATTACHMENT.Conditions = {
  224.         ['MaxDamage'] = 'mul'
  225.     }
  226. ]]
  227. ATTACHMENT.Conditions = {}
  228.  
  229. --[[
  230.     Simple pros and cons stuff.
  231.     Just input what you want in there and it will show up as either positive or negative
  232. ]]
  233. ATTACHMENT.ProsCons = {
  234.     Pros = [[]],
  235.     Cons = [[]],
  236.     Infos = [[]]
  237. }
  238.  
  239. --[[
  240.     These are callbacks for the attachment when being added/removed.
  241.     Use these to your advantage if the effects system isn't enough.
  242.  
  243.     For those who are still trying to grasp "pre" vs "post"
  244.     pre - means before the operation of attaching
  245.     post - means after the effects/etc has been attached/overwritten
  246.  
  247.     I suggest doing this for the hook system as well
  248.     Such as
  249.     self:AddHook(hook, identifier, function(self, ...) end)
  250.     self:RemoveHook(hook, identifier)
  251.  
  252.     This will allow you to modify the gun to the core, and even the dynamic bullet system.
  253.     Let's say, you wanted to change the color of the bullet? :)
  254.  
  255.     Please understand these are called both Client and Server realms.
  256.  
  257.     self is basically the weapon entity
  258.     uid is a bit special as it acts as 3 things.
  259.     1. Identification of the attachment location (like is it index 1, 2 or 3 for example)
  260.     2. Identification of models being added so that you can modify them (use self:UIDToModelLoc(string))
  261.         This returns a string of the exact attachment coordinates you are looking for to modify.
  262.     3. A unique identifier for hooks
  263. ]]
  264. ATTACHMENT.PreAttach = function(self, uid) end
  265. ATTACHMENT.PostAttach = function(self, uid) end
  266.  
  267. ATTACHMENT.PreDetach = function(self, uid) end
  268. ATTACHMENT.PostDetach = function(self, uid) end
RAW Paste Data