Agon Posted February 19, 2012 Share Posted February 19, 2012 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) Link to comment
Castillo Posted February 19, 2012 Share Posted February 19, 2012 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", } Link to comment
Agon Posted February 20, 2012 Author Share Posted February 20, 2012 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? Link to comment
GTX Posted February 20, 2012 Share Posted February 20, 2012 You'll also need to create XML files https://wiki.multitheftauto.com/wiki/XmlCreateFile Link to comment
Agon Posted February 21, 2012 Author Share Posted February 21, 2012 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... Link to comment
Castillo Posted February 21, 2012 Share Posted February 21, 2012 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 ) Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 Oh thank you 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.. Link to comment
Moderators IIYAMA Posted February 22, 2012 Moderators Share Posted February 22, 2012 Oh thank you 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!! Link to comment
drk Posted February 22, 2012 Share Posted February 22, 2012 Oh thank you 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 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 Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 oh thank you guys Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 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? Link to comment
drk Posted February 22, 2012 Share Posted February 22, 2012 (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 February 22, 2012 by Guest Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 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 Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 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 Link to comment
drk Posted February 22, 2012 Share Posted February 22, 2012 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. Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 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? Link to comment
drk Posted February 22, 2012 Share Posted February 22, 2012 xml example: Some amazing text In all xml files. And change xmlFindChild "rules" to your node ( in my example, node is "one" without " " ) Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 Thank you it works 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? addEventHandler("onClientGUIClick",root, function () if (source == closeButton) then guiSetVisible(helpWindow,not guiGetVisible(helpWindow)) showCursor(not isCursorShowing()) end end ) Link to comment
drk Posted February 22, 2012 Share Posted February 22, 2012 Sometimes I get this bug too but I don't know why. Reconnect and try. Link to comment
Agon Posted February 22, 2012 Author Share Posted February 22, 2012 ok thank you guys (again) Link to comment
drk Posted February 22, 2012 Share Posted February 22, 2012 You're welcome We are here to help. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now