XmlLoadData: Difference between revisions
No edit summary |
mNo edit summary |
||
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<pageclass class="#228B22" subcaption="Useful Function - Shared"></pageclass> | <pageclass class="#228B22" subcaption="Useful Function - Shared"></pageclass> | ||
<lowercasetitle></lowercasetitle> | <lowercasetitle></lowercasetitle> | ||
__NOTOC__ | |||
{{Important Note| | {{Important Note| | ||
Line 12: | Line 11: | ||
This function provides an automated way of loading your data from an [[XML]] file created by [[xmlSaveData]] <br> | This function provides an automated way of loading your data from an [[XML]] file created by [[xmlSaveData]] <br> | ||
To call | To call it, see the [[call]] function or the tip in this resources page: [https://wiki.multitheftauto.com/wiki/XmlData#Simplifying_the_export Simplifying the export] | ||
= Info = | |||
'''For proper data loading you need to pass the same booleans / securityLevel as you did on xmlSaveData.'''<br> | |||
'''If you called [[xmlSaveData]] with passing the securityLevel its recommended to pick securityLevel as function paremeter for the loading as well.''' | |||
Line 18: | Line 22: | ||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool xmlLoadData ( fileName [, serverProtected, resourceProtected | bool xmlLoadData ( string fileName [, bool serverProtected = true, bool resourceProtected = false ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool | bool xmlLoadData ( string fileName [, int securityLevel = 4 ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
====Required Arguments==== | ====Required Arguments==== | ||
*'''fileName:''' The name of the file you want to | *'''fileName:''' The name of the file you want to load. | ||
====Optional Arguments==== | ====Optional Arguments==== | ||
*'''serverProtected:''' If set to ''true'' it can only read the file | *'''serverProtected:''' If set to ''true'' it can only read the file of the creator-server, otherwise it doesn't care which server created it. | ||
*'''resourceProtected:''' If set to ''true'' it can only read the file | *'''resourceProtected:''' If set to ''true'' it can only read the file of the creator-resource, otherwise it doesn't care which resource created it. | ||
or | or | ||
*'''securityLevel:''' The level of security on which | *'''securityLevel:''' The level of security on which your data is stored at. (Details on the resource page: [https://wiki.multitheftauto.com/wiki/XmlData#Security_Levels Security Levels]) | ||
'''See [https://wiki.multitheftauto.com/wiki/XmlData#Variables_and_Specified_Names Variables and Specified names] for more detail.''' | '''See [https://wiki.multitheftauto.com/wiki/XmlData#Variables_and_Specified_Names xmlData Variables and Specified names] for more detail.''' | ||
===Returns=== | ===Returns=== | ||
Returns '' | Returns a ''table'' containing the files data, an empty ''table'' if there is no data stored inside the file, ''false'' and debug output in case if failure. | ||
'''Note: There is no encryption parameter in this function, because xmlLoadData will load and use a files key if it is encrypted.''' | '''Note: There is no encryption parameter in this function, because xmlLoadData will load and use a files key if it is encrypted.''' | ||
Line 45: | Line 48: | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool | bool xmlLoadData ( string fileName [, bool resourceProtected = false ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool xmlSaveData ( string fileName | bool xmlSaveData ( string fileName [, int securityLevel = 4] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
====Required Arguments==== | ====Required Arguments==== | ||
*'''fileName:''' The name of the file you want to | *'''fileName:''' The name of the file you want to load. | ||
====Optional Arguments==== | ====Optional Arguments==== | ||
*''' | *'''resourceProtected:''' If set to ''true'' it can only read the file of the creator-resource, otherwise it doesn't care which resource created it. | ||
or | or | ||
*'''securityLevel:''' The level of security on which | *'''securityLevel:''' The level of security on which your data is stored at. (Details on the resource page: [https://wiki.multitheftauto.com/wiki/XmlData#Security_Levels Security Levels]) | ||
'''See [https://wiki.multitheftauto.com/wiki/XmlData#Variables_and_Specified_Names xmlData Variables and Specified names] for more detail.''' | |||
===Returns=== | ===Returns=== | ||
Returns '' | Returns a ''table'' containing the files data, an empty ''table'' if there is no data stored inside the file, ''false'' and debug output in case if failure. | ||
''' | '''Note1: There is no encryption parameter, because xmlLoadData will load and use a files key if it is encrypted.'''<br> | ||
'''Note2: There is no serverProtected parameter, because its server-side already anyways. | |||
</section> | </section> | ||
Line 70: | Line 75: | ||
== Example == | == Example == | ||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Lets assume we created a encrypted, serverProtected file called "settings" already. | |||
local xml = exports.xmlData | local xml = exports.xmlData | ||
local | local tblSettings = xml:xmlLoadData("settings" true) -- serverProtected is true, resourceProtected false - false doesnt need to get passed here | ||
-- OR you can do this: | |||
local tblSettings = xml:xmlLoadData("settings" 6) -- securityLevel 6 equals serverProtected, encrypted, not resouceProtected - the encryption bool will be ignored at xmlLoadData | |||
</syntaxhighlight> | |||
</section> | |||
==See Also== | |||
{{Template:Shared_xml_functions}} | |||
[[Category:Useful Functions]] | |||
Latest revision as of 16:36, 13 September 2019
Important Note:
This is an unofficial MTA function, so its not included into the game by default. |
This function provides an automated way of loading your data from an XML file created by xmlSaveData
To call it, see the call function or the tip in this resources page: Simplifying the export
Info
For proper data loading you need to pass the same booleans / securityLevel as you did on xmlSaveData.
If you called xmlSaveData with passing the securityLevel its recommended to pick securityLevel as function paremeter for the loading as well.
Syntax
bool xmlLoadData ( string fileName [, bool serverProtected = true, bool resourceProtected = false ] )
bool xmlLoadData ( string fileName [, int securityLevel = 4 ] )
Required Arguments
- fileName: The name of the file you want to load.
Optional Arguments
- serverProtected: If set to true it can only read the file of the creator-server, otherwise it doesn't care which server created it.
- resourceProtected: If set to true it can only read the file of the creator-resource, otherwise it doesn't care which resource created it.
or
- securityLevel: The level of security on which your data is stored at. (Details on the resource page: Security Levels)
See xmlData Variables and Specified names for more detail.
Returns
Returns a table containing the files data, an empty table if there is no data stored inside the file, false and debug output in case if failure.
Note: There is no encryption parameter in this function, because xmlLoadData will load and use a files key if it is encrypted.
bool xmlLoadData ( string fileName [, bool resourceProtected = false ] )
bool xmlSaveData ( string fileName [, int securityLevel = 4] )
Required Arguments
- fileName: The name of the file you want to load.
Optional Arguments
- resourceProtected: If set to true it can only read the file of the creator-resource, otherwise it doesn't care which resource created it.
or
- securityLevel: The level of security on which your data is stored at. (Details on the resource page: Security Levels)
See xmlData Variables and Specified names for more detail.
Returns
Returns a table containing the files data, an empty table if there is no data stored inside the file, false and debug output in case if failure.
Note1: There is no encryption parameter, because xmlLoadData will load and use a files key if it is encrypted.
Note2: There is no serverProtected parameter, because its server-side already anyways.
Example
-- Lets assume we created a encrypted, serverProtected file called "settings" already. local xml = exports.xmlData local tblSettings = xml:xmlLoadData("settings" true) -- serverProtected is true, resourceProtected false - false doesnt need to get passed here -- OR you can do this: local tblSettings = xml:xmlLoadData("settings" 6) -- securityLevel 6 equals serverProtected, encrypted, not resouceProtected - the encryption bool will be ignored at xmlLoadData