=KoG=Rouche Posted November 22, 2013 Share Posted November 22, 2013 (edited) Hi all, I'm creating a Login Panel for my server ! I've a question for u guys My Question : How to delete created rectangle (blue and grey) when the player has logged in ? Cuz it don't work like "Gui" with guiSetVisible(gui, bool). Here is the Panel : Here is a part of the Code : function onClientResourceStart(resource) function render() -- Blue Rect rectBlue = dxDrawRectangle((0.30*screenX),(0.35*screenY),(0.40*screenX), (0.30*screenY), tocolor(32, 146, 234, 255)) -- Grey Rect rectGrey = dxDrawRectangle((0.31*screenX),(0.35*screenY),(0.39*screenX), (0.30*screenY), tocolor(58, 58, 58, 255)) -- Text | Welcome on =KoG= Server | txt = dxDrawText("| Welcome on =KoG= Server |", (0.36*screenX), (0.37*screenY),(0.3*screenX), (0.1*screenY), tocolor ( 0, 178, 238, 255 ),1.8,"pricedown") end --[[ Events ]]-- addEventHandler("onClientRender", getRootElement(), render) end addEventHandler ( "onClientResourceStart", getRootElement (), onClientResourceStart ) Thanks for your help Edited November 25, 2013 by Guest Link to comment
Castillo Posted November 22, 2013 Share Posted November 22, 2013 You must stop rendering it, use removeEventHandler. Link to comment
=KoG=Rouche Posted November 24, 2013 Author Share Posted November 24, 2013 And another question ^^ I created some buttons and editBox not linked to a window. For a window we use guiSetVisible(bool) but for a single button or editBox ? How to hide them ? Thanks Link to comment
glowdemon1 Posted November 24, 2013 Share Posted November 24, 2013 guiSetVisible() works for editBoxes and buttons also. Alternatively you could use destroyElement() Link to comment
=KoG=Rouche Posted November 24, 2013 Author Share Posted November 24, 2013 Its better for memory to destroy them maybe ? Link to comment
glowdemon1 Posted November 24, 2013 Share Posted November 24, 2013 I assume so. guiSetVisible() is only useful (in my eyes) for temporary GUI-text storing. Like, you fill in a field with text and do guiSetVisible(field,false), the field dissapears. But after a while you want to open that field again with guiSetVisible(field,true) and it shows the text you put in there. Link to comment
=KoG=Rouche Posted November 25, 2013 Author Share Posted November 25, 2013 How can i send the guiCreateEdit content to serverside for register and login function ? Link to comment
=KoG=Rouche Posted November 25, 2013 Author Share Posted November 25, 2013 I found a way to do what i want, working with flags ! If you need help for that just ask me "pm". Last Problem : When a player join the server the panel is displayed ! then ... # if the player press a panel button before spawning on the map the panel works fine and disappear. OK OR # if the player use a panel button after spawning on the map, the GUI element are not destroyed .. i don't understand why :-/ (when the map start, the Login Panel seems to have some fast flash "Appear ... Disappear ... Appear ... Disappear ... Appear") Thanks for your help Link to comment
Dealman Posted November 25, 2013 Share Posted November 25, 2013 Are you by chance creating the buttons inside the onClientRender event? If so, you'll be creating a button with every frame. Link to comment
=KoG=Rouche Posted November 25, 2013 Author Share Posted November 25, 2013 I found the answer here https://wiki.multitheftauto.com/wiki/OnClientResourceStart. Link to comment
=KoG=Rouche Posted November 25, 2013 Author Share Posted November 25, 2013 I've another problem. When there is already 1 player on the server the GUI are never displayed until the next map is loaded ! So the dx elements are displayed without gui elements and the newcomer has to wait for the next map. Maybe i can work with the state of the player ? ... Waiting, Ready ... ? What is the clientEvent ? It's anoying :-/ Any idea ? Link to comment
Dealman Posted November 25, 2013 Share Posted November 25, 2013 It would help if you posted all the relevant code instead of just one small piece. Hard to help you without it. Link to comment
=KoG=Rouche Posted November 25, 2013 Author Share Posted November 25, 2013 I think my problem is that serverside 'll trigger the clienside of all player and make panel bug. How to trigger from serverside to 1 clientside only ? (The client which must be triggered is the newcomer, you if you just join the server) Serverside : addEvent("onRegister",true) addEventHandler("onRegister",root, function ( player, user, pass ) -- Here is the register function end ) addEvent("onLogin",true) addEventHandler("onLogin",getRootElement(), function (player, user, pass) -- here is the login function end ) -- Here is the first function called function goToCreateGUI() triggerClientEvent("guiCreateClientside",getRootElement()) end addEventHandler("onResourceStart",getRootElement(),goToCreateGUI) Clientside : -- ScreenSize screenX, screenY = guiGetScreenSize(); -- ... flag = 0 -- Buttons Functions function clientLogin(button,state) if button == "left" and state == "up" then triggerServerEvent("onLogin",getRootElement(),getLocalPlayer(),guiGetText(loginBox),guiGetText(passwordBox)) flag = 1 hideLoginPanel() end end function clientRegister(button,state) if button == "left" and state == "up" then triggerServerEvent("onRegister",getRootElement(),getLocalPlayer(),guiGetText(loginBox),guiGetText(passwordBox)) flag = 1 hideLoginPanel() end end function clientGuest(button,state) if button == "left" and state == "up" then flag = 1 hideLoginPanel() end end function render() if (flag == 0) then -- Red Rect rectRed = dxDrawRectangle(HereIsMyArgs) -- All dx element are created here ... else hideLoginPanel() end end function CreateGUI() if (flag == 0) then -- Buttons buttonL = guiCreateButton(HereIsMyArgs) buttonR = guiCreateButton(HereIsMyArgs) buttonG = guiCreateButton(HereIsMyArgs) -- EditBox loginBox = guiCreateEdit(HereIsMyArgs) passwordBox = guiCreateEdit(HereIsMyArgs) guiEditSetMaxLength(HereIsMyArgs) guiEditSetMaxLength(HereIsMyArgs) guiEditSetMasked(HereIsMyArgs) addEventHandler("onClientGUIClick",buttonL,clientLogin) addEventHandler("onClientGUIClick",buttonR,clientRegister) addEventHandler("onClientGUIClick",buttonG,clientGuest) else hideLoginPanel() end end addEvent("guiCreateClientside", true) addEventHandler("guiCreateClientside", getRootElement(), CreateGUI) -- Hide the Login Panel function hideLoginPanel() if(flag == 1) then removeEventHandler("onClientRender",getRootElement(),render) destroyElement(buttonL) destroyElement(buttonR) destroyElement(buttonG) destroyElement(loginBox) destroyElement(passwordBox) showCursor(false) end end addEvent("onHide", true) addEventHandler("onHide", getRootElement(), hideLoginPanel) function onClientJoin() CreateGUI() outputChatBox("Passer CreateGUI()") end addEventHandler("onClientPlayerJoin",getRootElement(),onClientJoin) if(flag == 1) then removeEventHandler("onClientRender",getRootElement(),render) else addEventHandler("onClientRender",getRootElement(),render) end Link to comment
TAPL Posted November 25, 2013 Share Posted November 25, 2013 Change the event onClientPlayerJoin to onClientResourceStart and change the attachedTo argument to resourceRoot also do the same for the server side event. Link to comment
=KoG=Rouche Posted November 25, 2013 Author Share Posted November 25, 2013 New Problem with the script. Now the problem when ppl join or quit when someone is using the login panel is fixed but ... If there is nobody on the server ... i press a button on the panel and only the dx elements disappear. All the GUI elements stay displayed ! I think the panel generate two times the GUI element. I don't know why :-/ Cuz when i join server i begin to type my nickname in loginEdit and when tha map is loaded, the loginEdit and passwordEdit are back to default text ... when i close the panel by pressing a button i can see the old loginEdit and passwordEdit with my nickname i was writting a few seconds ago. 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