RU/aclGroupClone: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Dutchman101 (talk | contribs) (Mentioning author names on script examples isn't adopted practise on the MTA wiki, thanks for understanding) |
||
(2 intermediate revisions by 2 users 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 | |||
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 | 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( | addEventHandler("onResourceStart", resourceRoot, | ||
function( | function() | ||
setTimer(aclGroupClone, 1000, 1, "Console", "OwnersGroup", true, true) -- clone 'Console' Group to 'OwnersGroup' and clone ACLs and objects | |||
end ) | end | ||
) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
==Смотрите также== | ==Смотрите также== | ||
{{RU/Useful_Functions}} | {{RU/Useful_Functions}} | ||
[[en:aclGroupClone]] |
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 » Эта функция получает кол-во оборотов машины.