Jump to content

Reading from xml.


Recommended Posts

Hello,

I be new at multi theft auto and lua, and i think i do it very well :D

But i have a problem with reading from a xml file.

I have to ellements in the xml file:

The text that will show in guiCreateMemo()

The text that will show in guiCreateMemo()

The xml file:

  
<memo> 
    Hello, 
    \n\n 
    In this tab "order" you can order the next things:  
    \n\n 
        1. Vehicle's 
        2. Vehicle upgrade 
        3. Sell your vehicle's 
    \n\n 
    The max vehicle's to buy are 5! 
    \n\n 
    Nice driving, 
    \n\n 
    LexLife team. 
</memo> 
  
<buyMemo> 
    Hello, 
    \n\n 
    In this tab you can buy a vehicle, but we are busy at the system so for now, you cant. 
    \n\n 
    Nice driving, 
    \n\n 
    LexLife team. 
    </buyMemo> 
</text> 
  

The code where i want it to load:

  
addEventHandler( "onClientResourceStart", g_this_root,  
    function( theResource ) 
        if theResource == getThisResource() then  
            local x, y = guiGetScreenSize()  
            vehicleWindow = guiCreateWindow(x / 2 - 310, y / 2 - 260, 620, 520, "LexLife - VehicleMenu", false) 
             
            vehtabPanel = guiCreateTabPanel(0.01, 0.05, 0.98, 0.95, true, vehicleWindow) 
             
            vehTab = {} 
            vehTab.Tab = guiCreateTab("Vehicle info", vehtabPanel) 
            vehTab.Messages = guiCreateLabel ( 0.68, 0.05, 0.45, 0.04, "Health: 1000%", true, vehTab.Tab ) 
            vehTab.ownVehiclesSearch = guiCreateEdit ( 0.03, 0.05, 0.16, 0.04, "", true, vehTab.Tab ) 
             
            vehTab2 = {} 
            vehTab2.Tab = guiCreateTab("Order", vehtabPanel) 
            vehTab2.Messages = guiCreateLabel(0.01, 0.0, 0.55, 0.03, "Here you can buy/sell/upgrade vehicles", true, vehTab2.Tab) 
            vehTab2.buyCarbtn = guiCreateButton(0.01, 0.05, 0.25, 0.04, "Buy an car", true, vehTab2.Tab) 
            vehTab2.sellCarbtn = guiCreateButton(0.01, 0.12, 0.25, 0.04, "Sell your vehicle", true, vehTab2.Tab) 
            vehTab2.upgCarbtn = guiCreateButton(0.01, 0.18, 0.25, 0.04, "Upgrade your vehicle", true, vehTab2.Tab) 
             
            Node = xmlLoadFile("client\\text\\vehicle_order_text.xml") 
             
            MemoText = xmlNodeGetAttribute(Node, "memo") 
            buyMemoText = xmlNodeGetAttribute(Node, "buyMemo") 
             
            xmlUnloadFile(Node) 
             
            vehTab2.Memo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, MemoText, true, vehTab2.Tab) 
            vehTab2.buyMemo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, buyMemoText, true, vehTab2.Tab) 
                         
            guiSetVisible(vehTab2.buyMemo, false) 
             
            addEventHandler( "onClientGUIClick", vehTab2.buyCarbtn,  
                function() 
                    if source == vehTab2.buyCarbtn then 
                        guiSetVisible(vehTab2.Memo, false) 
                        guiSetVisible(vehTab2.buyMemo, true) 
                    end 
                end 
            )            
            showCursor(false) 
            guiSetVisible(vehicleWindow, false) 
             
            unbindKey("f1", "down") 
            unbindKey("f2", "down") 
            bindKey("f1", "down", showUi) 
            bindKey("f2", "down", hideUi)            
        end 
    end 
) 
  

I hope someone will help me out.

Thanks, Alexander

Link to comment

Hello,

I be new at multi theft auto and lua, and i think i do it very well :D

But i have a problem with reading from a xml file.

I have to ellements in the xml file:

The text that will show in guiCreateMemo()

The text that will show in guiCreateMemo()

The xml file:

     Hello,    \n\n    In this tab "order" you can order the next things:     \n\n        1. Vehicle's        2. Vehicle upgrade        3. Sell your vehicle's    \n\n    The max vehicle's to buy are 5!    \n\n    Nice driving,    \n\n    LexLife team.     Hello,    \n\n    In this tab you can buy a vehicle, but we are busy at the system so for now, you cant.    \n\n    Nice driving,    \n\n    LexLife team.     

The code where i want it to load:

 addEventHandler( "onClientResourceStart", g_this_root,     function( theResource )        if theResource == getThisResource() then             local x, y = guiGetScreenSize()             vehicleWindow = guiCreateWindow(x / 2 - 310, y / 2 - 260, 620, 520, "LexLife - VehicleMenu", false)                        vehtabPanel = guiCreateTabPanel(0.01, 0.05, 0.98, 0.95, true, vehicleWindow)                        vehTab = {}            vehTab.Tab = guiCreateTab("Vehicle info", vehtabPanel)            vehTab.Messages = guiCreateLabel ( 0.68, 0.05, 0.45, 0.04, "Health: 1000%", true, vehTab.Tab )            vehTab.ownVehiclesSearch = guiCreateEdit ( 0.03, 0.05, 0.16, 0.04, "", true, vehTab.Tab )                        vehTab2 = {}            vehTab2.Tab = guiCreateTab("Order", vehtabPanel)            vehTab2.Messages = guiCreateLabel(0.01, 0.0, 0.55, 0.03, "Here you can buy/sell/upgrade vehicles", true, vehTab2.Tab)            vehTab2.buyCarbtn = guiCreateButton(0.01, 0.05, 0.25, 0.04, "Buy an car", true, vehTab2.Tab)            vehTab2.sellCarbtn = guiCreateButton(0.01, 0.12, 0.25, 0.04, "Sell your vehicle", true, vehTab2.Tab)            vehTab2.upgCarbtn = guiCreateButton(0.01, 0.18, 0.25, 0.04, "Upgrade your vehicle", true, vehTab2.Tab)                        Node = xmlLoadFile("client\\text\\vehicle_order_text.xml")                        MemoText = xmlNodeGetAttribute(Node, "memo")            buyMemoText = xmlNodeGetAttribute(Node, "buyMemo")                        xmlUnloadFile(Node)                        vehTab2.Memo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, MemoText, true, vehTab2.Tab)            vehTab2.buyMemo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, buyMemoText, true, vehTab2.Tab)                                    guiSetVisible(vehTab2.buyMemo, false)                        addEventHandler( "onClientGUIClick", vehTab2.buyCarbtn,                 function()                    if source == vehTab2.buyCarbtn then                        guiSetVisible(vehTab2.Memo, false)                        guiSetVisible(vehTab2.buyMemo, true)                    end                end            )                       showCursor(false)            guiSetVisible(vehicleWindow, false)                        unbindKey("f1", "down")            unbindKey("f2", "down")            bindKey("f1", "down", showUi)            bindKey("f2", "down", hideUi)                   end    end) 

I hope someone will help me out.

Thanks, Alexander

Link to comment

try

<xml> 
<node memo="   Hello, 
    \n\n 
    In this tab "order" you can order the next things: 
    \n\n 
        1. Vehicle's 
        2. Vehicle upgrade 
        3. Sell your vehicle's 
    \n\n 
    The max vehicle's to buy are 5! 
    \n\n 
    Nice driving, 
    \n\n 
    LexLife team." /> 
<node buyMemo="    Hello, 
    \n\n 
    In this tab you can buy a vehicle, but we are busy at the system so for now, you cant. 
    \n\n 
    Nice driving, 
    \n\n 
    LexLife team." /> 
</xml> 

or you could split both them into seperate xml's and use this for each xml (or if you are feeling more adventurous, get lua to split them up from the same xml )

node = xmlLoadFile("hai.xml") 
nodetext = xmlNodeGetValue(node) 

and yes you will need to add to your meta.xml (remember to type run the command 'refresh' to make server load the meta.xml changes)

Link to comment

try

>memo="   Hello,    \n\n    In this tab "order" you can order the next things:    \n\n        1. Vehicle's        2. Vehicle upgrade        3. Sell your vehicle's    \n\n    The max vehicle's to buy are 5!    \n\n    Nice driving,    \n\n    LexLife team." />buyMemo="    Hello,    \n\n    In this tab you can buy a vehicle, but we are busy at the system so for now, you cant.    \n\n    Nice driving,    \n\n    LexLife team." />>

or you could split both them into seperate xml's and use this for each xml (or if you are feeling more adventurous, get lua to split them up from the same xml )

node = xmlLoadFile("hai.xml")nodetext = xmlNodeGetValue(node)

and yes you will need to add to your meta.xml (remember to type run the command 'refresh' to make server load the meta.xml changes)

Link to comment

Hello,

Thanks, but still doesn't work.

I've got the updated xml file:

  
<memo wlcTxt="Hello, 
    \n\n 
    In this tab 'order' you can order the next things:  
    \n\n 
        1. Vehicle's 
        2. Vehicle upgrade 
        3. Sell your vehicle's 
    \n\n 
    The max vehicle's to buy are 5! 
    \n\n 
    Nice driving, 
    \n\n 
    LexLife team." /> 
  
<memo buyTxt="  
    Hello, 
    \n\n 
    In this tab you can buy a vehicle, but we are busy at the system so for now, you cant. 
    \n\n 
    Nice driving, 
    \n\n 
    LexLife team." /> 
  

And the updated code:

  
addEventHandler( "onClientResourceStart", g_this_root,  
    function( theResource ) 
        if theResource == getThisResource() then  
            local x, y = guiGetScreenSize()  
            vehicleWindow = guiCreateWindow(x / 2 - 310, y / 2 - 260, 620, 520, "LexLife - VehicleMenu", false) 
             
            vehtabPanel = guiCreateTabPanel(0.01, 0.05, 0.98, 0.95, true, vehicleWindow) 
             
            vehTab = {} 
            vehTab.Tab = guiCreateTab("Vehicle info", vehtabPanel) 
            vehTab.Messages = guiCreateLabel ( 0.68, 0.05, 0.45, 0.04, "Health: 1000%", true, vehTab.Tab ) 
            vehTab.ownVehiclesSearch = guiCreateEdit ( 0.03, 0.05, 0.16, 0.04, "", true, vehTab.Tab ) 
             
            vehTab2 = {} 
            vehTab2.Tab = guiCreateTab("Order", vehtabPanel) 
            vehTab2.Messages = guiCreateLabel(0.01, 0.0, 0.55, 0.03, "Here you can buy/sell/upgrade vehicles", true, vehTab2.Tab) 
            vehTab2.buyCarbtn = guiCreateButton(0.01, 0.05, 0.25, 0.04, "Buy an car", true, vehTab2.Tab) 
            vehTab2.sellCarbtn = guiCreateButton(0.01, 0.12, 0.25, 0.04, "Sell your vehicle", true, vehTab2.Tab) 
            vehTab2.upgCarbtn = guiCreateButton(0.01, 0.18, 0.25, 0.04, "Upgrade your vehicle", true, vehTab2.Tab) 
             
            Node = xmlLoadFile("client\\text\\vehicle_order_text.xml") 
            nodetext = xmlNodeGetValue(Node) 
             
            MemoText = xmlNodeGetAttribute(nodetext, "wlcTxt") 
            buyMemoText = xmlNodeGetAttribute(nodetext, "buyTxt") 
             
            xmlUnloadFile(Node) 
             
            vehTab2.Memo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, MemoText, true, vehTab2.Tab) 
            vehTab2.buyMemo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, buyMemoText, true, vehTab2.Tab) 
                         
            guiSetVisible(vehTab2.buyMemo, false) 
             
            addEventHandler( "onClientGUIClick", vehTab2.buyCarbtn,  
                function() 
                    if source == vehTab2.buyCarbtn then 
                        guiSetVisible(vehTab2.Memo, false) 
                        guiSetVisible(vehTab2.buyMemo, true) 
                    end 
                end 
            )            
            showCursor(false) 
            guiSetVisible(vehicleWindow, false) 
             
            unbindKey("f1", "down") 
            unbindKey("f2", "down") 
            bindKey("f1", "down", showUi) 
            bindKey("f2", "down", hideUi)            
        end 
    end 
) 
  

Alexander

Edit:

The line in meta.xml

Link to comment

Hello,

Thanks, but still doesn't work.

I've got the updated xml file:

     \n\n    In this tab 'order' you can order the next things:     \n\n        1. Vehicle's        2. Vehicle upgrade        3. Sell your vehicle's    \n\n    The max vehicle's to buy are 5!    \n\n    Nice driving,    \n\n    LexLife team." />     Hello,    \n\n    In this tab you can buy a vehicle, but we are busy at the system so for now, you cant.    \n\n    Nice driving,    \n\n    LexLife team." /> 

And the updated code:

 addEventHandler( "onClientResourceStart", g_this_root,     function( theResource )        if theResource == getThisResource() then             local x, y = guiGetScreenSize()             vehicleWindow = guiCreateWindow(x / 2 - 310, y / 2 - 260, 620, 520, "LexLife - VehicleMenu", false)                        vehtabPanel = guiCreateTabPanel(0.01, 0.05, 0.98, 0.95, true, vehicleWindow)                        vehTab = {}            vehTab.Tab = guiCreateTab("Vehicle info", vehtabPanel)            vehTab.Messages = guiCreateLabel ( 0.68, 0.05, 0.45, 0.04, "Health: 1000%", true, vehTab.Tab )            vehTab.ownVehiclesSearch = guiCreateEdit ( 0.03, 0.05, 0.16, 0.04, "", true, vehTab.Tab )                        vehTab2 = {}            vehTab2.Tab = guiCreateTab("Order", vehtabPanel)            vehTab2.Messages = guiCreateLabel(0.01, 0.0, 0.55, 0.03, "Here you can buy/sell/upgrade vehicles", true, vehTab2.Tab)            vehTab2.buyCarbtn = guiCreateButton(0.01, 0.05, 0.25, 0.04, "Buy an car", true, vehTab2.Tab)            vehTab2.sellCarbtn = guiCreateButton(0.01, 0.12, 0.25, 0.04, "Sell your vehicle", true, vehTab2.Tab)            vehTab2.upgCarbtn = guiCreateButton(0.01, 0.18, 0.25, 0.04, "Upgrade your vehicle", true, vehTab2.Tab)                        Node = xmlLoadFile("client\\text\\vehicle_order_text.xml")            nodetext = xmlNodeGetValue(Node)                        MemoText = xmlNodeGetAttribute(nodetext, "wlcTxt")            buyMemoText = xmlNodeGetAttribute(nodetext, "buyTxt")                        xmlUnloadFile(Node)                        vehTab2.Memo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, MemoText, true, vehTab2.Tab)            vehTab2.buyMemo = guiCreateMemo(0.27, 0.05, 0.70, 0.80, buyMemoText, true, vehTab2.Tab)                                    guiSetVisible(vehTab2.buyMemo, false)                        addEventHandler( "onClientGUIClick", vehTab2.buyCarbtn,                 function()                    if source == vehTab2.buyCarbtn then                        guiSetVisible(vehTab2.Memo, false)                        guiSetVisible(vehTab2.buyMemo, true)                    end                end            )                       showCursor(false)            guiSetVisible(vehicleWindow, false)                        unbindKey("f1", "down")            unbindKey("f2", "down")            bindKey("f1", "down", showUi)            bindKey("f2", "down", hideUi)                   end    end) 

Alexander

Edit:

The line in meta.xml

Link to comment
node = xmlLoadFile("client/text/vehicle_order_text.xml") 
            
MemoText = xmlNodeGetAttribute(node, "wlcTxt") 
buyMemoText = xmlNodeGetAttribute(node, "buyTxt") 
            
xmlUnloadFile(node) 

Link to comment

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