Other Languages Moderators Lord Henry Posted June 12, 2019 Other Languages Moderators Share Posted June 12, 2019 (edited) 2 hours ago, Eficiencia said: entendi no caso false impede que ao clicar no botao a ação seja executada pelo botao e pela janela Isso. Edited June 12, 2019 by Lord Henry Link to comment
Gw8 Posted June 12, 2019 Share Posted June 12, 2019 button = {} button.__index = button function button.create(x,y,w,h,string,font,cr,cg,cb,exeCode) local self = setmetatable({},button) self.x = x self.y = y self.w = w self.h = h self.text = string or "" self.font = font self.cr = cr or 255 self.cg = cg or 255 self.cb = cb or 255 self.state = true self.exeCode = loadstring(exeCode) self.funcClick = function(but,state) self:clickHere(but,state) end addEventHandler("onClientClick",root,self.funcClick) return self end function button:setState(bool) self.state = bool end function button:render() local posX,posY,alpha = self.x,self.y,1 dxDrawRectangle(posX,posY,self.w,self.h,tocolor(0,0,0,35*alpha)) if isMousePosition(posX,posY,self.w,self.h) then dxDrawRectangle(posX,posY,self.w,self.h,tocolor(self.cr,self.cg,self.cb,220*alpha)) dxDrawText(self.text,posX+1,posY+1,posX+self.w+1,posY+self.h+1,tocolor(0,0,0,240*alpha),1,self.font,"center","center",true) dxDrawText(self.text,posX,posY,posX+self.w,posY+self.h,tocolor(255,255,255,240*alpha),1,self.font,"center","center",true) else dxDrawRectangle(posX,posY,self.w,self.h,tocolor(self.cr,self.cg,self.cb,190*alpha)) dxDrawText(self.text,posX+1,posY+1,posX+self.w+1,posY+self.h+1,tocolor(0,0,0,210*alpha),1,self.font,"center","center",true) dxDrawText(self.text,posX,posY,posX+self.w,posY+self.h,tocolor(255,255,255,210*alpha),1,self.font,"center","center",true) end end function button:clickHere(but,_state) local posX,posY = self.x,self.y if isMousePosition(posX,posY,self.w,self.h) and self.state then if but == "left" and _state == "down" then return end self.exeCode() end end function button:destroy() removeEventHandler("onClientClick",root,self.funcClick) if self.parent then self.parent:rem(self) end setmetatable(self,nil) end function isMousePosition(x,y,w,h) if (not isCursorShowing()) then return false end local cX,cY = getCursorPosition() local cX,cY = sX*cX,sY*cY if ( cX >= x and cX <= x+w and cY >= y and cY <= y+h ) then return true else return false end end novoBut = button.create(0,100,100,30,"click aqui","default",0,255,0,[[triggerServerEvent("Farda1PM",localPlayer)]]) novoBut2 = button.create(0,100,140,30,"click aqui2","default",0,255,0,[[triggerServerEvent("Farda2PM",localPlayer)]]) -- para mostrar o botao no dx, exemplo function show() novoBut:render() novoBut2:render() end addEventHandler("onClientRender",root,show) -- para habilitar e desabilitar a função de click. novoBut:setState(false) novoBut:setState(true) um exemplo de codigo que eu fiz um botao em dx um pouco mais avançado, mas voce ja entende eu creio. continue fazendo o painel em gui é um bom começo para aprender, apesar de nunca ter usado. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now