Xabache Posted January 4, 2015 Share Posted January 4, 2015 I need to force user nicknames (as visible in chat and on screen) to 4-10 characters, no color codes, in all caps. I know it is the mta client which defines the nickname you see despite the login panel account name, can I change this with my login_panel, or any other way? Link to comment
Xabache Posted January 4, 2015 Author Share Posted January 4, 2015 And could i implement these in my loginpanel_client.lua or loginpanel_server.lua, or is this an mta client change? Link to comment
TrapLord Studios™ Posted January 4, 2015 Share Posted January 4, 2015 Those aren't functions they are lua strings. So you'd have to use them client side. Link to comment
Anubhav Posted January 4, 2015 Share Posted January 4, 2015 Those aren't functions they are lua strings. So you'd have to use them client side. Who told you that? They're a lua string libary. Not a lua string but a function. You can use them server or client. Available for both Link to comment
TrapLord Studios™ Posted January 4, 2015 Share Posted January 4, 2015 Made a mistake thanks. Link to comment
Xabache Posted January 5, 2015 Author Share Posted January 5, 2015 Ten years ago when i started mIRC scripting i found it most helpful when someone with skills came along and solved one or two problems in total. That I may learn from their example. As I have done for new mirc scripters ever after The example I hope to learn from you from is an MTA New Player Regitration Entry nickname filter with hopefulyl all of the following rules forced at the entry point or rejected by the server once entered - No Colored Nicks allowed #FFFFFF - Characters A-Z, 0-9, - _ only - 4-10 characters required/limited - ALL CAPS - A Profanity Nick name filter position would be nice too if (UCKYOU isin $nick) echo BAd Nickname ...sort of thing Rejection at the typing level, the nickname entry level into the client would seem best, but a rejection message server side is also fine The Client Lua: ---------------------------------- -----------| Settings |----------- ---------------------------------- blackLoginScreen = false -- Set to 'true' to display a black screen to the player untill they log in or choose to play as a guest. enableKickPlayer = true -- Set whether to kick the player after they fail to login specified amount of times. disallowLogout = false -- Set whether to show the userpanel to the players if they log out of their accounts. removeBlackScreenTime = 4 -- The time it takes for the black screen to dissapear - If you choose to display the black screen. [iN SECONDS] maxLoginAttempts = 19 -- Set the maximum incorrect login attempts before the player gets kicked - If player kicking is enabled. ---------------------------------- -- Set the text you want displayed in the "rules" window here - use '\n' to go into the next line infoText = "------ Rules ------ \n\n* 1) No Insults!\n* 2) No Spamming!" -- Screen and GUI window sizes screenWidth,screenHeight = guiGetScreenSize() mainWidth,mainHeight = 749,472 regWidth,regHeight = 439,344 -- Generate the XML file name function getServerName() triggerServerEvent("onClientLoginLoaded",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerName) function setXmlFileName(sName) xmlFileName = tostring("login_"..sName..".xml") loginPanel() end addEvent("onGetServerData",true) addEventHandler("onGetServerData",getRootElement(),setXmlFileName) ---------------------------------- addEvent("onRequestIncreaseAttempts",true) addEvent("onRequestDisplayPanel",true) function loginPanel() -- Check if autologin is enabled - If yes, then log the player in, else create and show the userpanel local xmlFile = xmlLoadFile(xmlFileName) if xmlFile then status = xmlNodeGetAttribute(xmlFile,"autologin") if (status == "true") then local username = tostring(xmlNodeGetAttribute(xmlFile,"username")) local password = tostring(xmlNodeGetAttribute(xmlFile,"password")) if not (username == "") and not (password == "") then triggerServerEvent("onRequestAutologin",getLocalPlayer(),username,password) end else if blackLoginScreen == true then fadeCamera(false,0,0,0,0) end mainWindow = guiCreateWindow(screenWidth/2-mainWidth/2,screenHeight/2-mainHeight/2,mainWidth,mainHeight,"Login panel",false) guiWindowSetSizable(mainWindow,false) mInfo = guiCreateMemo(21,36,411,278,infoText,false,mainWindow) guiMemoSetReadOnly(mInfo,true) editUsername = guiCreateEdit(53,364,187,25,"",false,mainWindow) guiEditSetMaxLength(editUsername,30) editPassword = guiCreateEdit(53,421,187,25,"",false,mainWindow) guiEditSetMaxLength(editPassword,30) guiEditSetMasked(editPassword,true) lblUsername = guiCreateLabel(67,330,158,38,"Username:",false,mainWindow) guiLabelSetColor(lblUsername,0,85,255) guiLabelSetVerticalAlign(lblUsername,"center") guiLabelSetHorizontalAlign(lblUsername,"center",false) guiSetFont(lblUsername,"default-bold-small") lblPassword = guiCreateLabel(67,389,158,38,"Password:",false,mainWindow) guiLabelSetColor(lblPassword,0,85,255) guiLabelSetVerticalAlign(lblPassword,"center") guiLabelSetHorizontalAlign(lblPassword,"center",false) guiSetFont(lblPassword,"default-bold-small") btnLogin = guiCreateButton(280,368,242,74,"Login",false,mainWindow) guiSetFont(btnLogin,"sa-header") btnToggleRegister = guiCreateButton(490,246,206,68,"Register an account",false,mainWindow) guiSetFont(btnToggleRegister,"default-bold-small") registerWindow = guiCreateWindow(screenWidth/2-regWidth/2,screenHeight/2-regHeight/2,regWidth,regHeight,"Registration",false) guiWindowSetSizable(registerWindow,false) editRegistrationUsername = guiCreateEdit(98,138,242,25,"",false,registerWindow) editRegistrationPassword = guiCreateEdit(98,195,242,25,"",false,registerWindow) guiEditSetMasked(editRegistrationPassword,true) editRegistrationRepeatPassword = guiCreateEdit(99,252,242,25,"",false,registerWindow) guiEditSetMasked(editRegistrationRepeatPassword,true) lblRegister = guiCreateLabel(24,24,391,97,"Register",false,registerWindow) guiLabelSetColor(lblRegister,0,85,255) guiLabelSetVerticalAlign(lblRegister,"center") guiLabelSetHorizontalAlign(lblRegister,"center",false) guiSetFont(lblRegister,"sa-gothic") lblRUsername = guiCreateLabel(98,113,242,17,"Username:",false,registerWindow) guiLabelSetColor(lblRUsername,0,85,255) guiLabelSetVerticalAlign(lblRUsername,"center") guiLabelSetHorizontalAlign(lblRUsername,"center",false) guiSetFont(lblRUsername,"default-bold-small") lblRPassword = guiCreateLabel(98,171,242,17,"Password:",false,registerWindow) guiLabelSetColor(lblRPassword,0,85,255) guiLabelSetVerticalAlign(lblRPassword,"center") guiLabelSetHorizontalAlign(lblRPassword,"center",false) guiSetFont(lblRPassword,"default-bold-small") lblRepeatPassword = guiCreateLabel(98,230,242,17,"Repeat password:",false,registerWindow) guiLabelSetColor(lblRepeatPassword,0,85,255) guiLabelSetVerticalAlign(lblRepeatPassword,"center") guiLabelSetHorizontalAlign(lblRepeatPassword,"center",false) guiSetFont(lblRepeatPassword,"default-bold-small") btnCancel = guiCreateButton(232,292,179,38,"Cancel",false,registerWindow) guiSetFont(btnCancel,"default-bold-small") btnConfirmRegistration = guiCreateButton(29,292,179,38,"Confirm & register!",false,registerWindow) guiSetFont(btnConfirmRegistration,"default-bold-small") guiSetVisible(mainWindow, true) guiSetVisible(registerWindow, false) guiSetInputEnabled(true) showCursor(true) addEventHandler("onClientGUIClick",btnLogin,onClickLogin) addEventHandler("onClientGUIClick",btnToggleRegister,onClickRegisterToggle) addEventHandler("onClientGUIClick",btnConfirmRegistration,onClickRegisterConfirm) addEventHandler("onClientGUIClick",btnCancel,onClickCancel) addEventHandler("onRequestIncreaseAttempts",getRootElement(),increaseAttempts) attemptedLogins = 0 end xmlUnloadFile(xmlFile) else xmlFileHandler(true) end addEventHandler("onRequestDisplayPanel",getRootElement(),logoutHandler) end --addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),loginPanel) -- Disable autologin function removeAutoLogin() local xmlFile = xmlLoadFile(xmlFileName) if xmlFile then local status = xmlNodeGetAttribute(xmlFile,"autologin") if status == "true" then xmlNodeSetAttribute(xmlFile,"autologin","false") outputChatBox("#0000FF* #FFFFFFAuto-login is now #FF0000DISABLED#FFFFFF!",255,255,255,true) xmlSaveFile(xmlFile) xmlUnloadFile(xmlFile) else outputChatBox("#0000FF* #FFFFFFAuto-login is already #FF0000DISABLED#FFFFFF!",255,255,255,true) xmlUnloadFile(xmlFile) end end end addCommandHandler("disableauto", removeAutoLogin) -- Enable autologin function addAutoLogin() local xmlFile = xmlLoadFile(xmlFileName) if xmlFile then local status = xmlNodeGetAttribute(xmlFile,"autologin") if status == "false" then xmlNodeSetAttribute(xmlFile,"autologin","true") outputChatBox("#0000FF* #FFFFFFAuto-login is now #00FF00ENABLED#FFFFFF! You will be automatically logged in every time you join the server.",255,255,255,true) setTimer(outputChatBox,1000,1,"#0000FF* #FFFFFFTo #FF0000DISABLE#FFFFFF auto-login, use #ABCDEF/disableauto#FFFFFF!",255,255,255,true) xmlSaveFile(xmlFile) xmlUnloadFile(xmlFile) else outputChatBox("#0000FF* #FFFFFFAuto-login is already #00FF00ENABLED#FFFFFF!",255,255,255,true) xmlUnloadFile(xmlFile) end end end addCommandHandler("enableauto", addAutoLogin) -- LOGIN PLAYER function onClickLogin(button,state) if(button == "left" and state == "up") then if (source == btnLogin) then username = guiGetText(editUsername) password = guiGetText(editPassword) triggerServerEvent("onRequestLogin",getLocalPlayer(),username,password,enableKickPlayer,attemptedLogins,maxLoginAttempts) xmlFileHandler() end end end -- REGISTER PLAYER function onClickRegisterConfirm(button,state) if(button == "left" and state == "up") then if (source == btnConfirmRegistration) then username = guiGetText(editRegistrationUsername) password = guiGetText(editRegistrationPassword) passwordConfirm = guiGetText(editRegistrationRepeatPassword) triggerServerEvent("onRequestRegister",getLocalPlayer(),username,password,passwordConfirm) end end end -- Open registration window function onClickRegisterToggle(button,state) if(button == "left" and state == "up") then if (source == btnToggleRegister) then guiSetVisible(registerWindow, true) guiBringToFront(registerWindow) guiSetInputEnabled(true) showCursor(true) end end end -- Cancel registration function onClickCancel(button,state) if(button == "left" and state == "up") then if (source == btnCancel) then guiSetVisible(mainWindow, true) guiSetVisible(registerWindow, false) guiSetInputEnabled(true) showCursor(true) Link to comment
Dealman Posted January 5, 2015 Share Posted January 5, 2015 (edited) Read about Lua's String Library. There are many ways you could achieve this, most commonly using patterns with regular expressions. You'll find lots of helpful answers if you use Google a bit. For example if you searched the forums regarding colour-coded nicknames you'd find this popular line of code; string.gsub(theString, "#%x%x%x%x%x%x", "") -- Can also be used like this; theString:gsub("#%x%x%x%x%x%x", "") Now you can use the above pattern with whichever string function you'd like to either prevent them from entering hex colour-codes or replace it. You'll learn the most by trial and error and getting used to searching Google for potential hints in the right direction. People providing you full code/examples is but a lazy way to get someone to do it for you. Edited January 5, 2015 by Guest Link to comment
Xabache Posted January 6, 2015 Author Share Posted January 6, 2015 I've noticed that regardless my efforts nothing overwrites what is set in MTA > Settings > Multiplayer > Nick. Whatever is set in the MTA client is what i see in the chat room regardless of there being a totally different login name set on the client.lua side. Example: Xabache password as the client.lua login, is ignored and subject to ehcabaX as set in MTA > Settings > Multiplayer > Nick, and what i see on the map, above the user, and in the chat. How do i force it to use client.lua Login nick only and ignore MTA > Settings > Multiplayer > Nick in all cases. Link to comment
Dealman Posted January 7, 2015 Share Posted January 7, 2015 You can use setPlayerName to change the players nickname temporarily. Obviously, this will be reset to their default whenever they quit your server. This is a sort of security measure so servers can't "troll" people. Link to comment
Xabache Posted January 10, 2015 Author Share Posted January 10, 2015 function onClickLogin(button,state) if(button == "left" and state == "up") then if (source == btnLogin) then username = string.upper(guiGetText(editUsername)) outputChatBox("Debug: 001a") setPlayerName( getLocalPlayer() , username) outputChatBox("Debug: 002a") password = guiGetText(editPassword) triggerServerEvent("onRequestLogin",getLocalPlayer(),username,password,enableKickPlayer,attemptedLogins,maxLoginAttempts) xmlFileHandler() end end end not working to force the login nick "a1" to appear on screen in chat as "A1" instead of the MTA client set nickname JohnDoe... setPlayerName( getLocalPlayer() , username) ..ideas? 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