IsResourceProtected: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server function}} <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> {{New feature/item|3.0158|1.5.7|20468|...")
 
Line 20: Line 20:


==Example==  
==Example==  
<section name="Server" class="server" show="true">
This example creates a command which allows you to check if the given resource with the name provided is protected. The command is "/isprotected [Resource Name]".
{{Needs Example}}
 
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- todo
function resourceProtectedCommand(thePlayer, command, resourceName)
    if resourceName then -- If the player provided a resource name.
        local theResource = getResourceFromName(resourceName) -- Get the resource element.
        if theResource then -- If we have an element, the resource must exist.
            local protectedResource = isResourceProtected(theResource) -- Check to see if the resource is protected.
            if protectedResource then -- if it is protected.
                outputChatBox("This resource is a protected resource in the server config.", thePlayer, 0, 255, 0)
            else -- If the resource is not protected.
                outputChatBox("This resource is not a protected resource in the server config.", thePlayer, 0, 255, 0)
            end
        else -- A resource with the name didn't exist.
            outputChatBox("A resource with the name '" .. resourceName .. "' does not exist!", thePlayer, 255, 0, 0)
        end
    else -- The player didn't provide a resource name.
        outputChatBox("Please specify a resource name.", thePlayer, 255, 0, 0)
    end
end
addCommandHandler("isprotected", resourceProtectedCommand)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
<!-- 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 -->
{{Resource_functions}}
{{Resource_functions}}

Revision as of 09:16, 7 August 2020

This will check if a resource is currently protected, as defined in mtaserver.conf.

Syntax

bool isResourceProtected(resource theResource)

OOP Syntax Help! I don't understand this!

Method: resource:isProtected(...)
Variable: .protected


Required Arguments

  • theResource: the resource to check

Returns

Returns true if the resource is 'protected', false otherwise.

Example

This example creates a command which allows you to check if the given resource with the name provided is protected. The command is "/isprotected [Resource Name]".

function resourceProtectedCommand(thePlayer, command, resourceName)
    if resourceName then -- If the player provided a resource name.
        local theResource = getResourceFromName(resourceName) -- Get the resource element.
        if theResource then -- If we have an element, the resource must exist.
            local protectedResource = isResourceProtected(theResource) -- Check to see if the resource is protected.
            if protectedResource then -- if it is protected.
                outputChatBox("This resource is a protected resource in the server config.", thePlayer, 0, 255, 0)
            else -- If the resource is not protected.
                outputChatBox("This resource is not a protected resource in the server config.", thePlayer, 0, 255, 0)
            end
        else -- A resource with the name didn't exist.
            outputChatBox("A resource with the name '" .. resourceName .. "' does not exist!", thePlayer, 255, 0, 0)
        end
    else -- The player didn't provide a resource name.
        outputChatBox("Please specify a resource name.", thePlayer, 255, 0, 0)
    end
end
addCommandHandler("isprotected", resourceProtectedCommand)

See Also