Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make players only be able to build in a certain area?

Asked by 8 years ago

So I have city type game. One feature is where users can freely build their houses.

Everything works. Users can get items from the shop, place them, rotate, etc. The only thing is, they can do this to other peoples house too.

How can I create a script that will only let users build/delete, etc. in their own house, or claimed land?

When a user selects an item, I want that item only to be placed in their claimed area, not go off into someone else's.

0
Check the items position, and whether it (-1/2 of it's size) would work on top of a floor brick, then it can be placed. Scarious 243 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

Taryo has the right idea. When you're looking to see if an object is within the bounds which they can build within, look to see if the centre of the asset (The Position, for Parts) is within the bounds of the given plot.

You may also want to consider checking the bounding corners of the asset rather than just the Position of it. To get the bounding corners, you can do

local Position = asset.Position; -- Only for Parts
local Size = asset.Size; -- Also only for Parts.
local Corner1 = Position-Size/2
local Corner2 = Position+Size/2
-- Now check if both Corners are within the boundaries.
Ad
Log in to vote
1
Answered by
Scarious 243 Moderation Voter
8 years ago

Alright, in order to go about this, we first must know the fundamentals of a part, or.. in otherwords, where it's position is stated.

A part's position is the middle of the part... in otherwords, any sides position, subtracted by half of the part's size on that axis.

In order to see whether it should be able to be placed, we will create a function, but also have a table to check whether any of these parts can be added.

function check(model,player,location)
end

Here, we have created a function, it will check the model's parts, the player who owns a lot, and the location of all the parts they can build above.

Now, we must get all the models parts, and check for all of the locations available build areas...

function check(model,player,location)
    for index,parttocheck in ipairs(model:GetChildren()) do
        for index2,locationtocheck inipairs(location:GetChildren()) do
            -- Now we must check all the sides of the part to see whether they can go on it... to do this, you will check the x and y coordinates.
        end
    end
end

If you need help on checking the x and y coordinates of the parttocheck variable, and the locationtocheck variable, I can help... just ask. ;)

ELunate has given a great explanation on how to do this though, check her explanation out!

Make sure to accept and upvote this if I helped you!

Thanks, Taryo

Answer this question