Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onLoad()
- CreateButton()
- enabled = false
- end
- function CreateButton()
- local btn = self.createButton({
- click_function = "ToggleLock",
- function_owner = self,
- position = {-1.75, 0.05, -1.7},
- width = 160,
- height = 160,
- font_size = 64,
- label = "x"
- })
- end
- function ToggleLock()
- enabled = not enabled
- print(enabled and "enabled" or "disabled")
- if not enabled then
- self.removeAttachments()
- end
- if enabled then
- local objects = FindObjects()
- AttachObjects(objects)
- end
- end
- function FindObjects()
- local size = self.getBounds().size
- local pos = self.getPosition()
- local hitList = Physics.cast({
- origin = {pos.x, pos.y + size.y, pos.z},
- direction = {0,1,0},
- type = 3,
- size = {size.x,1,size.z},
- max_distance = 0,
- debug = true,
- })
- local result = {}
- for _, obj in ipairs(hitList) do
- if obj.hit_object and obj.hit_object.guid and obj.hit_object ~= self then
- if obj.hit_object.GetPosition().y > pos.y then
- table.insert(result, obj.hit_object)
- end
- end
- end
- return result
- end
- function AttachObjects(objects)
- for _, obj in ipairs(objects) do
- self.addAttachment(obj)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment