Jump to content

adding XML Files


Agon

Recommended Posts

Posted

I have 11 xml files (destructionzones.xml, environment.xml, ferriswheel.xml, headquarters.xml ......)

but i don't know how to add them when i click on the row.

should I make 11 functions like "if guiGridListGetSelectedItem(environment) then loadXML("environment.xml")" for all rows?

    function myHelpList(key, keyState) 
        helpWindow = guiCreateWindow(0.1768,0.2188,0.6475,0.6641,"Help Window",true) 
        guiSetAlpha(helpWindow,1) 
        guiWindowSetSizable(helpWindow,false) 
        closeButton = guiCreateButton(0.3725,0.8922,0.2398,0.0784,"Close",true,helpWindow) 
        guiSetFont(closeButton,"default-bold-small") 
        helpMemo = guiCreateMemo(0.2247,0.1471,0.7225,0.7137,"",true,helpWindow) 
        helpGrid = guiCreateGridList(0.0136,0.1451,0.1961,0.7157,true,helpWindow) 
        guiGridListSetSelectionMode(helpGrid,2) 
  
        guiGridListAddColumn(helpGrid,"Freeroam",0.2) 
  
        for i = 1, 11 do 
            guiGridListAddRow(helpGrid) 
end 
  
        guiGridListSetItemText(helpGrid,0,1,"Destruction Zones") 
  
        guiGridListSetItemText(helpGrid,1,1,"Environment") 
  
        guiGridListSetItemText(helpGrid,2,1,"Ferris Wheel") 
  
        guiGridListSetItemText(helpGrid,3,1,"HeadQuarters") 
  
        guiGridListSetItemText(helpGrid,4,1,"Horseshoe Mission") 
  
        guiGridListSetItemText(helpGrid,5,1,"Shops") 
  
        guiGridListSetItemText(helpGrid,6,1,"Skins") 
  
        guiGridListSetItemText(helpGrid,7,1,"UFO") 
  
        guiGridListSetItemText(helpGrid,8,1,"Vehicles") 
  
        guiGridListSetItemText(helpGrid,9,1,"Weapons") 
  
        guiGridListSetItemText(helpGrid,10,1,"Weed Mission") 
    end 
addCommandHandler("help", myHelpList) 
bindKey("F9", "down", myHelpList) 

Posted

I recommend to make a table with the name and the XML file, then when click the grid list load the content of that file.

E.g:

local myFiles = { 
    ["Hello"] = "hello.xml", 
    ["World"] = "world.xml", 
} 

Posted
  
local myFiles = { 
    ["Destruction Zones"] = "destruction.xml", 
    ["Environment"] = "env.xml", 
    ["Ferris Wheel"] = "ferris.xml", 
    ["HeadQuarters"] = "hq.xml", 
    ["Horseshoe Mission"] = "horseshoe.xml", 
    ["Shops"] = "shops.xml", 
    ["Skins"] = "skins.xml", 
    ["UFO"] = "ufo.xml", 
    ["Vehicles"] = "veh.xml", 
    ["Weapons"] = "weap.xml", 
    ["Weed Mission"] = "weed.xml", 
} 
  
function myHelpList(key, keyState) 
        helpWindow = guiCreateWindow(0.1768,0.2188,0.6475,0.6641,"Help Window",true) 
        guiSetAlpha(helpWindow,1) 
        guiWindowSetSizable(helpWindow,false) 
        closeButton = guiCreateButton(0.3725,0.8922,0.2398,0.0784,"Close",true,helpWindow) 
        guiSetFont(closeButton,"default-bold-small") 
        helpEdit = guiCreateEdit(0.2247,0.1471,0.7225,0.7137,"",true,helpWindow) 
        guiEditSetReadOnly( helpEdit, true )  
        helpGrid = guiCreateGridList(0.0136,0.1451,0.1961,0.7157,true,helpWindow) 
        guiGridListSetSelectionMode(helpGrid,2) 
        guiGridListAddColumn(helpGrid,"Freeroam",0.2) 
  
        destructionZones = guiGridListAddRow(helpGrid) 
        environment = guiGridListAddRow(helpGrid) 
        ferrisWheel = guiGridListAddRow(helpGrid) 
        headQuarters = guiGridListAddRow(helpGrid) 
        horseshoeMission = guiGridListAddRow(helpGrid) 
        shops = guiGridListAddRow(helpGrid) 
        skins = guiGridListAddRow(helpGrid) 
        ufo = guiGridListAddRow(helpGrid) 
        vehicles = guiGridListAddRow(helpGrid) 
        weapons = guiGridListAddRow(helpGrid) 
        weedMission = guiGridListAddRow(helpGrid) 
  
        guiGridListSetItemText(helpGrid, destructionZones, Freeroam, "Destruction Zones") 
        guiGridListSetItemText(helpGrid, environment, Freeroam, "Environment") 
        guiGridListSetItemText(helpGrid, ferrisWheel, Freeroam, "Ferris Wheel") 
        guiGridListSetItemText(helpGrid, headQuarters, Freeroam, "HeadQuarters") 
        guiGridListSetItemText(helpGrid, horseshoeMission, Freeroam, "Horseshoe Mission") 
        guiGridListSetItemText(helpGrid, shops, Freeroam, "Shops") 
        guiGridListSetItemText(helpGrid, skins, Freeroam, "Skins") 
        guiGridListSetItemText(helpGrid, ufo, Freeroam, "UFO") 
        guiGridListSetItemText(helpGrid, vehicles, Freeroam, "Vehicles") 
        guiGridListSetItemText(helpGrid, weapons, Freeroam, "Weapons") 
        guiGridListSetItemText(helpGrid, weedMission, Freeroam, "Weed Mission") 
    end 
addCommandHandler("help", myHelpList) 
bindKey("F9", "down", myHelpList) 

So how will i able to load xml files? https://wiki.multitheftauto.com/wiki/XmlLoadFile will this load the xml files into helpEdit? :|

Posted

I know and i've created the xml files (not with createXML function) but i don't know how to import that files when i click the items on gridlist...

Posted
local myFiles = { 
    ["Destruction Zones"] = "destruction.xml", 
    ["Environment"] = "env.xml", 
    ["Ferris Wheel"] = "ferris.xml", 
    ["HeadQuarters"] = "hq.xml", 
    ["Horseshoe Mission"] = "horseshoe.xml", 
    ["Shops"] = "shops.xml", 
    ["Skins"] = "skins.xml", 
    ["UFO"] = "ufo.xml", 
    ["Vehicles"] = "veh.xml", 
    ["Weapons"] = "weap.xml", 
    ["Weed Mission"] = "weed.xml", 
} 
  
function myHelpList(key, keyState) 
    helpWindow = guiCreateWindow(0.1768,0.2188,0.6475,0.6641,"Help Window",true) 
    guiSetAlpha(helpWindow,1) 
    guiWindowSetSizable(helpWindow,false) 
    closeButton = guiCreateButton(0.3725,0.8922,0.2398,0.0784,"Close",true,helpWindow) 
    guiSetFont(closeButton,"default-bold-small") 
    helpEdit = guiCreateEdit(0.2247,0.1471,0.7225,0.7137,"",true,helpWindow) 
    guiEditSetReadOnly( helpEdit, true ) 
    helpGrid = guiCreateGridList(0.0136,0.1451,0.1961,0.7157,true,helpWindow) 
    guiGridListSetSelectionMode(helpGrid,2) 
    guiGridListAddColumn(helpGrid,"Freeroam",0.2) 
    for name, file in pairs(myFiles) do 
        local row = guiGridListAddRow(helpGrid) 
        guiGridListSetItemText(helpGrid,row,1,tostring(name),false,false) 
    end 
end 
addCommandHandler("help", myHelpList) 
bindKey("F9", "down", myHelpList) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        if (source == helpGrid) then 
            local row,col = guiGridListGetSelectedItem(source) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local name = guiGridListGetItemText(source,row,1) 
                if fileExists(myFiles[name]) then 
                    local file = xmlLoadFile(myFiles[name]) 
                    local text = xmlNodeGetValue(file) 
                    guiSetText(helpEdit, tostring(text)) 
                    xmlUnloadFile(file) 
                end 
            end 
        end 
    end 
) 

Posted

Oh thank you :D but can you explain them? You know i'm a still beginner

for name, file in pairs (myFiles) do -- i know this is a table but what can i do with this? What does this do? Where can i use this? 
  
  
if (row and col and row ~= -1 and col ~= -1) then -- and this is a little bit confusing.. 

  • Moderators
Posted
Oh thank you :D but can you explain them? You know i'm a still beginner
for name, file in pairs (myFiles) do -- i know this is a table but what can i do with this? What does this do? Where can i use this? 
if (row and col and row ~= -1 and col ~= -1) then -- and this is a little bit confusing.. 

I also wanna know this.

But I think it is:

Table >

Makes it possible to use function on things inside this table.

(take all the vehicle and use at one of these the script.)

row and col>

first check if they exist.

"row and col and"

Check count of them.

"~= -1 and col ~= -1"

Maybe we can find it here: http://www.lua.org/manual/5.1/manual.html

PLS I seriously need to know if what I am saying is right!! Need some profesional information!!

Posted
Oh thank you :D but can you explain them? You know i'm a still beginner
for name, file in pairs (myFiles) do -- i know this is a table but what can i do with this? What does this do? Where can i use this? 
if (row and col and row ~= -1 and col ~= -1) then -- and this is a little bit confusing.. 

I also wanna know this.

But I think it is:

Table >

Makes it possible to use function on things inside this table.

(take all the vehicle and use at one of these the script.)

row and col>

first check if they exist.

"row and col and"

Check count of them.

"~= -1 and col ~= -1"

Maybe we can find it here: http://www.lua.org/manual/5.1/manual.html

PLS I seriously need to know if what I am saying is right!! Need some profesional information!!

I think you're right.

for name, file in pairs (myFiles) do -- Loop, used mostly when we are working with tables, this define the index ( if exists ) and data stored in it.

pairs -- Is used for all tables ( non-indexed and indexed )

ipairs -- Is used for indexed tables, like the name: i = indexed, pairs = table xD

if row and col and row ~= and col ~= -1 then -- I can't explain right, only what can I say is, if you don't put -1 and if you use onClientGUIClick it will not work when you click in any row...

Start learning Lua: http://lua-users.org/wiki/TutorialDirectory :D

Posted

CLIENT

local myFiles = { 
    ["Destruction Zones"] = "destruction.xml", 
    ["Environment"] = "env.xml", 
    ["Ferris Wheel"] = "ferris.xml", 
    ["HeadQuarters"] = "hq.xml", 
    ["Horseshoe Mission"] = "horseshoe.xml", 
    ["Shops"] = "shops.xml", 
    ["Skins"] = "skins.xml", 
    ["UFO"] = "ufo.xml", 
    ["Vehicles"] = "veh.xml", 
    ["Weapons"] = "weap.xml", 
    ["Weed Mission"] = "weed.xml", 
} 
  
function myHelpList() 
    helpWindow = guiCreateWindow(0.1768,0.2188,0.6475,0.6641,"Help Window",true) 
    guiSetAlpha(helpWindow,1) 
    guiWindowSetSizable(helpWindow,false) 
    closeButton = guiCreateButton(0.3725,0.8922,0.2398,0.0784,"Close",true,helpWindow) 
    guiSetFont(closeButton,"default-bold-small") 
    helpEdit = guiCreateEdit(0.2247,0.1471,0.7225,0.7137,"",true,helpWindow) 
    guiEditSetReadOnly( helpEdit, true ) 
    helpGrid = guiCreateGridList(0.0136,0.1451,0.1961,0.7157,true,helpWindow) 
    showCursor(true) 
    guiGridListSetSelectionMode(helpGrid,2) 
    guiGridListAddColumn(helpGrid,"Freeroam",0.2) 
    for name, file in pairs(myFiles) do 
        local row = guiGridListAddRow(helpGrid) 
        guiGridListSetItemText(helpGrid,row,1,tostring(name),false,false) 
    end 
end 
addCommandHandler("help", myHelpList) 
  
function bindTheKey() 
bindKey("F9", "down", myHelpList) 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), bindTheKey) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        if (source == helpGrid) then 
            local row,col = guiGridListGetSelectedItem(source) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local name = guiGridListGetItemText(source,row,1) 
                if fileExists(myFiles[name]) then 
                    local file = xmlLoadFile(myFiles[name]) 
                    local text = xmlNodeGetValue(file) 
                    guiSetText(helpEdit, tostring(text)) 
                    xmlUnloadFile(file) 
                end 
            end 
        end 
    end 
) 

META.XML

<meta> 
    <info description="Help manager" author="MTA" type="script" version="1.0.0"/> 
    <script src="newhelp.lua" type="server"/> 
    <config src="destruction.xml" type="client"/> 
    <config src="env.xml" type="client"/> 
    <config src="ferris.xml" type="client"/> 
    <config src="horseshoe.xml" type="client"/> 
    <config src="hq.xml" type="client"/> 
    <config src="shops.xml" type="client"/> 
    <config src="skins.xml" type="client"/> 
    <config src="ufo.xml" type="client"/> 
    <config src="veh.xml" type="client"/> 
    <config src="weap.xml" type="client"/> 
    <config src="weed.xml" type="client"/> 
</meta> 

OTHER XMLs (for example skins.xml)

<help> 
blah blah blah 
</help> 

but when i type /help or press F9, the gui doesn't appear. should other xmls' type be server?

Posted (edited)

CLIENT

local myFiles = { 
    ["Destruction Zones"] = "destruction.xml", 
    ["Environment"] = "env.xml", 
    ["Ferris Wheel"] = "ferris.xml", 
    ["HeadQuarters"] = "hq.xml", 
    ["Horseshoe Mission"] = "horseshoe.xml", 
    ["Shops"] = "shops.xml", 
    ["Skins"] = "skins.xml", 
    ["UFO"] = "ufo.xml", 
    ["Vehicles"] = "veh.xml", 
    ["Weapons"] = "weap.xml", 
    ["Weed Mission"] = "weed.xml", 
} 
  
helpWindow = guiCreateWindow(0.1768,0.2188,0.6475,0.6641,"Help Window",true) 
guiSetAlpha(helpWindow,1) 
guiWindowSetSizable(helpWindow,false) 
closeButton = guiCreateButton(0.3725,0.8922,0.2398,0.0784,"Close",true,helpWindow) 
guiSetFont(closeButton,"default-bold-small") 
helpEdit = guiCreateEdit(0.2247,0.1471,0.7225,0.7137,"",true,helpWindow) 
guiEditSetReadOnly( helpEdit, true ) 
helpGrid = guiCreateGridList(0.0136,0.1451,0.1961,0.7157,true,helpWindow) 
guiGridListSetSelectionMode(helpGrid,2) 
guiGridListAddColumn(helpGrid,"Freeroam",0.2) 
  
for name, file in pairs(myFiles) do 
     local row = guiGridListAddRow(helpGrid) 
     guiGridListSetItemText(helpGrid,row,1,tostring(name),false,false) 
end 
  
guiSetVisible(helpWindow,false) 
  
function seeWindow() 
       guiSetVisible(helpWindow,not guiGetVisible(helpWindow)) 
       showCursor(not isCursorShowing()) 
       guiSetInputEnabled(not guiGetInputEnabled()) 
end 
bindKey('f9','down',seeWindow) 
addCommandHandler('help',root,seeWindow) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        if (source == helpGrid) then 
            local row,col = guiGridListGetSelectedItem(source) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local name = guiGridListGetItemText(source,row,1) 
                if fileExists(myFiles[name]) then 
                    local file = xmlLoadFile(myFiles[name]) 
                    local node = xmlFindChild( file, "replaceWithYourNode", 0 ) 
                    local text = xmlNodeGetValue(node) 
                    guiSetText(helpEdit, tostring(text)) 
                    xmlUnloadFile(file) 
                end 
            end 
        end 
    end 
) 

META.XML

<meta> 
    <info description="Help manager" author="MTA" type="script" version="1.0.0"/> 
    <script src="newhelp.lua" type="server"/> 
    <file src="destruction.xml" /> 
    <file src="env.xml" /> 
    <file src="ferris.xml" /> 
    <file src="horseshoe.xml"/> 
    <file src="hq.xml" /> 
    <file src="shops.xml" /> 
    <file src="skins.xml" /> 
    <file src="ufo.xml" /> 
    <file src="veh.xml" /> 
    <file src="weap.xml" /> 
    <file src="weed.xml" /> 
</meta> 

Edited by Guest
Posted

ok made it and changed this

<script src="newhelp.lua" type="server"/> 

to this

<script src="newhelp.lua" type="client"/> 

lol idk why i made it server. but still can't see the gui. the gui doesn't appear with /help or F9. and no error in debugscript 3

Posted

ok it appears but when i click an item it says bad argument @ xmlNodeGetValue and it types "false" instead of my things in my .xml files

Posted

You have to replace "replaceWithYourNode" with your xml's nodes names.

Example: Change in your xml's the node names ( e.g: WHAT THE FUCK ) that you want to get. And set the same for all.

Posted

i know. i made

<rules> 
some test rules 
</rules> 

but didn't work

and this is the thingy you want

local node = xmlFindChild( file, "rules", 0 ) 

right?

Posted

xml example:

      Some amazing text

In all xml files.

And change xmlFindChild "rules" to your node ( in my example, node is "one" without " " )

Posted

Thank you it works :D

and last thing

when i click close it closes but cursor is still there, i press f9 again and click close again, cursor disappears. how can i fix it? :D

addEventHandler("onClientGUIClick",root, 
    function () 
        if (source == closeButton) then 
       guiSetVisible(helpWindow,not guiGetVisible(helpWindow)) 
       showCursor(not isCursorShowing()) 
        end 
    end 
) 

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...