IsResourceArchived: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Fixed build number and added example.)
(Correcting incorrect phrases, replacing the existing example and adding more examples.)
 
Line 2: Line 2:
{{Server function}}
{{Server function}}
{{New feature/item|3.0155|1.5.5|11550|
{{New feature/item|3.0155|1.5.5|11550|
Checks whether a resource is currently archived (running from within a ZIP file).
Checks whether the specified resource is archived. (Currently running from a ZIP file)
}}
}}


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool isResourceArchived ( resource resourceElement )</syntaxhighlight>
<syntaxhighlight lang="lua">bool isResourceArchived(resource resourceElement)</syntaxhighlight>
{{OOP||[[resource]]:isArchived|archived|}}
{{OOP||[[resource]]:isArchived|archived|}}
===Required Arguments===
===Required Arguments===
*'''resource:''' the resource to check
*'''resourceElement:''' The resource to check.


===Returns===
===Returns===
Returns ''true'' if a resource is archived, ''false'' if it is not archived, or ''nil'' if there is problem with resource.
Returns '''true''' if the selected resource is archived, '''false''' if it is not archived, and '''nil''' if some kind of problem occurred.


==Example==
==Example==
<section name="Example 1" class="server" show="true">
This example stops the resource if it's archived.
<syntaxhighlight lang="lua">
addEventHandler("onResourceStart", resourceRoot,
function(resourceElement)
if isResourceArchived(resourceElement) then
cancelEvent()
end
end
)
</syntaxhighlight>
</section>


This example stops the resource from loading if it's archived
<section name="Example 2 (OOP)" class="server" show="true">
This example stops the resource if it's archived by using the object oriented method. '''(It's important to note that you need to enable OOP in meta.xml to use this)'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function resourceLoading( res )
addEventHandler("onResourceStart", resourceRoot,
    if res.archived then
function(resourceElement)
        cancelEvent()
if resourceElement:isArchived() then
    end
cancelEvent()
end
end
)
</syntaxhighlight>
</section>


end
<section name="Example 3 (OOP)" class="server" show="true">
addEventHandler('onResourcePreStart',root,resourceLoading,true,'high+10')
This example stops the resource if it's archived by using the object oriented variable. '''(It's important to note that you need to enable OOP in meta.xml to use this)'''
<syntaxhighlight lang="lua">
addEventHandler("onResourceStart", resourceRoot,
function(resourceElement)
if resourceElement.archived then
cancelEvent()
end
end
)
</syntaxhighlight>
</syntaxhighlight>
</section>
==See Also==
==See Also==
{{Resource functions}}
{{Resource functions}}

Latest revision as of 03:13, 12 August 2023

Checks whether the specified resource is archived. (Currently running from a ZIP file)

Syntax

bool isResourceArchived(resource resourceElement)

OOP Syntax Help! I don't understand this!

Method: resource:isArchived(...)
Variable: .archived


Required Arguments

  • resourceElement: The resource to check.

Returns

Returns true if the selected resource is archived, false if it is not archived, and nil if some kind of problem occurred.

Example

Click to collapse [-]
Example 1

This example stops the resource if it's archived.

addEventHandler("onResourceStart", resourceRoot,
	function(resourceElement)
		if isResourceArchived(resourceElement) then
			cancelEvent()
		end
	end
)
Click to collapse [-]
Example 2 (OOP)

This example stops the resource if it's archived by using the object oriented method. (It's important to note that you need to enable OOP in meta.xml to use this)

addEventHandler("onResourceStart", resourceRoot,
	function(resourceElement)
		if resourceElement:isArchived() then
			cancelEvent()
		end
	end
)
Click to collapse [-]
Example 3 (OOP)

This example stops the resource if it's archived by using the object oriented variable. (It's important to note that you need to enable OOP in meta.xml to use this)

addEventHandler("onResourceStart", resourceRoot,
	function(resourceElement)
		if resourceElement.archived then
			cancelEvent()
		end
	end
)

See Also