Need Help in Making VB.Net code which will read from XML file

Sarthak Gautam 21 Reputation points
2021-06-04T17:31:45.483+00:00

I was creating a script for Grand Theft Auto IV which read dispatch.xml in the same way as Grand Theft Auto V reads and spawn stuff. Here's the code :

<?xml version="1.0" encoding="UTF-8"?>

<CDispatchData>
    <LawSpawnDelayMin>
        <SLOW value="20.0"/>
        <MEDIUM value="10.0"/>
        <FAST value="10.0"/>
    </LawSpawnDelayMin>
    <LawSpawnDelayMax>
        <SLOW value="30.0"/>
        <MEDIUM value="20.0"/>
        <FAST value="20.0"/>
    </LawSpawnDelayMax>
    <DispatchOrderDistances>
        <Item>
            <DispatchType>DT_PoliceAutomobile</DispatchType>
            <OnFootOrderDistance value="200.0"/>
            <MinInVehicleOrderDistance value="350.0"/>
            <MaxInVehicleOrderDistance value="350.0"/>
        </Item>
        <Item>
            <DispatchType>DT_PoliceHelicopter</DispatchType>
            <OnFootOrderDistance value="200.0"/>
            <MinInVehicleOrderDistance value="350.0"/>
            <MaxInVehicleOrderDistance value="350.0"/>
        </Item>
        <Item>
            <DispatchType>DT_SwatHelicopter</DispatchType>
            <OnFootOrderDistance value="200.0"/>
            <MinInVehicleOrderDistance value="350.0"/>
            <MaxInVehicleOrderDistance value="350.0"/>
        </Item>
        <Item>
            <DispatchType>DT_SwatAutomobile</DispatchType>
            <OnFootOrderDistance value="200.0"/>
            <MinInVehicleOrderDistance value="350.0"/>
            <MaxInVehicleOrderDistance value="350.0"/>
        </Item>
        <Item>
            <DispatchType>DT_PoliceRoadBlock</DispatchType>
            <OnFootOrderDistance value="350.0"/>
            <MinInVehicleOrderDistance value="350.0"/>
            <MaxInVehicleOrderDistance value="350.0"/>
        </Item>
        <Item>
            <DispatchType>DT_PoliceBoat</DispatchType>
            <OnFootOrderDistance value="200.0"/>
            <MinInVehicleOrderDistance value="350.0"/>
            <MaxInVehicleOrderDistance value="350.0"/>
        </Item>
    </DispatchOrderDistances>
    <VehicleSets>
        <Vehicle>
            <Name>ARMY</Name>
            <ConditionalVehicleSets>
                <Item>
                    <VehicleModels>
                        <Vehicle>mesa3</Vehicle>
                    </VehicleModels>
                    <PedModels>
                        <Ped>S_M_Y_BlackOps_01</Ped>
                    </PedModels>
                </Item>
            </ConditionalVehicleSets>
        </Vehicle>
    </VehicleSets>
    <WantedResponses>
        <WantedLevel5>
            <DispatchServices>
                <Item>
                    <DispatchType>DT_PoliceAutomobile</DispatchType>
                    <NumPedsToSpawn value="6"/>
                    <DispatchVehicleSets>
                        <Dispatch>MILITARY</Dispatch>
                        <Dispatch>FBI_CAR</Dispatch>
                        <Dispatch>SWAT_RIOT</Dispatch>
                    </DispatchVehicleSets>
                </Item>
                <Item>
                    <DispatchType>DT_PoliceRoadBlock</DispatchType>
                    <NumPedsToSpawn value="4"/>
                    <DispatchVehicleSets>
                        <Dispatch>POLICE_ROAD_BLOCK_MILITARY</Dispatch>
                        <Dispatch>POLICE_ROAD_BLOCK_RIOT</Dispatch>
                        <Dispatch>POLICE_ROAD_BLOCK_FBI</Dispatch>
                        <Dispatch>POLICE_ROAD_BLOCK_RHINO</Dispatch>
                    </DispatchVehicleSets>
                </Item>
                <Item>
                    <DispatchType>DT_PoliceBoat</DispatchType>
                    <NumPedsToSpawn value="9"/>
                    <DispatchVehicleSets>
                        <Dispatch>MILITARY_BOAT</Dispatch>
                        <Dispatch>SWAT_BOAT</Dispatch>
                    </DispatchVehicleSets>
                </Item>
            </DispatchServices>
        </WantedLevel5>
    </WantedResponses>
</CDispatchData>

I want to read all the values, if they are changed by user then it should read the modified one. Some codes are picked-up as random -

<ZoneType>VEHICLE_RESPONSE_COUNTRYSIDE</ZoneType>
<VehicleModels>
<Vehicle>SHERIFF</Vehicle>
<Vehicle>sheriff2</Vehicle>
</VehicleModels>
<PedModels>
<Ped>S_M_Y_Sheriff_01</Ped>
<Ped>S_F_Y_Sheriff_01</Ped>
</PedModels>
where

                    <Vehicle>SHERIFF</Vehicle>
                    <Vehicle>sheriff2</Vehicle> 

are picked up as random and same for

                    <Ped>S_M_Y_Sheriff_01</Ped> 
                    <Ped>S_F_Y_Sheriff_01</Ped>

is it possible to do?

I was successful in making .ini file configuration but it seems that XML is bit harder.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,820 questions
{count} votes

1 additional answer

Sort by: Most helpful
  1. Dewayne Basnett 1,371 Reputation points
    2021-06-07T14:16:31.907+00:00

    Start by reading LINQ to XML from Microsoft.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.