anufis_ok Posted June 5, 2018 Share 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) Link to comment
Moderators IIYAMA Posted June 5, 2018 Moderators Share 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 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