Jump to content

Система ID'ов и как правильно пользоваться ей


Recommended Posts

У меня вопрос, как правильно пользоваться системой ID? У меня она есть, работает, но как взаимодействовать с другими скриптами через elementData?

Заранее спасибо.

Link to comment

Дополню, вот скрипт ID системы:

exports [ "scoreboard" ]:addScoreboardColumn ( "ID", 2 )

local player_ID = {}

function getRowInex (login)
    for _, player in ipairs (getElementsByType("player")) do
	    for i, data in ipairs (player_ID) do
		    if data[2] == login then
			    return i
			end
		end
	end
	return false
end

function getRowFree ()
    for i, data in ipairs (player_ID) do
		if data[2] == "" then
			return data[1]
		end
   end
   local new_ID = #player_ID + 1
   table.insert(player_ID, new_ID, {new_ID, ""})
   return new_ID
end

function createAllNumbers ()
    for i = 1, 200 do
	    table.insert(player_ID, i, {i, ""})
	end
	for i, player in ipairs (getElementsByType("player")) do
	    local index = tonumber(getElementData(player, "ID"))
		if index then
		    rawset(player_ID, index, {index, getAccountName(getPlayerAccount(player))})
		else 
		    local index = getRowFree ()
			rawset(player_ID, index, {index, getAccountName(getPlayerAccount(player))})
			setElementData(player, "ID", index)
		end
	end
	
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), createAllNumbers)

function onPlayerLogin (_, account)
    local index = getRowFree ()
	rawset(player_ID, index, {index, getAccountName(account)})
	setElementData(source, "ID", index)
end
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin)

function onPlayerQuit ()
    local index = getRowInex (getAccountName(getPlayerAccount(source)))
	rawset(player_ID, index, {index, ""})
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit)

А вот скрипт, который я хочу использовать:

function giveadm (source, command, ident, lvl)
   if(getElementData(source,"admlvl") > 8) then
   if (ident) then
    for id, player in ipairs ( getElementsByType ( "player" ) ) do
				if ( tonumber(getElementData ( player, "ID" )) ==  tonumber(ident) ) then
   if lvl then
   if((tonumber(lvl) > -1) and (tonumber(lvl) < 11))then
    local RootNode = xmlLoadFile ( "Accounts/"..player..".xml" )
	local playeradmlvl = xmlFindChild ( RootNode, "admlvl", 0 )
	local valueadmlvl = xmlNodeSetValue ( playeradmlvl, lvl.."" )
    setElementData ( player, "admlvl", lvl )
	xmlSaveFile(RootNode)
	xmlUnloadFile(RootNode)
	outputChatBox("* Вы выдали "..lvl.." уровень администратирования игроку "..player..".", source, 255, 215, 0, true)
	else
    outputChatBox("* неверный уровень администратирования", source,255, 215, 0, true)
	end
   else
    outputChatBox("* /makeadmin [id] [0-10]", source,255, 215, 0, true)
   end
end
end
else
outputChatBox ("*/makeadmin [id] [0-10]", source,255, 215, 0, true)
end
else
outputChatBox ("*Вы не имеете доступ", source,255, 215, 0, true)
end
end
addCommandHandler ("makeadmin", giveadm)

Ошибка в RootNode, когда он загружает мой xml файл в аргументе ..player..

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...