Jump to content

Reading from meta.xml


Recommended Posts

Posted

The script that has to read the content meta.xml maps, it is run by meta.xml some (not all) maps.

It is meta.xml of map:

<?xml version="1.0" encoding="utf-16"?>
<meta>
<include resource="2paq_laptimer" />
(...)
 <settings>
               (...)
	<setting name="#laps" value="[14]" />
 </settings>
</meta>

:arrow: script I run

:arrow: something I need to read

I tried this script, but I have error:

ERROR: ...source-cache/unzipped/2paq_laptimer/lapcounter_s.lua:6: attempt to call global 'getRunningGamemodeMap' (a nil value)

local g_rot = getRootElement()
local g_ResRoot = getResourceRootElement(getThisResource())
local numberOfAllLaps = -1
 
function readNumberOfLapsFromMeta()
local meta = xmlLoadFile(':' ..getResourceName( getRunningGamemodeMap() ) .. '/' .. 'meta.xml')
if not meta then
outputDebugString('Error while loading meta.xml - lap counter: no meta.xml', 2)
return false
end
local settingsNode = xmlFindChild(meta, 'settings', 0)
if not settingsNode then
outputDebugString('Error while loading meta.xml - lap counter: no <settings>', 2)
return false
end
local i_xmlSetting = 0
xml_setting = xmlFindChild(settingsNode, 'setting', i_xmlSetting)
while xml_setting do
if xmlNodeGetAttributes(xml_setting) then
local attrs = xmlNodeGetAttributes(xml_setting)
if attrs.name == laps then
			numberOfAllLaps = attrs.value
			readNumberOfLaps()
break
end
end
	i_xmlSetting = i_xmlSetting + 1
end
end

2paq MTA:SA Race Serwer PL [http://www.2paq.ugu.pl]

YouTube HD - advertisement my server: [

]

Polski wątek mojego serwera na forum.mtasa.com [http://forum.mtasa.com/viewtopic.php?f=124&t=31657]

acp___3.gif

Posted
local meta = xmlLoadFile(':' ..getResourceName( exports.mapmanager:getRunningGamemodeMap() ) .. '/' .. 'meta.xml')

:arrowdown::arrowdown::arrowdown::arrowdown::arrowdown::arrowdown::arrowdown::arrowdown::arrowdown:

ERROR: xmlLoadFile failed; ModifyOtherObjects in ACL denied resource 2paq_laptimer to access race-australiangp

I hope that when added 2paq_laptimer to the ACL will work

2paq MTA:SA Race Serwer PL [http://www.2paq.ugu.pl]

YouTube HD - advertisement my server: [

]

Polski wątek mojego serwera na forum.mtasa.com [http://forum.mtasa.com/viewtopic.php?f=124&t=31657]

acp___3.gif

Posted

The first part work:

INFO: Loading meta.xml - lap counter: race-wurstsaustraliangp

function readNumberOfLapsFromMeta()
local meta = xmlLoadFile(':' ..getResourceName( exports.mapmanager:getRunningGamemodeMap() ) .. '/' .. 'meta.xml')
outputDebugString('Loading meta.xml - lap counter: '..getResourceName( exports.mapmanager:getRunningGamemodeMap() ), 3)
if not meta then
outputDebugString('Error while loading meta.xml - lap counter: no meta.xml', 2)
return false
end
local settingsNode = xmlFindChild(meta, 'settings', 0)
if not settingsNode then
outputDebugString('Error while loading meta.xml - lap counter: no <settings>', 2)
return false
end

ERROR: ERROR: Infinite/too long execution (2paq_laptimer)

local i_xmlSetting = 0
xml_setting = xmlFindChild(settingsNode, 'setting', i_xmlSetting)
while xml_setting do
if xmlNodeGetAttributes(xml_setting) then
local attrs = xmlNodeGetAttributes(xml_setting)
if attrs.name == laps then
			numberOfAllLaps = attrs.value
			readNumberOfLaps()
break
end
end
	i_xmlSetting = i_xmlSetting + 1
end
end

what do I wrong?

Edit:

xml_setting = xmlFindChild(settingsNode, 'setting', i_xmlSetting)
while xml_setting do
if xmlNodeGetAttributes(xml_setting) then
local attrs = xmlNodeGetAttributes(xml_setting)
if attrs.name == "laps" then
			numberOfAllLaps = attrs.value
			readNumberOfLaps()
break
end
end
	i_xmlSetting = i_xmlSetting + 1
	xml_setting = xmlFindChild(settingsNode, 'setting', i_xmlSetting)
end

2paq MTA:SA Race Serwer PL [http://www.2paq.ugu.pl]

YouTube HD - advertisement my server: [

]

Polski wątek mojego serwera na forum.mtasa.com [http://forum.mtasa.com/viewtopic.php?f=124&t=31657]

acp___3.gif

Posted

You're not meant to read the settings data directly, as this can be overridden by admins.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...