ZH-CN/aclGroupAddObjectServer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(4 intermediate revisions by one other user not shown)
Line 2: Line 2:
{{Server function}}
{{Server function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function adds an object to the given ACL group. An object can be a player's account, specified as:
此函数用于将对象添加到给定的ACL组。对象可以是玩家的帐户,指定为:
   ''user.<accountname>''
   ''user.<accountname>''


Or a resource, specified as:
或者是资源,指定为:
   ''resource.<resourcename>''
   ''resource.<resourcename>''


Objects are specified as strings. The ACL groups work for the user accounts and the resources that are specified in them.
对象被指定为字符串。ACL组用于用户帐户和其中指定的资源.


==Syntax==  
==语法==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 16: Line 16:
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[aclgroup]]:addObject||}}
{{OOP||[[aclgroup]]:addObject||}}
===Required Arguments===  
===必填参数===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''theGroup:''' The group to add the object name string too.
*'''theGroup:''' 要添加对象名称字符串的组.
*'''theObjectName:''' The object string to add to the given ACL.
*'''theObjectName:''' 要添加到给定ACL的对象字符串.


===Returns===
===返回值===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if the object was successfully added to the ACL, ''false'' if it already existed in the list.
如果对象已成功添加到ACL,则返回“true”;如果对象已存在于列表中,则返回“false”.


==Example==  
==示例==  
<!-- Explain what the example is in a single sentance -->
<!-- Explain what the example is in a single sentance -->
This example makes every player able to use a command named "giveAccountAdminRights" that will add a specific accountname as an ACL object to the "Admin" group.
这个例子使每个玩家都能使用一个名为“giveAccountAdminRights”的命令,这个命令会将一个特定的帐户名作为ACL对象添加到“Admin”组中.
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function giveAdminRights (playerSource, commandName, accountName) --add the function giveAdminRights and specify its arguments
function giveAdminRights (playerSource, commandName, accountName) --添加函数giveAdminRights并指定其参数
if accountName then --if there was an accountName entered then
if accountName then --如果输入了accountName
aclGroupAddObject (aclGetGroup("Admin"), "user."..accountName) --add an ACL object using the form "user.[accountName]" to the ACL group "Admin"
aclGroupAddObject (aclGetGroup("Admin"), "user."..accountName) --使用“user.[accountName]”格式将ACL对象添加到ACL组“Admin”
outputChatBox ("Account '"..accountName.."' succesfully added to the admin group", playerSource) --output a notification to the player who entered the command that the acocunt was successfully added
outputChatBox ("Account '"..accountName.."' succesfully added to the admin group", playerSource) --向输入命令的玩家输出一个通知,通知其账户已成功添加
else --else output an error message and the correct syntax of the command to the player who entered it
else --否则,将错误消息和命令的正确语法输出给输入它的玩家
outputChatBox ("No account name specified.", playerSource)
outputChatBox ("No account name specified.", playerSource)
outputChatBox ("Correct syntax: /giveAccountAdminRights [accountName]", playerSource)
outputChatBox ("Correct syntax: /giveAccountAdminRights [accountName]", playerSource)
Line 40: Line 40:
end
end


addCommandHandler ("giveAccountAdminRights", giveAdminRights) --add a command "giveAccountAdminRights" and attch the function "giveAdminRights" to it
addCommandHandler ("giveAccountAdminRights", giveAdminRights) --添加一个命令“giveAccountAdminRights”并将函数“giveAdminRights”添加到其中
</syntaxhighlight>
</syntaxhighlight>


Line 46: Line 46:
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{ACL_functions}}
{{ACL_functions}}
[[en:aclGroupAddObjectServer]]
 
[[ar:aclGroupAddObjectServer]]
[[en:AclGroupAddObjectServer]]
[[zh-cn:aclGroupAddObjectServer]]

Latest revision as of 18:29, 21 February 2021

此函数用于将对象添加到给定的ACL组。对象可以是玩家的帐户,指定为:

 user.<accountname>

或者是资源,指定为:

 resource.<resourcename>

对象被指定为字符串。ACL组用于用户帐户和其中指定的资源.

语法

bool aclGroupAddObject ( aclgroup theGroup, string theObjectName )

OOP Syntax Help! I don't understand this!

Method: aclgroup:addObject(...)


必填参数

  • theGroup: 要添加对象名称字符串的组.
  • theObjectName: 要添加到给定ACL的对象字符串.

返回值

如果对象已成功添加到ACL,则返回“true”;如果对象已存在于列表中,则返回“false”.

示例

这个例子使每个玩家都能使用一个名为“giveAccountAdminRights”的命令,这个命令会将一个特定的帐户名作为ACL对象添加到“Admin”组中.

function giveAdminRights (playerSource, commandName, accountName) --添加函数giveAdminRights并指定其参数
	if accountName then --如果输入了accountName
		aclGroupAddObject (aclGetGroup("Admin"), "user."..accountName) --使用“user.[accountName]”格式将ACL对象添加到ACL组“Admin”
		outputChatBox ("Account '"..accountName.."' succesfully added to the admin group", playerSource) --向输入命令的玩家输出一个通知,通知其账户已成功添加
	else --否则,将错误消息和命令的正确语法输出给输入它的玩家
		outputChatBox ("No account name specified.", playerSource)
		outputChatBox ("Correct syntax: /giveAccountAdminRights [accountName]", playerSource)
	end
end

addCommandHandler ("giveAccountAdminRights", giveAdminRights) --添加一个命令“giveAccountAdminRights”并将函数“giveAdminRights”添加到其中

See Also