anufis_ok Posted June 5, 2018 Posted June 5, 2018 Hello.I need that players do not register and the code is saved and joined to the server. Help please. local ALLOW_SAVE = true; local SAVE_TIME = 60; function onPlayerLogin(_,account) if not xmlLoadFile("users/"..getAccountName(account)..".xml") then local XMLROOT = xmlCreateFile("users/"..getAccountName(account)..".xml","user"); xmlCreateChild(XMLROOT, "Nickname") xmlCreateChild(XMLROOT, "Money") xmlCreateChild(XMLROOT, "Skin") xmlSaveFile(XMLROOT); xmlUnloadFile(XMLROOT); else local XMLROOT = xmlLoadFile("users/"..getAccountName(account)..".xml"); local Money = xmlNodeGetValue (xmlFindChild( XMLROOT, "Money", 0 )); local Skin = xmlNodeGetValue (xmlFindChild( XMLROOT, "Skin", 0 )); setPlayerMoney(source,Money); setElementModel(source,Skin); xmlSaveFile(XMLROOT); xmlUnloadFile(XMLROOT); end setElementData(source,"account:name",getAccountName(account)) end function onPlayerLogout() local XMLROOT = xmlLoadFile("users/"..getElementData(source,"account:name")..".xml"); if XMLROOT then xmlNodeSetValue (xmlFindChild( XMLROOT, "Money", 0), getPlayerMoney(source)); xmlNodeSetValue (xmlFindChild( XMLROOT, "Skin", 0), getElementModel(source)); xmlSaveFile(XMLROOT); xmlUnloadFile(XMLROOT); end end function saveAllAccounts() for key, thePlayer in ipairs(getElementsByType("player")) do local XMLROOT = xmlLoadFile("users/"..getElementData(thePlayer,"account:name")..".xml"); if XMLROOT then xmlNodeSetValue (xmlFindChild( XMLROOT, "Money", 0), getPlayerMoney(thePlayer)); xmlNodeSetValue (xmlFindChild( XMLROOT, "Skin", 0), getElementModel(thePlayer)); xmlSaveFile(XMLROOT); xmlUnloadFile(XMLROOT); end end print(" "); print(" *** All accounts are saved! / Все аккаунты сохранены ***"); print(" "); end if ALLOW_SAVE then setTimer(saveAllAccounts,SAVE_TIME*60000,0) end addEventHandler("onResourceStop", getResourceRootElement(),saveAllAccounts) addEventHandler("onPlayerLogin", root,onPlayerLogin) addEventHandler("onPlayerLogout", root,onPlayerLogout) addEventHandler("onPlayerQuit", root,onPlayerLogout)
Moderators IIYAMA Posted June 5, 2018 Moderators Posted June 5, 2018 (edited) @anufis_ok Check if a player is logged-in with: https://wiki.multitheftauto.com/wiki/IsGuestAccount Edited June 5, 2018 by IIYAMA Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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