RU/aclGroupClone: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Mentioning author names on script examples isn't adopted practise on the MTA wiki, thanks for understanding)
 
(One intermediate revision by the same user not shown)
Line 16: Line 16:
<section name="Сервер" class="server" show="true">
<section name="Сервер" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function aclGroupClone( clonedGroup, groupName, aclsClone, objectsClone )
function aclGroupClone(clonedGroup, groupName, aclsClone, objectsClone)
if ( type( clonedGroup ) ~= 'string' ) then  
    if (type(clonedGroup) ~= "string") then
error( "Bad argument @ 'aclGroupClone' [Expected string at argument 1, got " .. tostring( clonedGroup ) .. "]" ) return false end
        error("Bad argument @ 'aclGroupClone' [Expected string at argument 1, got " .. tostring(clonedGroup) .. "]")
if ( aclsClone == true or aclsClone == false ) then  
        return false
if ( objectsClone == true or objectsClone == false ) then  
    end
local cloned = aclGetGroup( clonedGroup )
 
if ( cloned == false or not cloned ) then
    if (aclsClone == true or aclsClone == false) then
outputDebugString( "Bad argument @ 'aclGroupClone' [Expected acl-group at argument 1, got string '" .. tostring( clonedGroup ) .. "']", 2 ) return false end
        if (objectsClone == true or objectsClone == false) then
local newGroup = aclCreateGroup( groupName )
            local cloned = aclGetGroup(clonedGroup)
if ( newGroup == false or not newGroup ) then
 
outputDebugString( "Bad argument @ 'aclGroupClone' [Expected acl-group at argument 2, got string '" .. tostring( groupName ) .. "']", 2 ) return false end
            if (cloned == false or not cloned) then
if ( aclsClone == true ) then
                outputDebugString("Bad argument @ 'aclGroupClone' [Expected acl-group at argument 1, got string '" .. tostring(clonedGroup) .. "']", 2)
for index, value in ipairs( aclGroupListACL( cloned ) ) do
                return false
aclGroupAddACL( newGroup, value )
            end
end
 
end
            local newGroup = aclCreateGroup(groupName)
if ( objectsClone == true ) then
 
for index, value in ipairs( aclGroupListObjects( cloned ) ) do
            if (newGroup == false or not newGroup) then
aclGroupAddObject( newGroup, value )
                outputDebugString("Bad argument @ 'aclGroupClone' [Expected acl-group at argument 2, got string '" .. tostring(groupName) .. "']", 2)
end
                return false
end
            end
outputDebugString( "'aclGroupClone' [The group '"..clonedGroup.."' has been cloned successfully to '"..groupName.."' .", 3 ) return true
 
else error( "Bad argument @ 'aclGroupClone' [Expected boolean at argument 4, got " .. tostring( objectsClone ) .. "]" ) return false
            if (aclsClone == true) then
end
                for index, value in ipairs(aclGroupListACL(cloned)) do
else error( "Bad argument @ 'aclGroupClone' [Expected boolean at argument 3, got " .. tostring( aclsClone ) .. "]" ) return false
                    aclGroupAddACL(newGroup, value)
end
                end
            end
 
            if (objectsClone == true) then
                for index, value in ipairs(aclGroupListObjects(cloned)) do
                    aclGroupAddObject(newGroup, value)
                end
            end
 
            outputDebugString("'aclGroupClone' [The group '" .. clonedGroup .. "' has been cloned successfully to '" .. groupName .. "' .", 3)
            return true
        else
            error("Bad argument @ 'aclGroupClone' [Expected boolean at argument 4, got " .. tostring(objectsClone) .. "]")
            return false
        end
    else
        error("Bad argument @ 'aclGroupClone' [Expected boolean at argument 3, got " .. tostring(aclsClone) .. "]")
        return false
    end
end
end
</syntaxhighlight></section>
</syntaxhighlight></section>
Line 49: Line 67:
<section name="Сервер" class="server" show="true">
<section name="Сервер" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler( 'onResourceStart', resourceRoot,
addEventHandler("onResourceStart", resourceRoot,
function( )
    function()
setTimer( aclGroupClone, 1000, 1, 'Console', 'OwnersGroup', true, true )
        setTimer(aclGroupClone, 1000, 1, "Console", "OwnersGroup", true, true) -- clone 'Console' Group to 'OwnersGroup' and clone ACLs and objects
end )
    end
)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
'''Автор''': MR.GRAND
'''Перевел''': Alex7202


==Смотрите также==
==Смотрите также==

Latest revision as of 22:02, 12 December 2020


Эта функция создает копию группы с другим названием с/буз ACL'ов и/или объектов.

Синтаксис

bool aclGroupClone ( string groupToClone, string groupName, bool cloneACLs, bool cloneObjects )

Required Arguments

  • groupToClone: Какую группу копировать
  • groupName: Название копии
  • cloneACLs: true чтобы копировать ACL'ы, false чтобы не копировать ACL'ы
  • cloneObjects: true чтобы копировать объекты, false чтобы не копировать объекты

Возврат

Вернет true если все успешно, false наоборот.

Код

Click to collapse [-]
Сервер
function aclGroupClone(clonedGroup, groupName, aclsClone, objectsClone)
    if (type(clonedGroup) ~= "string") then
        error("Bad argument @ 'aclGroupClone' [Expected string at argument 1, got " .. tostring(clonedGroup) .. "]")
        return false
    end

    if (aclsClone == true or aclsClone == false) then
        if (objectsClone == true or objectsClone == false) then
            local cloned = aclGetGroup(clonedGroup)

            if (cloned == false or not cloned) then
                outputDebugString("Bad argument @ 'aclGroupClone' [Expected acl-group at argument 1, got string '" .. tostring(clonedGroup) .. "']", 2)
                return false
            end

            local newGroup = aclCreateGroup(groupName)

            if (newGroup == false or not newGroup) then
                outputDebugString("Bad argument @ 'aclGroupClone' [Expected acl-group at argument 2, got string '" .. tostring(groupName) .. "']", 2)
                return false
            end

            if (aclsClone == true) then
                for index, value in ipairs(aclGroupListACL(cloned)) do
                    aclGroupAddACL(newGroup, value)
                end
            end

            if (objectsClone == true) then
                for index, value in ipairs(aclGroupListObjects(cloned)) do
                    aclGroupAddObject(newGroup, value)
                end
            end

            outputDebugString("'aclGroupClone' [The group '" .. clonedGroup .. "' has been cloned successfully to '" .. groupName .. "' .", 3)
            return true
        else
            error("Bad argument @ 'aclGroupClone' [Expected boolean at argument 4, got " .. tostring(objectsClone) .. "]")
            return false
        end
    else
        error("Bad argument @ 'aclGroupClone' [Expected boolean at argument 3, got " .. tostring(aclsClone) .. "]")
        return false
    end
end

Пример

Клонируем 'Console' группу в 'OwnersGroup' и клонируем все ACL и объекты

Click to collapse [-]
Сервер
addEventHandler("onResourceStart", resourceRoot,
    function()
        setTimer(aclGroupClone, 1000, 1, "Console", "OwnersGroup", true, true) -- clone 'Console' Group to 'OwnersGroup' and clone ACLs and objects
    end
)

Смотрите также

Функции таблиц

  • pairsByKeys » Эта функция сортирует pairs таблицы.

ACL фунции

  • aclGroupClone » Эта функция создает копию группы с другим названием с/буз ACL'ов и/или объектов.

События

  • isEventHandlerAdded » Эта функция проверяет, создано событие или нет.

Функции машины

  • getVehicleRPM » Эта функция получает кол-во оборотов машины.