Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2018-09-03, 01:21


mefju







Wiek: 31
Na forum: 2833 dni
Posty: 2
Nick w MP: Mefju



Respekt: 50

Witam.
Ot?? mam problem z przyciskiem do nowego okna GUI.
Chodzi mi o to ?e jak klikniemy w przycisk (LABEL) to powinno nam zamkn?? okno nr.1 a wy?wietli? okno nr.2 i tutaj jest problem w tym ?e nie wywala mi b??du a okno nr.2 si? nie wy?wietla oto niezb?dny kod:

Kod:


GUIEditor = {
staticimage = {},
label = {},
background = {},
edit = {}
}

addEventHandler("onClientResourceStart", resourceRoot,
function()
GUIEditor.background[1] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)
guiSetAlpha(GUIEditor.background[1], 0.80)
GUIEditor.background[2] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)
guiSetAlpha(GUIEditor.background[2], 0.80)
GUIEditor.background[3] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)
guiSetAlpha(GUIEditor.background[3], 0.80)

--Zawarto?? logowania--
GUIEditor.label[1] = guiCreateLabel(143, 83, 194, 18, "Login", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[1], "default-bold-small")
GUIEditor.edit[1] = guiCreateEdit(133, 101, 214, 32, "", false, GUIEditor.background[1])
GUIEditor.label[2] = guiCreateLabel(143, 153, 194, 18, "Has?o", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[2], "default-bold-small")
GUIEditor.edit[2] = guiCreateEdit(133, 171, 214, 32, "", false, GUIEditor.background[1])

--Zawarto?? rejestracji--
GUIEditor.label[3] = guiCreateLabel(143, 55, 194, 18, "Login", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[3], "default-bold-small")
GUIEditor.edit[3] = guiCreateEdit(133, 73, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.label[4] = guiCreateLabel(143, 125, 194, 18, "Has?o", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[4], "default-bold-small")
GUIEditor.edit[4] = guiCreateEdit(133, 143, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.edit[5] = guiCreateEdit(133, 213, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.label[5] = guiCreateLabel(143, 195, 194, 18, "E-mail", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[5], "default-bold-small")

--Rejestracja--
GUIEditor.staticimage[1] = guiCreateStaticImage(560, 395, 160, 45, ":egui/images/examples/shruk.png", false)
guiSetAlpha(GUIEditor.staticimage[1], 0.80)

GUIEditor.label[6] = guiCreateLabel(10, 13, 140, 22, "Rejestracja", false, GUIEditor.staticimage[1])
guiSetFont(GUIEditor.label[6], "default-bold-small")
guiLabelSetHorizontalAlign(GUIEditor.label[6], "center", false)
end
)
addEvent("ShowHide",true)
function ShowHide()
if (guiGetVisible(GUIEditor.background[2]) == true and source ~= GUIEditor.background[2]) then
guiSetVisible(GUIEditor.background[2],false)
showCursor(false)
end
if (guiGetVisible(GUIEditor.background[3]) == true and source ~= GUIEditor.background[3]) then
guiSetVisible(GUIEditor.background[3],false)
showCursor(false)
end
end
addEventHandler("ShowHide",getLocalPlayer(),ShowHide)

--Przycisk kt?ry powinien ukry? okno nr.1 i wy?wietli? okno nr.2--
function btnRegister()
if (source == GUIEditor.label[6]) then
guiSetVisible(GUIEditor.background[2],true)
guiSetVisible(GUIEditor.background[1],false)
end
end
addEventHandler("onClientGUIClick", GUIEditor.staticimage[1], btnRegister)

-- GUIEditor.staticimage[1] -> jest to t?o obrazkowe na kt?rym jest nasz LABEL kt?ry ukrywa i pokazuje okna.--


Pomo?e kto??

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-09-03, 11:22


Norbert1234

Nie umiem w LUA






Wiek: 22
Na forum: 3987 dni
Posty: 319
Nick w MP: Gusterowskyy

Piwa: 242

Respekt: 60

Tag dodaj inny, a db3 co? wskazuje

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-09-03, 13:30


Wilq







Wiek: 24
Na forum: 4428 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

1. W jaki element GUI chcesz klikn??, ?eby zmieni?o si? okno lub t?o. Podaj zmienn? tego elementu lub napisz czy jest to obrazek czy tekst (guiCreateLabel).

2. W addEventHandlerze w drugim argumencie wpisa?e? element GUI, kt?ry jest odpowiedzialny za funkcj? btnRegister(), tym samym source (?r?d?o) to GUIEditor.staticimage[1]. Po kiego grzyba da?e? tam " if (source == GUIEditor.label[6]) then "?

function btnRegister() 
    if (source == GUIEditor.label[6]) then 
        guiSetVisible(GUIEditor.background[2],true) 
        guiSetVisible(GUIEditor.background[1],false) 
    end    
end 
addEventHandler("onClientGUIClick"GUIEditor.staticimage[1], btnRegister


* https://wiki.multitheftauto.com/wiki/OnClientGUIClick *

3. Dodatkowy event ShowHide jest ?le zrobiony. Masz tam warunek "source ~= GUIEditor.background[2]', kt?ry nie sprawdzi si? bo prawdopodobnie source (?r?d?o) w Twoim przypadku to gracz. Wyja?nij dzia?anie tego eventu i r?wnie? go poprawimy.

PS. Koledze wy?ej poleci?bym szybki kurs czytania, bo mefju wspomnia?, i?:

Cytat:

... problem w tym ?e nie wywala mi b??du ...


Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-09-03, 23:18


mefju







Wiek: 31
Na forum: 2833 dni
Posty: 2
Nick w MP: Mefju



Respekt: 50

Opisze to dok?adniej.
Og?lnie s? 3 obrazki, 2 z nich nazwa?em background[1] i background[2]

Kod:


GUIEditor.background[1] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)
guiSetAlpha(GUIEditor.background[1], 0.80)
GUIEditor.background[2] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)
guiSetAlpha(GUIEditor.background[2], 0.80)


w background[1] s? wy?wietlane dane logowania

Kod:



--Zawarto?? logowania--
GUIEditor.label[1] = guiCreateLabel(143, 83, 194, 18, "Login", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[1], "default-bold-small")
GUIEditor.edit[1] = guiCreateEdit(133, 101, 214, 32, "", false, GUIEditor.background[1])
GUIEditor.label[2] = guiCreateLabel(143, 153, 194, 18, "Has?o", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[2], "default-bold-small")
GUIEditor.edit[2] = guiCreateEdit(133, 171, 214, 32, "", false, GUIEditor.background[1])


a w background[2] dane rejestracji.

Kod:


--Zawarto?? rejestracji--
GUIEditor.label[3] = guiCreateLabel(143, 55, 194, 18, "Login", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[3], "default-bold-small")
GUIEditor.edit[3] = guiCreateEdit(133, 73, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.label[4] = guiCreateLabel(143, 125, 194, 18, "Has?o", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[4], "default-bold-small")
GUIEditor.edit[4] = guiCreateEdit(133, 143, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.edit[5] = guiCreateEdit(133, 213, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.label[5] = guiCreateLabel(143, 195, 194, 18, "E-mail", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[5], "default-bold-small")


Ostatnie t?o(obrazek) bedzie s?u?y? za t?o do LABELa kt?ry bedzie mia? za zadanie ukry? dany background z zawarto?ci? i wy?wietli? drugi np.

Na start mamy wy?wietlony background[1] kt?ry zawiera dane logowania oraz staticimage[1] (t?o LABELA do przekierowania) a na tym staticimage[1] b?dzie znajdowa? si? LABEL o nazwie "Rejestracja".

Kod:


GUIEditor.background[1] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)--background[1] do logowania--
guiSetAlpha(GUIEditor.background[1], 0.80)

--Zawarto?? logowania--
GUIEditor.label[1] = guiCreateLabel(143, 83, 194, 18, "Login", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[1], "default-bold-small")
GUIEditor.edit[1] = guiCreateEdit(133, 101, 214, 32, "", false, GUIEditor.background[1])
GUIEditor.label[2] = guiCreateLabel(143, 153, 194, 18, "Has?o", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[2], "default-bold-small")
GUIEditor.edit[2] = guiCreateEdit(133, 171, 214, 32, "", false, GUIEditor.background[1])

--Rejestracja--
GUIEditor.staticimage[1] = guiCreateStaticImage(560, 395, 160, 45, ":egui/images/examples/shruk.png", false)--T?o do LABEL[6]--
guiSetAlpha(GUIEditor.staticimage[1], 0.80)

GUIEditor.label[6] = guiCreateLabel(10, 13, 140, 22, "Rejestracja", false, GUIEditor.staticimage[1]) --LABEL[6] kt?ry ma ukrywa?/pokazywa? backgroundy--
guiSetFont(GUIEditor.label[6], "default-bold-small")
guiLabelSetHorizontalAlign(GUIEditor.label[6], "center", false)


Gdy klikniemy w ten LABEL[6] powinno nam schowa? background[1] w kt?rym jest zawarto?? do logowania i wy?wietli?
nam background[2] z zawarto?ci? rejestraji.

Kod:


function btnRegister()
guiSetVisible(GUIEditor.background[1],false)
guiSetVisible(GUIEditor.background[2],true)
end
addEventHandler("onClientGUIClick", GUIEditor.label[6], btnRegister)


Dodatkowe info:
Ten kod ukrywa nam przy starcie background[2] (bg z zawarto?ci? rejestracji, po to aby dwa t?a na siebie nie nachodzi?y).

Kod:


addEvent("showHide",true)
function ShowHide()
if guiGetVisible(GUIEditor.background[2]) == true then
guiSetVisible(GUIEditor.background[2],false)
showCursor(false)
end
end
addEventHandler("showHide",getLocalPlayer(),ShowHide)


Pe?en kod jak wygl?da teraz po wywaleniu:
Kod:

if (source == GUIEditor.label[6])


PE?NY KOD:
Kod:


GUIEditor = {
staticimage = {},
label = {},
background = {},
edit = {}
}

addEventHandler("onClientResourceStart", resourceRoot,
function()
GUIEditor.background[1] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)--background[1] do logowania--
guiSetAlpha(GUIEditor.background[1], 0.80)
GUIEditor.background[2] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)--background[2] do rejestracji--
guiSetAlpha(GUIEditor.background[2], 0.80)
GUIEditor.background[3] = guiCreateStaticImage(400, 450, 480, 330, ":egui/images/examples/shruk.png", false)
guiSetAlpha(GUIEditor.background[3], 0.80)

--Zawarto?? logowania--
GUIEditor.label[1] = guiCreateLabel(143, 83, 194, 18, "Login", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[1], "default-bold-small")
GUIEditor.edit[1] = guiCreateEdit(133, 101, 214, 32, "", false, GUIEditor.background[1])
GUIEditor.label[2] = guiCreateLabel(143, 153, 194, 18, "Has?o", false, GUIEditor.background[1])
guiSetFont(GUIEditor.label[2], "default-bold-small")
GUIEditor.edit[2] = guiCreateEdit(133, 171, 214, 32, "", false, GUIEditor.background[1])

--Zawarto?? rejestracji--
GUIEditor.label[3] = guiCreateLabel(143, 55, 194, 18, "Login", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[3], "default-bold-small")
GUIEditor.edit[3] = guiCreateEdit(133, 73, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.label[4] = guiCreateLabel(143, 125, 194, 18, "Has?o", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[4], "default-bold-small")
GUIEditor.edit[4] = guiCreateEdit(133, 143, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.edit[5] = guiCreateEdit(133, 213, 214, 32, "", false, GUIEditor.background[2])
GUIEditor.label[5] = guiCreateLabel(143, 195, 194, 18, "E-mail", false, GUIEditor.background[2])
guiSetFont(GUIEditor.label[5], "default-bold-small")

--Rejestracja--
GUIEditor.staticimage[1] = guiCreateStaticImage(560, 395, 160, 45, ":egui/images/examples/shruk.png", false)--T?o do LABEL[6]--
guiSetAlpha(GUIEditor.staticimage[1], 0.80)

GUIEditor.label[6] = guiCreateLabel(10, 13, 140, 22, "Rejestracja", false, GUIEditor.staticimage[1]) --LABEL[6] kt?ry ma ukrywa?/pokazywa? backgroundy--
guiSetFont(GUIEditor.label[6], "default-bold-small")
guiLabelSetHorizontalAlign(GUIEditor.label[6], "center", false)
end
)
addEvent("showHide",true)
function ShowHide()
if guiGetVisible(GUIEditor.background[2]) == true then
guiSetVisible(GUIEditor.background[2],false)
showCursor(false)
end
if guiGetVisible(GUIEditor.background[3]) == true then
guiSetVisible(GUIEditor.background[3],false)
showCursor(false)
end
end
addEventHandler("showHide",getLocalPlayer(),ShowHide)

function btnRegister()
guiSetVisible(GUIEditor.background[2],true)
guiSetVisible(GUIEditor.background[1],false)
end
addEventHandler("onClientGUIClick", GUIEditor.label[6], btnRegister)


A i jeszcze dodam wam 2 obrazki takie na szybko ?eby?cie widzieli mniej wi?cej jak to powinno wygl?da?.

1. Po odpaleniu skryptu wy?wietlane background[1] <-- to jest git



2. Po klikni?ciu LABEL[6] (Rejestracja) powinno wy?wietli? background[2] (z zawarto?ci? rejestracji) i ukry? background[1](z zawarto?ci? logowania). <-- I to w?a?nie nie dzia?a




P??niej zrobi? te? powr?t do logowania tylko pierw musz? obczai? jak to zrobi? z tym showHide.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-09-04, 19:43


Wilq







Wiek: 24
Na forum: 4428 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Zacznijmy od tego: od razu przy w??czeniu skryptu tworzy si? GUI i jest ono pokazywane. W tym samym momencie triggerujesz event "showHide" aby schowa? to GUI tak?
Je?li nie - mo?esz od razu schowa? ca?e GUI i po wej?ciu gracza na serwer triggerowa? event aby to GUI si? otwiera?o.

Wykorzysta?em kod w taki spos?b:

CLIENT:

local GUIEditor = { 
staticimage = {}, 
label = {}, 
background = {}, 
edit = {} 
} 

    GUIEditor.background[1] = guiCreateStaticImage(400450480330"tlo.png"false)--background[1] do logowania-- 
    guiSetAlpha(GUIEditor.background[1], 0.80) 
    GUIEditor.background[2] = guiCreateStaticImage(400450480330"tlo.png"false)--background[2] do rejestracji-- 
    guiSetAlpha(GUIEditor.background[2], 0.80) 
    GUIEditor.background[3] = guiCreateStaticImage(400450480330"tlo.png"false) 
    guiSetAlpha(GUIEditor.background[3], 0.80) 

    --Zawarto?? logowania-- 
    GUIEditor.label[1] = guiCreateLabel(1438319418"Login"falseGUIEditor.background[1]) 
    guiSetFont(GUIEditor.label[1], "default-bold-small") 
    GUIEditor.edit[1] = guiCreateEdit(13310121432""falseGUIEditor.background[1]) 
    GUIEditor.label[2] = guiCreateLabel(14315319418"Has?o"falseGUIEditor.background[1]) 
    guiSetFont(GUIEditor.label[2], "default-bold-small") 
    GUIEditor.edit[2] = guiCreateEdit(13317121432""falseGUIEditor.background[1]) 

    --Zawarto?? rejestracji-- 
    GUIEditor.label[3] = guiCreateLabel(1435519418"Login"falseGUIEditor.background[2]) 
    guiSetFont(GUIEditor.label[3], "default-bold-small") 
    GUIEditor.edit[3] = guiCreateEdit(1337321432""falseGUIEditor.background[2]) 
    GUIEditor.label[4] = guiCreateLabel(14312519418"Has?o"falseGUIEditor.background[2]) 
    guiSetFont(GUIEditor.label[4], "default-bold-small") 
    GUIEditor.edit[4] = guiCreateEdit(13314321432""falseGUIEditor.background[2]) 
    GUIEditor.edit[5] = guiCreateEdit(13321321432""falseGUIEditor.background[2]) 
    GUIEditor.label[5] = guiCreateLabel(14319519418"E-mail"falseGUIEditor.background[2]) 
    guiSetFont(GUIEditor.label[5], "default-bold-small") 

    --Rejestracja-- 
    GUIEditor.staticimage[1] = guiCreateStaticImage(56039516045"tlo.png"false)--T?do LABEL[6]-- 
    guiSetAlpha(GUIEditor.staticimage[1], 0.80) 

    GUIEditor.label[6] = guiCreateLabel(101314022"Rejestracja"falseGUIEditor.staticimage[1]) --LABEL[6kt?ry ma ukrywa?/pokazywabackgroundy-- 
    guiSetFont(GUIEditor.label[6], "default-bold-small") 
    guiLabelSetHorizontalAlign(GUIEditor.label[6], "center"false) 
 
    guiSetVisible(GUIEditor.background[1], false)
    guiSetVisible(GUIEditor.background[2], false)
    guiSetVisible(GUIEditor.background[3], false)
    guiSetVisible(GUIEditor.staticimage[1], false)
 
addEvent("showHide"true) 
function showHide() 
    if guiGetVisible(GUIEditor.background[1]) == false then 
        guiSetVisible(GUIEditor.background[1], true) 
    end 
    if guiGetVisible(GUIEditor.staticimage[1]) == false then 
        guiSetVisible(GUIEditor.staticimage[1], true) 
    end
    showCursor(true)     
end 
addEventHandler("showHide"getRootElement(), showHide) 

function btnRegister()
    if guiGetVisible(GUIEditor.background[2]) ~= false then return end
        guiSetVisible(GUIEditor.background[2], true) 
        guiSetVisible(GUIEditor.background[1], falseend 
addEventHandler("onClientGUIClick"GUIEditor.label[6], btnRegister


i po wej?ciu na serwer lub pobraniu zasob?w, nie wiem jak masz u siebie - wykorzystujesz

triggerEvent("showHide"localPlayer)


lub

triggerClientEvent(*zmienna gracza*, "showHide", *zmienna gracza*)



Mo?esz tak?e zrobi? odwrotnie, zostawi? ?eby GUI si? pokaza?o ale przy starcie od razu zrobi? p?tl? na graczy i sprawdza? czy s? zalogowani - je?li tak, wy??czasz im GUI a je?li nie, zostawiasz w??czone.


Na dole w spoilerze dorzuci?em od siebie kod na powr?t to logowania - bez dodatkowych label?w - tak gdyby? chcia? mie? inspiracj?.






Postaw piwo autorowi tego posta
 

 
Tagi: przycisk :: showhide :: skrypcie :: nie :: chce :: działać!
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Przycisk showHide w skrypcie nie chce działać! Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku