Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {}
- buttonapis = {}
- bfunctions = {}
- local co
- local running = false
- --Creates a button-- Returns: Success (true/false)
- function buttonapis.addButton(x1,y1,x2,y2,func,button)
- button = button or 1
- if button == 1 or button == 2 or button == 3 then
- buttons[func] = {}
- buttons[func]["x1"] = x1
- buttons[func]["y1"] = y1
- buttons[func]["x2"] = x2
- buttons[func]["y2"] = y2
- buttons[func]["button"] = button
- return true
- end
- return false
- end
- --Removes a button--
- function buttonapis.removeButton(buttonN)
- buttons[buttonN] = nil
- end
- function buttonapis.clearButtons()
- buttons = {}
- end
- function buttonapis.removeFunction(func)
- bfunctions[func] = nil
- end
- function buttonapis.clearFunctions()
- bfunctions = {}
- end
- --Starts Button Detection--Automatically Run--
- function buttonapis.startLoop()
- running = true
- while true do
- if running then
- local e,b,x,y = os.pullEvent("mouse_click")
- for i,v in pairs(buttons)do
- if b == v["button"] and x >= v["x1"] and x <= v["x2"] and y >= v["y1"] and y <= v["y2"] then
- if bfunctions[i] then
- bfunctions[i](x,y,i)
- end
- end
- end
- end
- sleep(0)
- end
- end
- function buttonapis.stopLoop()
- running = false
- end
- function buttonapis.resumeLoop()
- running = true
- end
Advertisement
Add Comment
Please, Sign In to add comment