Morgen
Ich Habe ein Großes Problem ( mal Groß mal Klein )
Unzwar baue ich eine Funktion mit der Man dx element Hin und her ziehen kann nunja
Es Funktioniert alles wie es soll nur das wenn ich das dx Element anklicke es sich um ein paar x und y Koordinaten Verschiebt
Evt Könnt ihr mir ja dabei helfen
Lua
local x,y = guiGetScreenSize()
local sx,sy = x/2,y/2
lp = getLocalPlayer()
dx = {}
dx.x = x/3.5
dx.y = y/1.6
dx.w = x/2.22
dx.h = y/9
local cx,cy = getCursorPosition()
dx.dragx = cx*2
dx.dragy = cx*2
dx.color = tocolor(255, 0, 0, 200)
dx.maincolor = tocolor(0, 0, 0, 200)
setElementData(getRootElement(),"dragndropx",dx.x)
setElementData(getRootElement(),"dragndropy",dx.y)
function isCursorOnElement(cursorx,cursory,x,y,w,h)
if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then
return true
else
return false
end
end
addEventHandler("onClientRender",getRootElement(),
function ()
dxDrawText( dx.x, 200, 250 )
dxDrawText( dx.y, 200, 220 )
dxDrawRectangle (dx.x, dx.y, dx.w, dx.h, dx.color)
if (getKeyState ( "mouse1" ) == true ) and getElementData(lp,"clickeddxElement") == true then
local cx,cy = getCursorPosition()
dxDrawRectangle (dx.x*cx*2, dx.y*cy*1.5, dx.w, dx.h, dx.maincolor)
setElementData(getRootElement(),"dragndropx",dx.x*cx*2)
setElementData(getRootElement(),"dragndropy",dx.y*cy*1.5)
else
dxDrawRectangle (getElementData(getRootElement(),"dragndropx"),getElementData(getRootElement(),"dragndropy"), dx.w, dx.h, dx.maincolor)
end
end)
function dx.onEnter(_,_, ax, ay)
if (isCursorOnElement(ax, ay, getElementData(getRootElement(),"dragndropx"),getElementData(getRootElement(),"dragndropy"), dx.w, dx.h) == true) and not (getKeyState ( "mouse1" ) == true )then
dx.maincolor = tocolor(0, 0, 0, 180)
elseif (getKeyState ( "mouse1" ) ~= true ) then
dx.maincolor = tocolor(0, 0, 0, 150)
end
end
addEventHandler( "onClientCursorMove", getRootElement( ),dx.onEnter)
function dx.click(button, state, ax,ay)
if (button == "left" and state == "down") and (isCursorOnElement(ax, ay,getElementData(getRootElement(),"dragndropx"),getElementData(getRootElement(),"dragndropy"),dx.w,dx.h) == true) then
setElementData(lp,"clickeddxElement",true)
dx.maincolor = tocolor(0, 255, 0, 255)
else
dx.maincolor = tocolor(0, 0, 0, 150)
setElementData(lp,"clickeddxElement",false)
end
end
addEventHandler( "onClientClick", getRootElement( ),dx.click)
Alles anzeigen
MfG