Advertisement
ChampulseV

EggScript_Format_LuaCode

Apr 14th, 2024 (edited)
9,371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. -- ChampulseV0
  2. -- Last edited on 17/4/24
  3. local function ActivateScripter()
  4.     local Egg_Tool = script.Parent;
  5.     local ServerStorage_EggData = game.ServerStorage:WaitForChild("RareEggs");
  6.     local cooldownActivated = false;
  7.     local eggChildren = ServerStorage_EggData:GetChildren();
  8.     local availableEggs = {
  9.         ["CamoEgg"] = {};
  10.         ["CashEgg"] = {};
  11.         ["ComputerEgg"] = {};
  12.         ["FireplaceEgg"] = {};
  13.         ["MatrixEgg"] = {};
  14.         ["MedicEgg"] = {};
  15.         ["PaintingEgg"] = {};
  16.         ["RobotEgg"] = {};
  17.         ["SuitEgg"] = {};
  18.         ["WorkerEgg"] = {};
  19.         ["CommonEgg1"] = {};
  20.         ["CommonEgg2"] = {};
  21.         ["CommonEgg3"] = {};
  22.         ["CommonEgg4"] = {};
  23.     };
  24.     -- Chances must go in ascending order ( Smallest to Highest );
  25.     local rigged_Chances = { -- egg has to Available in the availableEggs and the maximum chance is 110%
  26.         ["PaintingEgg"] = 5;
  27.         ["FireplaceEgg"] = 15;
  28.         ["MatrixEgg"] = 25;
  29.         ["WorkerEgg"] = 35;
  30.         ["SuitEgg"] = 45;
  31.         ["ComputerEgg"] = 55;
  32.         ["MedicEgg"] = 65;
  33.         ["RobotEgg"] = 75;
  34.         ["CashEgg"] = 85;
  35.         ["CamoEgg"] = 95;
  36.         ["CommonEgg1"] = 105;
  37.         ["CommonEgg2"] = 115;
  38.         ["CommonEgg3"] = 125;
  39.         ["CommonEgg4"] = 135;
  40.     };
  41.     local function CloneEgg_Instructor(Egg_instanceName)
  42.         if cooldownActivated then
  43.             return
  44.         end
  45.         pcall(function()
  46.             local locateAvailableEggData = availableEggs[Egg_instanceName]
  47.             if locateAvailableEggData and not cooldownActivated then
  48.                 cooldownActivated = true;
  49.                 if Egg_Tool:FindFirstChild("Handle") then
  50.                     Egg_Tool.Handle:Destroy();
  51.                 end
  52.                 local NewEgg_Instance = ServerStorage_EggData[Egg_instanceName]:Clone();
  53.                 NewEgg_Instance.Name = "Handle";
  54.                 NewEgg_Instance.Parent = Egg_Tool;
  55.                 wait(0.5);
  56.                 cooldownActivated = false;
  57.             end
  58.         end)
  59.     end
  60.     local function findClosestCalculated_Egg(indicatedChance)
  61.         local chosenEgg = nil
  62.         local minCalcDifference = math.huge
  63.         for _EGG, eggChanceCal in pairs(rigged_Chances) do
  64.             local inDifference = math.abs(indicatedChance - eggChanceCal)
  65.             if inDifference < minCalcDifference then
  66.                 minCalcDifference = inDifference
  67.                 chosenEgg = _EGG
  68.             end
  69.         end
  70.         return chosenEgg;
  71.     end
  72.  
  73.     Egg_Tool.Equipped:Connect(function()
  74.         if cooldownActivated then
  75.             return
  76.         end
  77.         pcall(function()
  78.             if #eggChildren > 0 and not cooldownActivated then
  79.                 local minAndMaxChances = math.random(1, 175);
  80.                 local chosenEgg = findClosestCalculated_Egg(minAndMaxChances)
  81.                 CloneEgg_Instructor(tostring(chosenEgg));
  82.             end
  83.         end)
  84.     end)
  85. end
  86. ActivateScripter();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement