Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. ------------------------------[[ Locals ]]------------------------------
  2. print("Contraption Cost Loaded")
  3. local floor = math.floor
  4.  
  5. local Classes = {}
  6. local PhysgunCont = {}
  7.  
  8. local function AddClass(Class, Name, Function)
  9. if not Class then return end
  10. if not isfunction(Function) then return end
  11.  
  12. Classes[Class] = {
  13. Name = Name,
  14. Func = Function
  15. }
  16. end
  17.  
  18. local function GetClassData(Entity)
  19. local PhysObj = Entity:GetPhysicsObject()
  20. local Data = Classes[Entity:GetClass()] or Classes.Default
  21.  
  22. if not IsValid(PhysObj) then return 0, Data.Name end
  23.  
  24. return Data.Func(PhysObj:GetMass()), Data.Name
  25. end
  26.  
  27. local function GetViewContraption(Player)
  28. local Ent = Player:GetEyeTrace().Entity
  29. local Cont = cframe.Get(Ent)
  30. local PhysEnts = cframe.GetPhysicalEntities(Ent)
  31.  
  32. return PhysEnts[Ent] and Cont
  33. end
  34.  
  35. local function DespawnContraption(Contraption)
  36. local Entities = cframe.GetPhysicalEntities(Contraption)
  37.  
  38. for K in pairs(Entities) do
  39. K:Remove()
  40. end
  41. end
  42.  
  43. ------------------------------[[ CFrame Hooks ]]------------------------------
  44.  
  45. hook.Add("CFrame InitEntity", "Failz DarkRP", function(Entity)
  46. local Cost, Name = GetClassData(Entity)
  47.  
  48. if Name then
  49. --print("[Debug] Spawned " .. Name .. " with cost $" .. Cost)
  50. end
  51.  
  52. Entity.CFWRK.DarkRP = {
  53. Cost = Cost
  54. }
  55. end)
  56.  
  57. hook.Add("CFrame Create", "Failz DarkRP", function(Contraption)
  58. Contraption.DarkRP = {
  59. Cost = 0,
  60. Frozen = {
  61. Count = 0,
  62. Ents = {}
  63. }
  64. }
  65. end)
  66.  
  67. hook.Add("CFrame Connect", "Failz DarkRP", function(Contraption, Entity)
  68. local Data = Contraption.DarkRP
  69. local Cost = cframe.GetCost(Entity)
  70.  
  71. Data.Cost = Data.Cost + Cost
  72. end)
  73.  
  74. hook.Add("CFrame Disconnect", "Failz DarkRP", function(Contraption, Entity)
  75. local Data = Contraption.DarkRP
  76. local Cost = cframe.GetCost(Entity)
  77.  
  78. Data.Cost = Data.Cost - Cost
  79. end)
  80.  
  81. ------------------------------[[ AdvDupe2 Hooks ]]------------------------------
  82.  
  83. hook.Add("AdvDupe_FinishPasting", "Failz DarkRP", function(Data)
  84. local Entities = Data[1].CreatedEntities
  85. local Contraptions = {}
  86.  
  87. for _, V in pairs(Entities) do
  88. local CF = cframe.Get(V)
  89.  
  90. if CF and not Contraptions[CF] then
  91. Contraptions[CF] = true
  92. end
  93. end
  94.  
  95. for K in pairs(Contraptions) do
  96. local Count = K.Ents.Count
  97. local Cost = floor(cframe.GetCost(K))
  98.  
  99. K.DarkRP.Spawned = true
  100.  
  101. --print("Spawned contraption with " .. Count .. " entities and a cost of $" .. Cost)
  102. end
  103. end)
  104.  
  105. ------------------------------[[ Garrysmod Hooks ]]------------------------------
  106.  
  107. hook.Add("OnPhysgunPickup", "Failz DarkRP", function(Player, Entity)
  108. local Cont = cframe.Get(Entity)
  109. local PhysEnts = cframe.GetPhysicalEntities(Entity)
  110.  
  111. if Cont and PhysEnts[Entity] then
  112. PhysgunCont[Player] = Cont
  113. end
  114. end)
  115.  
  116. hook.Add("PhysgunDrop", "Failz DarkRP", function(Player)
  117. if PhysgunCont[Player] then
  118. PhysgunCont[Player] = nil
  119. end
  120. end)
  121.  
  122. local function DespawnContraption(Contraption)
  123. local Entities = cframe.GetPhysicalEntities(Contraption)
  124.  
  125. for K in pairs(Entities) do
  126. K:Remove()
  127. end
  128. end
  129.  
  130. hook.Add("OnPhysgunReload", "Failz DarkRP", function(_, Player)
  131. local Cont = PhysgunCont[Player] or GetViewContraption(Player)
  132.  
  133. if Cont and Cont.DarkRP.Spawned and not Cont.DarkRP.Unfrozen then
  134. local Cost = floor(cframe.GetCost(Cont))
  135.  
  136. Cont.DarkRP.Unfrozen = true
  137. PhysgunCont[Player] = nil
  138.  
  139. local finalweight = Cont.Mass.Total
  140.  
  141. if finalweight < 10000 then
  142.  
  143. Cost = Cost * 0.5
  144. elseif finalweight >= 10000 and finalweight < 20000 then
  145. Cost = Cost * 1.3
  146.  
  147. elseif finalweight >= 20000 and finalweight < 30000 then
  148. Cost = Cost * 1.7
  149. elseif finalweight >= 30000 and finalweight < 40000 then
  150. Cost = Cost * 3
  151.  
  152. elseif finalweight >= 40000 and finalweight < 50000 then
  153. Cost = Cost * 4.5
  154.  
  155. elseif finalweight >= 50000 then
  156. Cost = Cost * 6
  157.  
  158.  
  159. end
  160.  
  161. Player:PrintMessage(HUD_PRINTTALK, "Unfroze a contraption with a cost of $" .. Cost)
  162. Player:PrintMessage(HUD_PRINTTALK, "You have 10 seconds to remove it or you pay for it.")
  163. Player:PrintMessage(HUD_PRINTCENTER, "You have 10 seconds to remove it or you pay for it.")
  164.  
  165.  
  166.  
  167.  
  168. timer.Simple(10, function()
  169. if not Cont.IsContraption then return end
  170.  
  171. end)
  172. end
  173. end)
  174.  
  175. hook.Add("Initialize", "Failz DarkRP", function()
  176. local Meta = FindMetaTable("PhysObj")
  177. Meta.LegacyMotion = Meta.EnableMotion
  178.  
  179. -- Note: OnPhysgunPickup doesn't use this
  180. function Meta:EnableMotion(Enabled)
  181. if IsValid(self) then
  182. local CF = cframe.Get(self:GetEntity())
  183.  
  184. if CF then
  185. --local Data = CF.DarkRP
  186. --print(self, Enabled)
  187. end
  188. end
  189.  
  190. self:LegacyMotion(Enabled)
  191. end
  192.  
  193. hook.Remove("Initialize", "Failz DarkRP")
  194. end)
  195.  
  196. ------------------------------[[ Library Functions ]]------------------------------
  197.  
  198. -- Handy function to get either an entity's cost or a whole contraption's cost
  199. function cframe.GetCost(Var)
  200. if not Var then return 0 end
  201.  
  202. if Var.IsContraption then
  203. return Var.DarkRP.Cost
  204. elseif Var.CFWRK then
  205. return Var.CFWRK.DarkRP.Cost
  206. else
  207. return 0
  208. end
  209. end
  210.  
  211. ------------------------------[[ Cost Math Fun ]]------------------------
  212. function contrapmass2cost(weight)
  213.  
  214. return 1 * (weight)
  215.  
  216. end
  217.  
  218. ------------------------------[[ Classes ]]------------------------------
  219.  
  220. AddClass("Default", nil, function(Mass) return Mass end)
  221. AddClass("gmod_wire_expression2", "e2", function() return 100 end)
  222. AddClass("acf_engine", "engine", function(Mass) return 150 + 0.15 * Mass end)
  223. AddClass("acf_gearbox", "gearbox", function(Mass) return 50 + 0.25 * Mass end)
  224. AddClass("acf_fueltank", "fuel", function(Mass) return 0.2 * Mass end)
  225. AddClass("acf_gun", "gun", function(Mass) return 1 * Mass end)
  226. AddClass("acf_rack", "missile", function(Mass) return 3.5 * Mass end)
  227. AddClass("acf_radar", "radar", function(Mass) return 1 * Mass end)
  228. AddClass("acf_ammo", "ammo", function(Mass) return 0.5 * Mass end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement