Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------[[ Locals ]]------------------------------
- print("Contraption Cost Loaded")
- local floor = math.floor
- local Classes = {}
- local PhysgunCont = {}
- local function AddClass(Class, Name, Function)
- if not Class then return end
- if not isfunction(Function) then return end
- Classes[Class] = {
- Name = Name,
- Func = Function
- }
- end
- local function GetClassData(Entity)
- local PhysObj = Entity:GetPhysicsObject()
- local Data = Classes[Entity:GetClass()] or Classes.Default
- if not IsValid(PhysObj) then return 0, Data.Name end
- return Data.Func(PhysObj:GetMass()), Data.Name
- end
- local function GetViewContraption(Player)
- local Ent = Player:GetEyeTrace().Entity
- local Cont = cframe.Get(Ent)
- local PhysEnts = cframe.GetPhysicalEntities(Ent)
- return PhysEnts[Ent] and Cont
- end
- local function DespawnContraption(Contraption)
- local Entities = cframe.GetPhysicalEntities(Contraption)
- for K in pairs(Entities) do
- K:Remove()
- end
- end
- ------------------------------[[ CFrame Hooks ]]------------------------------
- hook.Add("CFrame InitEntity", "Failz DarkRP", function(Entity)
- local Cost, Name = GetClassData(Entity)
- if Name then
- --print("[Debug] Spawned " .. Name .. " with cost $" .. Cost)
- end
- Entity.CFWRK.DarkRP = {
- Cost = Cost
- }
- end)
- hook.Add("CFrame Create", "Failz DarkRP", function(Contraption)
- Contraption.DarkRP = {
- Cost = 0,
- Frozen = {
- Count = 0,
- Ents = {}
- }
- }
- end)
- hook.Add("CFrame Connect", "Failz DarkRP", function(Contraption, Entity)
- local Data = Contraption.DarkRP
- local Cost = cframe.GetCost(Entity)
- Data.Cost = Data.Cost + Cost
- end)
- hook.Add("CFrame Disconnect", "Failz DarkRP", function(Contraption, Entity)
- local Data = Contraption.DarkRP
- local Cost = cframe.GetCost(Entity)
- Data.Cost = Data.Cost - Cost
- end)
- ------------------------------[[ AdvDupe2 Hooks ]]------------------------------
- hook.Add("AdvDupe_FinishPasting", "Failz DarkRP", function(Data)
- local Entities = Data[1].CreatedEntities
- local Contraptions = {}
- for _, V in pairs(Entities) do
- local CF = cframe.Get(V)
- if CF and not Contraptions[CF] then
- Contraptions[CF] = true
- end
- end
- for K in pairs(Contraptions) do
- local Count = K.Ents.Count
- local Cost = floor(cframe.GetCost(K))
- K.DarkRP.Spawned = true
- --print("Spawned contraption with " .. Count .. " entities and a cost of $" .. Cost)
- end
- end)
- ------------------------------[[ Garrysmod Hooks ]]------------------------------
- hook.Add("OnPhysgunPickup", "Failz DarkRP", function(Player, Entity)
- local Cont = cframe.Get(Entity)
- local PhysEnts = cframe.GetPhysicalEntities(Entity)
- if Cont and PhysEnts[Entity] then
- PhysgunCont[Player] = Cont
- end
- end)
- hook.Add("PhysgunDrop", "Failz DarkRP", function(Player)
- if PhysgunCont[Player] then
- PhysgunCont[Player] = nil
- end
- end)
- local function DespawnContraption(Contraption)
- local Entities = cframe.GetPhysicalEntities(Contraption)
- for K in pairs(Entities) do
- K:Remove()
- end
- end
- hook.Add("OnPhysgunReload", "Failz DarkRP", function(_, Player)
- local Cont = PhysgunCont[Player] or GetViewContraption(Player)
- if Cont and Cont.DarkRP.Spawned and not Cont.DarkRP.Unfrozen then
- local Cost = floor(cframe.GetCost(Cont))
- Cont.DarkRP.Unfrozen = true
- PhysgunCont[Player] = nil
- local finalweight = Cont.Mass.Total
- if finalweight < 10000 then
- Cost = Cost * 0.5
- elseif finalweight >= 10000 and finalweight < 20000 then
- Cost = Cost * 1.3
- elseif finalweight >= 20000 and finalweight < 30000 then
- Cost = Cost * 1.7
- elseif finalweight >= 30000 and finalweight < 40000 then
- Cost = Cost * 3
- elseif finalweight >= 40000 and finalweight < 50000 then
- Cost = Cost * 4.5
- elseif finalweight >= 50000 then
- Cost = Cost * 6
- end
- Player:PrintMessage(HUD_PRINTTALK, "Unfroze a contraption with a cost of $" .. Cost)
- Player:PrintMessage(HUD_PRINTTALK, "You have 10 seconds to remove it or you pay for it.")
- Player:PrintMessage(HUD_PRINTCENTER, "You have 10 seconds to remove it or you pay for it.")
- timer.Simple(10, function()
- if not Cont.IsContraption then return end
- end)
- end
- end)
- hook.Add("Initialize", "Failz DarkRP", function()
- local Meta = FindMetaTable("PhysObj")
- Meta.LegacyMotion = Meta.EnableMotion
- -- Note: OnPhysgunPickup doesn't use this
- function Meta:EnableMotion(Enabled)
- if IsValid(self) then
- local CF = cframe.Get(self:GetEntity())
- if CF then
- --local Data = CF.DarkRP
- --print(self, Enabled)
- end
- end
- self:LegacyMotion(Enabled)
- end
- hook.Remove("Initialize", "Failz DarkRP")
- end)
- ------------------------------[[ Library Functions ]]------------------------------
- -- Handy function to get either an entity's cost or a whole contraption's cost
- function cframe.GetCost(Var)
- if not Var then return 0 end
- if Var.IsContraption then
- return Var.DarkRP.Cost
- elseif Var.CFWRK then
- return Var.CFWRK.DarkRP.Cost
- else
- return 0
- end
- end
- ------------------------------[[ Cost Math Fun ]]------------------------
- function contrapmass2cost(weight)
- return 1 * (weight)
- end
- ------------------------------[[ Classes ]]------------------------------
- AddClass("Default", nil, function(Mass) return Mass end)
- AddClass("gmod_wire_expression2", "e2", function() return 100 end)
- AddClass("acf_engine", "engine", function(Mass) return 150 + 0.15 * Mass end)
- AddClass("acf_gearbox", "gearbox", function(Mass) return 50 + 0.25 * Mass end)
- AddClass("acf_fueltank", "fuel", function(Mass) return 0.2 * Mass end)
- AddClass("acf_gun", "gun", function(Mass) return 1 * Mass end)
- AddClass("acf_rack", "missile", function(Mass) return 3.5 * Mass end)
- AddClass("acf_radar", "radar", function(Mass) return 1 * Mass end)
- AddClass("acf_ammo", "ammo", function(Mass) return 0.5 * Mass end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement