Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function canPlaceObject(plr, objectName, pos)
- pos = translateToGrid(pos)
- local unit = config.unitSize.Value
- local rectSide = config.tycoonUnitRectSide.Value
- if not buildings:FindFirstChild(objectName) then
- -- why isn't it in there wat
- return false, "[debug] "..objectName.." was not found in buildings, are you exploiting?"
- end
- local obj = buildings[objectName]
- if not playerData[plr].inventory[objectName] then
- -- they don't own any of that how did they do that xd
- return false, "[debug] you don't own any "..objectName.."'s, are you exploiting?"
- end
- if objectName ~= "baseCore" and not tycoons[plr]:FindFirstChild("baseCore") then
- -- trying to place something else when they dont have their core down
- return false, "[debug] you haven't placed your core down yet, are you exploiting?"
- end
- if playerData[plr].inventory.baseCore and objectName == "baseCore" then
- -- check to make sure it is not within someone's territory
- for plrKey, v in next, tycoons do
- -- make sure ur not checking own tycoon cuz that baka and also make sure they have core
- if plrKey ~= plr and v:FindFirstChild("baseCore") then
- local corePos = v.baseCore.PrimaryPart.Position
- local isWithinBounds =
- (
- (pos.X + obj.PrimaryPart.Size.X/2 <= corePos.X + rectSide*unit/2)
- and
- (pos.X - obj.PrimaryPart.Size.X/2 >= corePos.X - rectSide*unit/2)
- )
- and
- (
- (pos.Z + obj.PrimaryPart.Size.Z/2 <= corePos.Z + rectSide*unit/2)
- and
- (pos.Z - obj.PrimaryPart.Size.Z/2 >= corePos.Z - rectSide*unit/2)
- )
- if isWithinBounds then
- return false, "You are within the bounds of someone else's tycoon!"
- end
- end
- end
- return true, "You can place your core!"
- elseif not playerData[plr].inventory.baseCore and objectName == "baseCore" then
- return false, "[debug] you've already placed your core but you're trying to place another, are you exploiting?"
- end
- -- So if they got this far they passed the safety checks and it's not their core then:
- -- We can also assume that all of the cores are correctly placed
- local corePos = tycoons[plr].baseCore.PrimaryPart.Position
- for plrKey, v in next, tycoons do
- -- make sure ur not checking own tycoon cuz that baka and also make sure they have core
- if plrKey ~= plr and v:FindFirstChild("baseCore") then
- local corePos = v.baseCore.PrimaryPart.Position
- local isWithinBounds =
- (
- (pos.X + obj.PrimaryPart.Size.X/2 <= corePos.X + rectSide*unit/2)
- and
- (pos.X - obj.PrimaryPart.Size.X/2 >= corePos.X - rectSide*unit/2)
- )
- and
- (
- (pos.Z + obj.PrimaryPart.Size.Z/2 <= corePos.Z + rectSide*unit/2)
- and
- (pos.Z - obj.PrimaryPart.Size.Z/2 >= corePos.Z - rectSide*unit/2)
- )
- if isWithinBounds then
- return false, "You are within the bounds of someone else's tycoon!"
- end
- end
- end
- local isWithinBounds =
- (
- (pos.X + obj.PrimaryPart.Size.X/2 <= corePos.X + rectSide*unit/2)
- and
- (pos.X - obj.PrimaryPart.Size.X/2 >= corePos.X - rectSide*unit/2)
- )
- and
- (
- (pos.Z + obj.PrimaryPart.Size.Z/2 <= corePos.Z + rectSide*unit/2)
- and
- (pos.Z - obj.PrimaryPart.Size.Z/2 >= corePos.Z - rectSide*unit/2)
- )
- if isWithinBounds then
- return true, "You can place this!"
- else
- return false, "You are not within the bounds of your own tycoon!"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement