Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.40 KB | None | 0 0
  1. local function canPlaceObject(plr, objectName, pos)
  2.     pos = translateToGrid(pos)
  3.    
  4.     local unit = config.unitSize.Value
  5.     local rectSide = config.tycoonUnitRectSide.Value
  6.    
  7.     if not buildings:FindFirstChild(objectName) then
  8.         -- why isn't it in there wat
  9.         return false, "[debug] "..objectName.." was not found in buildings, are you exploiting?"
  10.     end
  11.    
  12.     local obj = buildings[objectName]
  13.    
  14.     if not playerData[plr].inventory[objectName] then
  15.         -- they don't own any of that how did they do that xd
  16.         return false, "[debug] you don't own any "..objectName.."'s, are you exploiting?"
  17.     end
  18.    
  19.     if objectName ~= "baseCore" and not tycoons[plr]:FindFirstChild("baseCore") then
  20.         -- trying to place something else when they dont have their core down
  21.         return false, "[debug] you haven't placed your core down yet, are you exploiting?"
  22.     end
  23.    
  24.     if playerData[plr].inventory.baseCore and objectName == "baseCore" then
  25.         -- check to make sure it is not within someone's territory
  26.         for plrKey, v in next, tycoons do
  27.             -- make sure ur not checking own tycoon cuz that baka and also make sure they have core
  28.             if plrKey ~= plr and v:FindFirstChild("baseCore") then
  29.                 local corePos = v.baseCore.PrimaryPart.Position
  30.                
  31.                 local isWithinBounds =
  32.                     (
  33.                         (pos.X + obj.PrimaryPart.Size.X/2 <= corePos.X + rectSide*unit/2)
  34.                         and
  35.                         (pos.X  - obj.PrimaryPart.Size.X/2 >= corePos.X - rectSide*unit/2)
  36.                     )
  37.                     and
  38.                     (
  39.                         (pos.Z + obj.PrimaryPart.Size.Z/2 <= corePos.Z + rectSide*unit/2)
  40.                         and
  41.                         (pos.Z - obj.PrimaryPart.Size.Z/2 >= corePos.Z - rectSide*unit/2)
  42.                     )
  43.                
  44.                 if isWithinBounds then
  45.                     return false, "You are within the bounds of someone else's tycoon!"
  46.                 end
  47.             end
  48.         end
  49.         return true, "You can place your core!"
  50.     elseif not playerData[plr].inventory.baseCore and objectName == "baseCore" then
  51.         return false, "[debug] you've already placed your core but you're trying to place another, are you exploiting?"
  52.     end
  53.    
  54.     -- So if they got this far they passed the safety checks and it's not their core then:
  55.     -- We can also assume that all of the cores are correctly placed
  56.    
  57.     local corePos = tycoons[plr].baseCore.PrimaryPart.Position
  58.     for plrKey, v in next, tycoons do
  59.     -- make sure ur not checking own tycoon cuz that baka and also make sure they have core
  60.         if plrKey ~= plr and v:FindFirstChild("baseCore") then
  61.             local corePos = v.baseCore.PrimaryPart.Position
  62.            
  63.             local isWithinBounds =
  64.                 (
  65.                     (pos.X + obj.PrimaryPart.Size.X/2 <= corePos.X + rectSide*unit/2)
  66.                     and
  67.                     (pos.X  - obj.PrimaryPart.Size.X/2 >= corePos.X - rectSide*unit/2)
  68.                 )
  69.                 and
  70.                 (
  71.                     (pos.Z + obj.PrimaryPart.Size.Z/2 <= corePos.Z + rectSide*unit/2)
  72.                     and
  73.                     (pos.Z - obj.PrimaryPart.Size.Z/2 >= corePos.Z - rectSide*unit/2)
  74.                 )
  75.            
  76.             if isWithinBounds then
  77.                 return false, "You are within the bounds of someone else's tycoon!"
  78.             end
  79.         end
  80.     end
  81.    
  82.     local isWithinBounds =
  83.         (
  84.             (pos.X + obj.PrimaryPart.Size.X/2 <= corePos.X + rectSide*unit/2)
  85.             and
  86.             (pos.X  - obj.PrimaryPart.Size.X/2 >= corePos.X - rectSide*unit/2)
  87.         )
  88.         and
  89.         (
  90.             (pos.Z + obj.PrimaryPart.Size.Z/2 <= corePos.Z + rectSide*unit/2)
  91.             and
  92.             (pos.Z - obj.PrimaryPart.Size.Z/2 >= corePos.Z - rectSide*unit/2)
  93.         )
  94.  
  95.     if isWithinBounds then
  96.         return true, "You can place this!"
  97.     else
  98.         return false, "You are not within the bounds of your own tycoon!"
  99.     end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement