Jump to content

XML Join


Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...