Miika Posted January 8, 2015 Share Posted January 8, 2015 Hey! My login panel having a problem. It doesn't load data from xml file. The panel works perfectly, but xml not. btw, it saves data to xml, I checked it. No any errors in debugscript. [Clientside functions] [in main function] local username, password = loadDataFromXml() if not( username == "" or password == "") then guiCheckBoxSetSelected ( LoginPanel.checkbox[1], true ) guiSetText ( LoginPanel.edit[1], tostring(username)) guiSetText ( LoginPanel.edit[2], tostring(password)) else guiCheckBoxSetSelected ( LoginPanel.checkbox[1], false ) guiSetText ( LoginPanel.edit[1], tostring(username)) guiSetText ( LoginPanel.edit[2], tostring(password)) end [And load function] function loadDataFromXml() local xml_save = xmlLoadFile ("autologin.xml") if not xml_save then xml_save = xmlCreateFile("autologin.xml", "login") end local xmlAccount = xmlFindChild (xml_save, "username", 0) local passwordNode = xmlFindChild (xml_save, "password", 0) if xmlAccount and passwordNode then return xmlNodeGetValue(xmlAccount), xmlNodeGetValue(passwordNode) else return "", "" end xmlUnloadFile ( xml_save ) end I do not show the full code, because I do not want someone to steal it: D What this might be the problem? Link to comment
Castillo Posted January 8, 2015 Share Posted January 8, 2015 Post the saving function. Link to comment
Miika Posted January 8, 2015 Author Share Posted January 8, 2015 Post the saving function. function saveLoginToXML(username, password) local xml_save = xmlLoadFile ("autologin.xml") if not xml_save then xml_save = xmlCreateFile("autologin.xml", "login") end if (username ~= "") then local xmlAccount = xmlFindChild (xml_save, "username", 0) if not xmlAccount then xmlAccount = xmlCreateChild(xml_save, "username") end xmlNodeSetValue (xmlAccount, tostring(username)) end if (password ~= "") then local passwordNode = xmlFindChild (xml_save, "password", 0) if not passwordNode then passwordNode = xmlCreateChild(xml_save, "password") end xmlNodeSetValue (passwordNode, tostring(password)) end xmlSaveFile(xml_save) xmlUnloadFile (xml_save) end addEvent("saveLoginToXML", true) addEventHandler("saveLoginToXML", getRootElement(), saveLoginToXML) I checked the file in my mta mods folder and it was saved the data Link to comment
Castillo Posted January 8, 2015 Share Posted January 8, 2015 local username, password = loadDataFromXml ( ) if ( username ~= "" and password ~= "" ) then guiCheckBoxSetSelected ( LoginPanel.checkbox[1], true ) guiSetText ( LoginPanel.edit[1], tostring ( username ) ) guiSetText ( LoginPanel.edit[2], tostring ( password ) ) end Try it. Link to comment
TAPL Posted January 8, 2015 Share Posted January 8, 2015 Don't forget this: Client file security https://wiki.multitheftauto.com/wiki/Filepath Link to comment
Miika Posted January 8, 2015 Author Share Posted January 8, 2015 local username, password = loadDataFromXml ( ) if ( username ~= "" and password ~= "" ) then guiCheckBoxSetSelected ( LoginPanel.checkbox[1], true ) guiSetText ( LoginPanel.edit[1], tostring ( username ) ) guiSetText ( LoginPanel.edit[2], tostring ( password ) ) end Try it. Doesn't work Link to comment
Castillo Posted January 8, 2015 Share Posted January 8, 2015 What does "username" and "password" return? use outputChatBox to find that out. Link to comment
Miika Posted January 8, 2015 Author Share Posted January 8, 2015 What does "username" and "password" return? use outputChatBox to find that out. Oh, i put your code into register function ;D Now it works. Thx solidsnake! Link to comment
Castillo Posted January 8, 2015 Share Posted January 8, 2015 Read what TAPL posted, or else you'll have a security problem. Link to comment
Miika Posted January 8, 2015 Author Share Posted January 8, 2015 Read what TAPL posted, or else you'll have a security problem. Yeah, but now I have problem with smoothMoveCamera ERROR: loginpanel\login_c.lua:208(in line 2 here) : attempt to call global 'smoothMoveCamera' (a nill value) function smoothMovCamera() smoothMoveCamera(-1833.8863525391,155.25959777832,61.177501678467,-1834.4569091797,154.45721435547,61.00262451171,-1901.7043457031,488.02301025391,140.8975982666,-1901.7189941406,487.13961791992,140.4291839599,20000) end addEventHandler("onClientPreRender",root,smoothMovCamera) Link to comment
TAPL Posted January 8, 2015 Share Posted January 8, 2015 You must include the function smoothMoveCamera in your code. Link to comment
Miika Posted January 9, 2015 Author Share Posted January 9, 2015 You must include the function smoothMoveCamera in your code. x = -1833.8863525391 y = 155.25959777832 z = 61.177501678467 xl = -1834.4569091797 yl = 154.45721435547 zl = 61.00262451171 x2 = -1901.7043457031 y2 = 488.02301025391 z2 = 140.8975982666 z2l = -1901.7189941406 y2l = 487.13961791992 z2l = 140.4291839599 tim = 20000 function smoothMoveCamera(x, y, z, xl, yl, zl, x2, y2, z2, x2l, y2l, z2l, tim) return true end addEventHandler("onClientResourceStart",root,smoothMoveCamera) Doesn't work and debugscript doesn't say anything Link to comment
Castillo Posted January 9, 2015 Share Posted January 9, 2015 Well, that's kinda obvious, all you did was make the function return true. Link to comment
Miika Posted January 9, 2015 Author Share Posted January 9, 2015 Well, that's kinda obvious, all you did was make the function return true. I tried many choices, none of which worked: x = -1833.8863525391 y = 155.25959777832 z = 61.177501678467 xl = -1834.4569091797 yl = 154.45721435547 zl = 61.00262451171 x2 = -1901.7043457031 y2 = 488.02301025391 z2 = 140.8975982666 z2l = -1901.7189941406 y2l = 487.13961791992 z2l = 140.4291839599 tim = 20000 function smoothMoveCamera(x, y, z, xl, yl, zl, x2, y2, z2, x2l, y2l, z2l, tim) end addEventHandler("onClientPreRender", root, smoothMoveCamera) x = -1833.8863525391 y = 155.25959777832 z = 61.177501678467 xl = -1834.4569091797 yl = 154.45721435547 zl = 61.00262451171 x2 = -1901.7043457031 y2 = 488.02301025391 z2 = 140.8975982666 z2l = -1901.7189941406 y2l = 487.13961791992 z2l = 140.4291839599 tim = 20000 function smoothMoveCamer() smoothMoveCamera(x, y, z, xl, yl, zl, x2, y2, z2, x2l, y2l, z2l, tim) end addEventHandler("onClientPreRender", root, smoothMoveCamer) function smoothMoveCamer() smoothMoveCamera(-1833.8863525391,155.25959777832,61.177501678467,-1834.4569091797,154.45721435547,61.00262451171,-1901.7043457031,488.02301025391,140.8975982666,-1901.7189941406,487.13961791992,140.4291839599,20000) end addEventHandler("onClientPreRender", root, smoothMoveCamer) Link to comment
Sasu Posted January 9, 2015 Share Posted January 9, 2015 local sm = {} sm.moov = 0 sm.object1,sm.object2 = nil,nil local function removeCamHandler() if(sm.moov == 1)then sm.moov = 0 end end local function camRender() if (sm.moov == 1) then local x1,y1,z1 = getElementPosition(sm.object1) local x2,y2,z2 = getElementPosition(sm.object2) setCameraMatrix(x1,y1,z1,x2,y2,z2) end end addEventHandler("onClientPreRender",root,camRender) function smoothMoveCamera(x1,y1,z1,x1t,y1t,z1t,x2,y2,z2,x2t,y2t,z2t,time) if(sm.moov == 1)then return false end sm.object1 = createObject(1337,x1,y1,z1) sm.object2 = createObject(1337,x1t,y1t,z1t) setElementAlpha(sm.object1,0) setElementAlpha(sm.object2,0) setObjectScale(sm.object1,0.01) setObjectScale(sm.object2,0.01) moveObject(sm.object1,time,x2,y2,z2,0,0,0,"InOutQuad") moveObject(sm.object2,time,x2t,y2t,z2t,0,0,0,"InOutQuad") sm.moov = 1 setTimer(removeCamHandler,time,1) setTimer(destroyElement,time,1,sm.object1) setTimer(destroyElement,time,1,sm.object2) return true end function smoothMoveCamer() smoothMoveCamera(-1833.8863525391,155.25959777832,61.177501678467,-1834.4569091797,154.45721435547,61.00262451171,-1901.7043457031,488.02301025391,140.8975982666,-1901.7189941406,487.13961791992,140.4291839599,20000) end addEventHandler("onClientResourceStart", resourceRoot, smoothMoveCamer) Link to comment
Miika Posted January 9, 2015 Author Share Posted January 9, 2015 local sm = {} sm.moov = 0 sm.object1,sm.object2 = nil,nil local function removeCamHandler() if(sm.moov == 1)then sm.moov = 0 end end local function camRender() if (sm.moov == 1) then local x1,y1,z1 = getElementPosition(sm.object1) local x2,y2,z2 = getElementPosition(sm.object2) setCameraMatrix(x1,y1,z1,x2,y2,z2) end end addEventHandler("onClientPreRender",root,camRender) function smoothMoveCamera(x1,y1,z1,x1t,y1t,z1t,x2,y2,z2,x2t,y2t,z2t,time) if(sm.moov == 1)then return false end sm.object1 = createObject(1337,x1,y1,z1) sm.object2 = createObject(1337,x1t,y1t,z1t) setElementAlpha(sm.object1,0) setElementAlpha(sm.object2,0) setObjectScale(sm.object1,0.01) setObjectScale(sm.object2,0.01) moveObject(sm.object1,time,x2,y2,z2,0,0,0,"InOutQuad") moveObject(sm.object2,time,x2t,y2t,z2t,0,0,0,"InOutQuad") sm.moov = 1 setTimer(removeCamHandler,time,1) setTimer(destroyElement,time,1,sm.object1) setTimer(destroyElement,time,1,sm.object2) return true end function smoothMoveCamer() smoothMoveCamera(-1833.8863525391,155.25959777832,61.177501678467,-1834.4569091797,154.45721435547,61.00262451171,-1901.7043457031,488.02301025391,140.8975982666,-1901.7189941406,487.13961791992,140.4291839599,20000) end addEventHandler("onClientResourceStart", resourceRoot, smoothMoveCamer) It works, but if I click "sign in" button, the camera does not stop moving. function hideLoginWindow() if (guiGetVisible(LoginPanel.window[1]) == true) then guiSetVisible(LoginPanel.window[1], false) showCursor(false) showChat(true) setCameraTarget ( getLocalPlayer() ) end if (guiGetVisible(LoginPanel.window[2]) == true) then guiSetVisible(LoginPanel.window[2], false) showCursor(false) showChat(true) setCameraTarget ( getLocalPlayer() ) end end addEvent("hideLoginWindow", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) local sm = {} sm.moov = 0 sm.object1,sm.object2 = nil,nil local function removeCamHandler() if(sm.moov == 1)then sm.moov = 0 end end local function camRender() if (sm.moov == 1) then local x1,y1,z1 = getElementPosition(sm.object1) local x2,y2,z2 = getElementPosition(sm.object2) setCameraMatrix(x1,y1,z1,x2,y2,z2) end end addEventHandler("onClientPreRender",root,camRender) function smoothMoveCamera(x1,y1,z1,x1t,y1t,z1t,x2,y2,z2,x2t,y2t,z2t,time) if(sm.moov == 1)then return false end sm.object1 = createObject(1337,x1,y1,z1) sm.object2 = createObject(1337,x1t,y1t,z1t) setElementAlpha(sm.object1,0) setElementAlpha(sm.object2,0) setObjectScale(sm.object1,0.01) setObjectScale(sm.object2,0.01) moveObject(sm.object1,time,x2,y2,z2,0,0,0,"InOutQuad") moveObject(sm.object2,time,x2t,y2t,z2t,0,0,0,"InOutQuad") sm.moov = 1 setTimer(removeCamHandler,time,1) setTimer(destroyElement,time,1,sm.object1) setTimer(destroyElement,time,1,sm.object2) return true end function smoothMoveCamer() smoothMoveCamera(-1833.8863525391,155.25959777832,61.177501678467,-1834.4569091797,154.45721435547,61.00262451171,-1901.7043457031,488.02301025391,140.8975982666,-1901.7189941406,487.13961791992,140.4291839599,20000) end addEventHandler("onClientResourceStart", resourceRoot, smoothMoveCamer) Link to comment
Mizudori Posted January 9, 2015 Share Posted January 9, 2015 You need to remove handler from event, after clicking on button or after log in process + set camera on source of the event of siging in. Link to comment
Miika Posted January 9, 2015 Author Share Posted January 9, 2015 You need to remove handler from event, after clicking on button or after log in process + set camera on source of the event of siging in. I tested it but nothing happens. function hideLoginWindow() if (guiGetVisible(LoginPanel.window[1]) == true) then guiSetVisible(LoginPanel.window[1], false) showCursor(false) showChat(true) removeEventHandler("onClientResourceStart", resourceRoot, smoothMoveCamer) removeEventHandler("onClientPreRender",root,camRender) setTimer(function() setCameraTarget ( getLocalPlayer() ) end,100,1) end if (guiGetVisible(LoginPanel.window[2]) == true) then guiSetVisible(LoginPanel.window[2], false) showCursor(false) showChat(true) removeEventHandler("onClientResourceStart", resourceRoot, smoothMoveCamer) removeEventHandler("onClientPreRender",root,camRender) setTimer(function() setCameraTarget ( getLocalPlayer() ) end,100,1) end end addEvent("hideLoginWindow", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) Link to comment
Mizudori Posted January 9, 2015 Share Posted January 9, 2015 You need to remove handler from event, after clicking on button or after log in process + set camera on source of the event of siging in. I tested it but nothing happens. function hideLoginWindow() if (guiGetVisible(LoginPanel.window[1]) == true) then guiSetVisible(LoginPanel.window[1], false) showCursor(false) showChat(true) removeEventHandler("onClientResourceStart", resourceRoot, smoothMoveCamer) removeEventHandler("onClientPreRender",root,camRender) setTimer(function() setCameraTarget ( getLocalPlayer() ) end,100,1) end if (guiGetVisible(LoginPanel.window[2]) == true) then guiSetVisible(LoginPanel.window[2], false) showCursor(false) showChat(true) removeEventHandler("onClientResourceStart", resourceRoot, smoothMoveCamer) removeEventHandler("onClientPreRender",root,camRender) setTimer(function() setCameraTarget ( getLocalPlayer() ) end,100,1) end end addEvent("hideLoginWindow", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) That was my bad just use this sm.moov = 0 in hideLoginWindow(). You don't need any removeEventHandlers Link to comment
Miika Posted January 10, 2015 Author Share Posted January 10, 2015 That was my bad just use this sm.moov = 0 in hideLoginWindow(). You don't need any removeEventHandlers Thanks dude! It works. 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