Ciekurs Posted August 3, 2020 Share Posted August 3, 2020 Hello guys! i need help i want to add to my login panel so once player is on login panel the image will change every second for example from this to this every second 1 Link to comment
Filex Posted August 3, 2020 Share Posted August 3, 2020 best thing to do is to store your images paths in a table and use a current index variable for example local currentImageIndex = 1 local myImages = { "path1.png", "path2.png" } and use dxDrawImage with the player Screen Width/Height ( guiGetScreenSize() ) to get the image on full screen, set your image to myImages[currentImageIndex] to set the image path with the current index in the table local screenW, screenH = guiGetScreenSize() function draw() dxDrawImage(0, 0, screenW, screenH, myImages[currentImageIndex]) end addEventHandler("onClientRender", getRootElement(), draw) in order for your image to change after a specific time use a timer to update the current index as following: local changeDuration = 2000 -- this will set my image to change every 2s function updateCurrentImageIndex() if ( currentImageIndex == #myImages) then return currentImageIndex = 1 end -- this is set to avoid having the index higher than the table count currentImageIndex = currentImageIndex + 1 end local myTimer = setTimer( updateCurrentImageIndex, changeDuration, 0) with this way your image will be changing every 2s and make sure to destroy the timer and remove the onClientRender event. please note this is just the concept of how i'd personally do it, try to replicate it your way, you can also possibly set a fade effect to make it look better Link to comment
Ciekurs Posted August 3, 2020 Author Share Posted August 3, 2020 @Filex Quote -- -308.42431640625,1296.0610351563,115.47154998779 resourceRoot = getResourceRootElement(getThisResource()) localPlayer = getLocalPlayer() marwinButtons = {} font = {} font[1] = guiCreateFont( "font.ttf", 12 ) font[2] = guiCreateFont( "font.ttf", 28 ) --Button function createMarwinButton(x,y,widht,height,text,bool,parent,info) button = guiCreateStaticImage(x,y,widht,height,"images/button_standart.png", bool,parent or nil) table.insert(marwinButtons,button) guiBringToFront(button) label = guiCreateLabel(0,0,1,1,text,bool,button) guiBringToFront(label) setElementData(label,"parent",button) setElementData(button,"info",info) guiSetFont(label,font[1]) guiLabelSetVerticalAlign (label, "center") guiLabelSetHorizontalAlign (label, "center") addEventHandler("onClientMouseEnter",label,markButton,false) addEventHandler("onClientMouseLeave",label,unmarkButton,false) return label end function markButton () parent = getElementData(source,"parent") guiStaticImageLoadImage (parent,"images/button_mouse.png") setElementData(getLocalPlayer(),"clickedButton",parent) end function unmarkButton (b,s) parent = getElementData(source,"parent") guiStaticImageLoadImage (parent,"images/button_standart.png") setElementData(getLocalPlayer(),"clickedButton",false) end --false to disable all debug messages idb = false function loginPanel() showCursor(true,false) screenw,screenh = guiGetScreenSize() login_window = guiCreateStaticImage(0, 0, screenw, screenh, "images/bg.png", false) login_login = createMarwinButton(0.1,0.455,0.095,0.03,"Login",true,login_window,"login") name = guiCreateLabel(5, 700, 175, 48, namep, false, login_window) guiSetFont ( name, font[2] ) --login_error = guiCreateLabel(5, 5, 175, 48, "", false, login_window) addEventHandler ( "onClientGUIClick", login_login, function() guiSetVisible(login_window2,false) guiSetVisible(register_window,false) createLogin() --if idb == true then --outputChatBox("got reg click") --end --username = guiGetText(login_username) --password = guiGetText(login_password) --if username ~= "" and password ~= "" then -- guiSetText(login_error,"") -- triggerServerEvent("onClientSendLoginDataToServer", getLocalPlayer(), username, password) --else --guiSetText(login_error,"Ошибка: Заполните все поля!") --end end, false ) --- login_register = createMarwinButton(0.1,0.495,0.095,0.03,"Register",true,login_window,"login") addEventHandler ( "onClientGUIClick", login_register, function() guiSetVisible(register_window,false) guiSetVisible(login_window2,false) guiSetVisible(register_window,false) createRegistration() end, false ) login_exit = createMarwinButton(0.1,0.535,0.095,0.03,"Exit",true,login_window,"quit") addEventHandler ( "onClientGUIClick", login_exit, function() guiSetVisible(login_window2,false) guiSetVisible(register_window,false) end, false ) login_error = guiCreateLabel(5, 5, 175, 48, "", false, login_window) guiLabelSetColor(login_error, 197, 0, 0) guiLabelSetHorizontalAlign(login_error, "left", true) end function createRegistration() screenw,screenh = guiGetScreenSize() register_window = guiCreateStaticImage(350, 270, 200, 250, "images/menu.png", false) infol1 = guiCreateLabel(0.27, 0.05, 0.80, 0.30,"Register",true,register_window) guiSetFont(infol1,font[1]) infol4 = guiCreateLabel(0.38, 0.16, 0.80, 0.30,"Name",true,register_window) guiSetFont(infol4,font[1]) infol5 = guiCreateLabel(0.36, 0.38, 0.80, 0.30,"Pasword",true,register_window) guiSetFont(infol5,font[1]) register_username = guiCreateEdit(30, 60, 134, 28, "", false, register_window) guiSetAlpha(register_username, 0.60) register_password = guiCreateEdit(30, 120, 134, 28, "", false, register_window) guiSetAlpha(login_password, 0.60) guiEditSetMasked(register_password, true) regbutt = createMarwinButton(0.14,0.695,0.695,0.110,"Register",true,register_window,"login") -- regbutt = guiCreateButton( 7, 180, 175, 48, "Вперед!", false, register_window) addEventHandler ( "onClientGUIClick", regbutt, function() if idb == true then outputChatBox("got reg click") end username = guiGetText(register_username) pass1 = guiGetText(register_password) if username ~= "" and pass1 ~= "" then guiSetText(login_error,"") triggerServerEvent("onClientSendRegisterDataToServer", getLocalPlayer(), username, pass1) else guiSetText(login_error,"ERROR! Please fill in all the fields!") end end, false ) end function createLogin() screenw,screenh = guiGetScreenSize() login_window2 = guiCreateStaticImage(350, 270, 200, 250, "images/menu.png", false) infol = guiCreateLabel(0.27, 0.05, 0.80, 0.30,"Register",true,login_window2) guiSetFont(infol,font[1]) infol2 = guiCreateLabel(0.38, 0.16, 0.80, 0.30,"Username",true,login_window2) guiSetFont(infol2,font[1]) infol3 = guiCreateLabel(0.36, 0.38, 0.80, 0.30,"Pasword",true,login_window2) guiSetFont(infol3,font[1]) --login_window2 = guiCreateWindow(450, 250, 200, 250, "Вход", false) --register_window = guiCreateWindow ( 450, 250, 200, 250, "Register", true ) login_username = guiCreateEdit(30, 60, 134, 28, "", false, login_window2) guiSetAlpha(register_username, 0.60) login_password = guiCreateEdit(30, 120, 134, 28, "", false, login_window2) guiSetAlpha(login_password, 0.60) guiEditSetMasked(login_password, true) loginbutt = createMarwinButton(0.14,0.695,0.695,0.110,"Login",true,login_window2,"login") addEventHandler ( "onClientGUIClick", loginbutt, function() if idb == true then outputChatBox("got reg click") end username = guiGetText(login_username) password = guiGetText(login_password) if username ~= "" and password ~= "" then guiSetText(login_error,"") triggerServerEvent("onClientSendLoginDataToServer", getLocalPlayer(), username, password) else guiSetText(login_error,"ERROR! Please fill in all the fields!") end end, false ) config = xmlLoadFile("fragconf.xml") if config then uname = xmlNodeGetAttribute(config,"username") pass = xmlNodeGetAttribute(config,"pass") guiSetText(login_username,uname) guiSetText(login_password,pass) else config = xmlCreateFile("fragconf.xml","account") xmlNodeSetAttribute(config, "username", "") xmlNodeSetAttribute(config, "pass", "") xmlSaveFile(config) end end addEvent("regerror",true) function registererror(etype) local enames = {} enames[0] = "This account already exists!" enames[1] = "Please fill in all the fields!" enames[2] = "Unknown error!" enames[3] = "Invalid username or password!" guiSetText(login_error,"ERROR! "..enames[etype]) end addEventHandler ( "regerror", getLocalPlayer(), registererror) function finishlogin() config = xmlLoadFile("fragconf.xml") xmlNodeSetAttribute(config, "username",guiGetText(login_username)) xmlNodeSetAttribute(config, "pass",guiGetText(login_password)) xmlSaveFile(config) guiSetVisible(login_bg,false) guiSetVisible(login_window,false) showCursor(false) guiSetVisible(register_window,false) guiSetVisible(login_window2,false) end addEvent("onPlayerDoneLogin", true) addEventHandler("onPlayerDoneLogin", getRootElement(), finishlogin) addEventHandler("onClientResourceStart", resourceRoot, function () loginPanel() setPlayerHudComponentVisible ("radar", false ) ped = createPed ( 73, 2661.5905761719, 2729.5161132813, 10.8203125, 440,true ) setPedAnimation( ped, "ped", "endchat_01",nil,true,true,false,false) guiSetInputMode("no_binds_when_editing") fadeCamera (true) setCameraMatrix(2658.2626953125, 2728.0246582031, 10.541299819946, 2659.0986328125, 2728.521484375, 10.774273872375) end ) --playSound("music.mp3") Link to comment
Filex Posted August 3, 2020 Share Posted August 3, 2020 26 minutes ago, Ciekurs said: didnt work https://streamable.com/a1tl4z that's how it's supposed to work using your two images Link to comment
Ciekurs Posted August 3, 2020 Author Share Posted August 3, 2020 if ur still here mate can u help me? because i do not know how to put it on the login panel once i putted it as a resource thats not in the login panel it worked but the login button didnt show Link to comment
Filex Posted August 3, 2020 Share Posted August 3, 2020 31 minutes ago, Ciekurs said: if ur still here mate can u help me? because i do not know how to put it on the login panel once i putted it as a resource thats not in the login panel it worked but the login button didnt show please refer the mta discord server script-help channel so we can have a more smooth conversation 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