Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
      7. The Diamond Casino Heist
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

MrGTAmodsgerman

[C#.NET] How to read INI file section in dynamic blocks?

Recommended Posts

MrGTAmodsgerman

Hey guys,

 

Lets say, i have a INI File like the following example:


VEHICLE_MODEL = btype2
[SLOT1]
SLOT_POSX: 73588539803
SLOT_POSY: -785656685
SLOT_POSZ: 73588539803
[SLOT2]
SLOT_POSX: 73588539803
SLOT_POSY: -785656685
SLOT_POSZ: 73588539803
SLOT_COUNT = 2 <both slots getting used by the script>
NeedXY = true
godmode = false
invisible = false


VEHICLE_MODEL = infernus
[SLOT1]
SLOT_POSX: 53588539803
SLOT_POSY: -585656685
SLOT_POSZ: -5588539803
[SLOT2]
SLOT_POSX: 7878539803
SLOT_POSY: -785656685 >Not getting used because of SLOT Count 1<
SLOT_POSZ: 73588539803
SLOT_COUNT = 1
NeedXY = false
godmode = false
invisible = false

Ok? Got it?

 

Now, lets say that the SLOT POS XYZ are coordinates that get set by the ini file and loaded by the script. So the car get teleported to the coordinates (not like a vehicle save script)

 

But now lets say, i want that the user just simply can add his own section to the INI file and the scripts reads it and use the new entry for the new defined vehicle.

 

For example

VEHICLE_MODEL = btype2
[SLOT1]
SLOT_POSX: 73588539803
SLOT_POSY: -785656685
SLOT_POSZ: 73588539803
[SLOT2]
SLOT_POSX: 73588539803
SLOT_POSY: -785656685
SLOT_POSZ: 73588539803
SLOT_COUNT = 2 <both slots getting used by the script>
NeedXY = true
godmode = false
invisible = false


VEHICLE_MODEL = infernus
[SLOT1]
SLOT_POSX: 53588539803
SLOT_POSY: -585656685
SLOT_POSZ: -5588539803
[SLOT2]
SLOT_POSX: 7878539803
SLOT_POSY: -785656685 >Not getting used because of SLOT Count 1<
SLOT_POSZ: 73588539803
SLOT_COUNT = 1
NeedXY = false
godmode = false
invisible = false
                                                                           
VEHICLE_MODEL = mercedesw123
[SLOT1]
SLOT_POSX: 53588539803
SLOT_POSY: -585656685
SLOT_POSZ: -5588539803
[SLOT2]
SLOT_POSX: 7878539803
SLOT_POSY: -785656685
SLOT_POSZ: 73588539803
SLOT_COUNT = 2
NeedXY = false
godmode = false
invisible = false

 

 

But here is my problem. All these values are the same. So how can i read them automaticly as single blocks and use the new defined entrys without define them in my script?

I know its possible, because someone else did this https://www.gta5-mods.com/scripts/dlc-vehicles-spawn-on-traffic

or just like in Menyoo.

 

thanks

 

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
Jitnaught

Use an XML file instead, then you can do something like:

<vehicle>
<model>btype2</model>
<pos>XYZ</pos>
<godmode>true</godmode>
<invisible>false</invisible>
</vehicle>

<vehicle>
<model>infernus</model>
<pos>XYZ</pos>
<godmode>true</godmode>
<invisible>false</invisible>
</vehicle>

 

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
13 minutes ago, Jitnaught said:

Use an XML file instead, then you can do something like:

<vehicle>
<model>btype2</model>
<pos>XYZ</pos>
<godmode>true</godmode>
<invisible>false</invisible>
</vehicle>

<vehicle>
<model>infernus</model>
<pos>XYZ</pos>
<godmode>true</godmode>
<invisible>false</invisible>
</vehicle>

 

Ok, but how to do that in codewise? Any tutorial for XML files? Sorry i am not very skilled in this. What makes it automaticly read new entrys that are not defined?

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
Jitnaught

Look up "c# xmldocument"

https://stackoverflow.com/a/55840

 

There are multiple ways to parse XML files in C# though. Look up "c# parse XML" to find all of your options.

Share this post


Link to post
Share on other sites
Guest

@MrGTAmodsgermanTry this small project https://drive.google.com/file/d/1tralYo36VwXuW23l9-jBjTIQTrPV8H91/view?usp=sharing

 

It creates this as an output:

<?xml version="1.0" encoding="utf-8"?>
<Vehicles>
  <VehicleDefinitions>
    <VehicleDefinition>
      <Model>infernus</Model>
      <Position>
        <X>0</X>
        <Y>0</Y>
        <Z>0</Z>
      </Position>
      <GodMode>true</GodMode>
      <Invisible>false</Invisible>
    </VehicleDefinition>
    <VehicleDefinition>
      <Model>zion</Model>
      <Position>
        <X>0</X>
        <Y>0</Y>
        <Z>0</Z>
      </Position>
      <GodMode>true</GodMode>
      <Invisible>false</Invisible>
    </VehicleDefinition>
    <VehicleDefinition>
      <Model>comet</Model>
      <Position>
        <X>0</X>
        <Y>0</Y>
        <Z>0</Z>
      </Position>
      <GodMode>true</GodMode>
      <Invisible>false</Invisible>
    </VehicleDefinition>
    <VehicleDefinition>
      <Model>bodhi2</Model>
      <Position>
        <X>0</X>
        <Y>0</Y>
        <Z>0</Z>
      </Position>
      <GodMode>true</GodMode>
      <Invisible>false</Invisible>
    </VehicleDefinition>
  </VehicleDefinitions>
</Vehicles>

I use something similar to this for saving my Players Extended config data and the data for my Driver Info System mod.

 

You just have to be aware that there are some data types that won't serialise, like Color but the majority of things work okay. For Color, I just created a VColor that I convert to and from and that works fine.

 

The main rule for serialising objects, is that the class must have a parameterless constructor. So in the case of the class used in this for the VehicleDefinition, it looks like this:

 

    public class VehicleDefinition
    {
        public string Model;
        public Vector3 Position;
        public bool GodMode;
        public bool Invisible;

        public VehicleDefinition() { }

    }

Also, it will only serialise Public properties. You might want to read up on the XmlAttributes class for more info on controlling the serialisation process.

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
10 hours ago, LeeC2202 said:

Thx for the file. Now i understand that XML stuff a little bit more 😀

 

LqhE8RW.png

This part is the reason why i really created this topic. Because you working with predefined vehicles. But how can it be done without the exact definition. How can i read them as dynamic section?

In my example above, i just go ahead as "user" and add a block of lines with a definition for a mercedesw123, right? But here is the problem. The user can't change my script. So the script should automaticly read the new block with all his values.

So i need to work with something that doesn't exist. I am not quite sure if you understand my whole topic for the problem i have.

Well for example, Menyoo have a objectlist. There are some objectlist files you can download which add new entrys to the file which Menyoo doesn't have in when you download it.

But Menyoo knows that the second line of the object list, is a for example "modelname" and the next one is a bool.

 

Quote

You might want to read up on the XmlAttributes class for more info on controlling the serialisation process.

So is that what you meaning with my problem? Would that help me for that case?

I am sorry, i never builded a script which completely lives from a XML file that  only gets loaded by the script, instead of writing it.

 

My last idea would be to make a second function which writes the XML file by pressing a key. But that is not what i want. Because i saw that its possible without that.

 

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
Guest
3 hours ago, MrGTAmodsgerman said:

This part is the reason why i really created this topic. Because you working with predefined vehicles

No, it isn't working with predefined vehicles, I just made it load the same file back in as a demonstration. It loads whatever it finds... if it finds nothing, it loads nothing. If the file contains 1, 5, 10 or 50 definitions, it will load them all.

 

If you use that script to output the Test.XML class, manually edit it to add a new section and press the key to load the file. You will see the name of the new section appear on screen, along with the rest.

 

Basically, it will deserialise all objects contained in that XML file, no matter how they were added. So if you added this...

    <VehicleDefinition>
      <Model>dominator</Model>
      <Position>
        <X>0</X>
        <Y>0</Y>
        <Z>0</Z>
      </Position>
      <GodMode>false</GodMode>
      <Invisible>true</Invisible>
    </VehicleDefinition>

...as a new VehicleDefinition at the bottom, then the script would have 5 vehicles in the newVehicles collection. So the file could start off like this:

<?xml version="1.0" encoding="utf-8"?>
<Vehicles>
  <VehicleDefinitions>
  </VehicleDefinitions>
</Vehicles>

And that would create an empty collection, until something was added to it. It's exactly the same as adding a new <Item></Item> to handling.meta when you edit the game files, whatever it finds, as long as it is correct, it will add it to the collection.

 

3 hours ago, MrGTAmodsgerman said:

But Menyoo knows that the second line of the object list, is a for example "modelname" and the next one is a bool. 

No, it doesn't know that and it doesn't care about that. The object list is probably created from a serialised set of objects. So it knows the value is there, simply because the class (or Struct) it was created from had one

 

If you want to see how that works, in the bit where it loads the file back in, change the UI.Notify line to this:

UI.Notify(vd.Model + " / " + vd.GodMode + " / " + vd.Invisible);

Then change the order of the GodMode and Invisible lines in one of the vehicle definitions. Even though you have some that say:

      <GodMode>true</GodMode>
      <Invisible>false</Invisible>

and one that says:

      <Invisible>false</Invisible>
      <GodMode>true</GodMode>

It will still assign the correct values to the relevant properties.

Edited by Guest

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
42 minutes ago, LeeC2202 said:

No, it isn't working with predefined vehicles, I just made it load the same file back in as a demonstration. It loads whatever it finds... if it finds nothing, it loads nothing. If the file contains 1, 5, 10 or 50 definitions, it will load them all.

 

If you use that script to output the Test.XML class, manually edit it to add a new section and press the key to load the file. You will see the name of the new section appear on screen, along with the rest.

 

Basically, it will deserialise all objects contained in that XML file, no matter how they were added. So if you added this...

 

It will still assign the correct values to the relevant properties.

Okey. Well, for my english, i need to play around with this first, to make sure that i understand what you wrote. Thanks.

Share this post


Link to post
Share on other sites
MrGTAmodsgerman

@LeeC2202 Well, basically i understand now how it works. But my way to filter the vehicle models from the xml in the nearby vehicles, doesn't work.

 

            Ped Spieler = Game.Player.Character;
            {
                if (MarkerGameTimeRef < Game.GameTime)
                {
                    MarkerGameTimeRef = Game.GameTime + 10;
                    if (Spieler.IsInVehicle())
                    {
                        foreach (Vehicle nearbyVehicle in World.GetNearbyVehicles(Spieler, 40f))
                        {
                            Vehicles newVehicles = XMLExtensions.XMLDeserialise<Vehicles>(SettingsFilePrefix + "test.xml");

                            foreach (VehicleDefinition vd in newVehicles.VehicleDefinitions)
                            {

                                String Automodel = vd.Model.Trim().ToString();
                                if (nearbyVehicle.Model.ToString() == Automodel)
                                {
                                    UI.Notify(Automodel);

                                    UI.Notify(vd.Model);
                                    nearbyVehicle.AddBlip();
                                    nearbyVehicle.CurrentBlip.IsFlashing = true;
                                }
                            }

Its on Tick.

It doesn't always really work. The game uses a other if statement after that (ignore the part), or all vehicles get blips around me and the minimap starts to get bigger than usual and flickers.

What i did i forgot? Or why can't this script compare the vehiclenames around me with the vehicles from the XML?

 

All i want to do is just doing task with vehicles around me that are only mentioned in the XML file. Thats all.

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
37 minutes ago, LeeC2202 said:

Don't deserialise XML in your onTick, that's going to be bad. Deserialising is like reading an ini file, you do it once.

But what else then? I don't want to use onKey events. And anything else like creating a void, require it to mention the void in a OnTick event or onKeyup/Down. Or did i get something wrong?

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
2 hours ago, LeeC2202 said:
if (Spieler.IsInVehicle())
{
	CollectVehicles();
}
void CollectVehicles()
{
	Vehicle[] nearbyVehicle = World.GetNearbyVehicles(Spieler, 40f));
	
	foreach (Vehicle veh in nearbyVehicles)
	{
		// If the list contains this model string, then it's a matching vehicle
		if (VehicleModels.Contains(veh.Model.ToString()))
		{
			if (!CollectedVehicles.ContainsKey(veh.Handle))
			{
				// This is a unique vehicle, so we store it as collected and do whatever else you need to do
				CollectedVehicles.Add(veh.Handle, veh);
				// Do some Blip stuff here etc...
			}
			else
			{
				// Vehicle is already collected, so we don't need to do anything with it... unless you want to do something.
			}
		}
	}
}

 

 

Do i forget something?

Because i tried to play around now with this, fixed some little errors you made and the game do nothing 🤔

        private void onTick(object sender, EventArgs e)
        {
            // Exits from the loop if the game is loading
            if (Game.IsLoading) return;
            //Bikefahren();
            if (Game.Player.Character.IsInVehicle())
            {
                CollectVehicles();
                Wait(30000);
                CheckIfVehiclesStillExist();
                UI.Notify("onTick Event Ende");
            }

        }

Well, you may do a facepalm now, so i am sorry. I have no idea to put "foreach" combined with "wait" into one. I am a damn noob.

But anyways, the UI gets displayed as you can see here, and the game laggs for a second when i reload the script. But thats all.

 

But what about the Initialise function? As far as i know, no void is running when it isn't in any onTick or KeyDown/Up event. So thats my idea why nothing happends.

But should i also mention it in OnTick?

        public cXMLTest()
        {
            Tick += onTick;
            KeyUp += onKeyUp;

            Interval = 100;
        }


        // Call once when the mod runs
        void Initialise()
        {
            MyVehicles = XMLExtensions.XMLDeserialise<Vehicles>("scripts\\test.xml");

            foreach (VehicleDefinition vd in MyVehicles.VehicleDefinitions)
            {
                VehicleModelHashes.Add(Game.GenerateHash(vd.Model.Trim()));
            }
        }

EDIT: Well, i put Initialise now into on Tick with a UI notify message. It only runs in onTick. But it doesn't make the script to work

 

 

        void CollectVehicles()
        {

            Vehicle[] nearbyVehicle = World.GetNearbyVehicles(Spieler, 40f);

            foreach (Vehicle veh in nearbyVehicle)
            {
                // If the list contains this model hash, then it's a matching vehicle
                if (VehicleModelHashes.Contains(veh.Model.Hash))
                {
                    if (!CollectedVehicles.ContainsKey(veh.Handle))
                    {
                        // This is a unique vehicle, so we store it as collected and do whatever else you need to do
                        CollectedVehicles.Add(veh.Handle, veh);
                        // Do some Blip stuff here etc...
                        veh.AddBlip();
                        veh.CurrentBlip.IsFlashing = true;
                        UI.Notify(veh.Model.ToString());
                    }
                    else
                    {
                        // Vehicle is already collected, so we don't need to do anything with it... unless you want to do something.
                    }
                }
            }
        }

Is veh as collected vehicle the right one?

 

EDIT: Btw. I want to load the XML file when the mod is loaded, without pressing anything on the keyboard.

 

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
7 minutes ago, LeeC2202 said:

If something says "Run once" the last thing you should be doing, is putting it into something that runs every frame.

 

That's what a constructor is for, or if you don't like using the constructor for any reason, then just wrap a piece of code in a bool.

// Global variable
bool RunOnce = false;


// in OnTick
if (!RunOnce)
{
	// Do things here that only happen once...
	
	// ... then set this flag to stop it running again
	RunOnce = true;
}

 

Sorry i thought you was meaning that its possible to run everything without mention all voids in the onTick event.

So you mention only CollectVehicles void in the OnTick Event. Hmm i will watch some more tutorials for that. Hope that helps.

But like i said. Running all voids in the onTick event, doesn't do anything better except the UI notification i wrote into each void, getting displayed :/

Having only collectvehicles onTick doesn't make the script to work. What did i wrong then?

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
3 hours ago, LeeC2202 said:

 

*sigh* Maybe my vehicle checking code isn't fully working, it's not deleting the blips. :(

 

I don't think I can do anything more tonight, I think my head is screwed from stressing over finite state machines in a mod I am writing. It's been almost 15 years since I used them and I can't remember fully how they work.

 

Edit: God I am so stupid sometimes, add this line at Line 143, before the line that says CarBlips.Remove(key);

if (CarBlips[key].Exists()) CarBlips[key].Remove();

I wasn't actually removing the Blip, just the entry in the Dictionary... time for bed I think. :(

Well that is what i was about to tell. Never mind, you helped me alot already. I just also tried to draw a marker on the catched vehicle, but i only can see the marker 1 milli second when i reload the scripts.

Another day, another try ;) good night

 

EDIT: There is some real big other question i have. Is it possible to access defined functions from one void to another void? I mean. I want to access for ex. "blipKeys" list in the CollectedVehicles void for example. But i always need to define it as parameter above. Thats what Visual Studio says. But thats not working when i try to access "Spieler = Game.Player.Character" or something like that in one void where "Spieler" is defined in a another one.

 

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
6 hours ago, LeeC2202 said:

It sounds like you need to go over some programming basics before you go much further. I have just tried to find a video to explain it and this was about the best of a very bad bunch.

thx. Will it also help me to create the marker without disappearing?

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
24 minutes ago, LeeC2202 said:

Markers have to be drawn every frame to stay visible.

Ok thanks for the video. so

    public class cXMLTest : Script
    {
        // Global variables
        List<int> VehicleModelHashes = new List<int>();
        Dictionary<int, Vehicle> CollectedVehicles = new Dictionary<int, Vehicle>();
        Vehicles MyVehicles;
        public Ped Spieler = Game.Player.Character;
        Dictionary<int, Blip> CarBlips = new Dictionary<int, Blip>();

doing it like that is the right way, right? I mean "Spieler"

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
12 minutes ago, LeeC2202 said:

Yep, that's right. It doesn't need to be public but in this case, it's probably not going to cause you any problems being like that.

 

That being said, I would put "accessibility" on your list to find out about as well. That will teach you about private, public, internal... that kind of thing. That kind of thing does become important when you start using multiple classes in a mod.

Ok, so what is the right way now to remove the blip? Define your checkvehiclesexist function carblip remove for public use? Because veh.currentBlip.remove doesn't still work, because you set the blip to his current position. So not attached to the vehicle. Which isn't bad because cost less memory. But then, i need to use CarBlips.Remove which also doesn't do anything, because its the List. And when i try to set it flashing to the blip, then i need to use veh.currentBlip.isflashing, true. So what is the right way to get access?

I already include the missing line for blips, which fixes the blip removement in the void of checkvehiclesexist.

 

Edit: Well thats how i like it. The link u send explains everything short :D

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
1 minute ago, LeeC2202 said:

Once you attach a blip to an entity, you can't remove it unless the entity is removed, you have to set the Alpha level to zero to hide it. That's why I create blips at the position instead. If I wanted it to follow the vehicle, I would update the Blip.Position in an onTick function. I think in the game, Blips are designed to be attached and left alone and they will get removed once something has happened to the entity they are attached to. But modding let's us use them differently and that's when we run into problems like this.

 

Inside a class, nothing has to be public for the rest of the class to have access to it. Public (or internal) is only used when another class needs access to that property from outside.

So i don't want to attach it. But do i need to attach it first to let it flashing for example? And then dettach it? I only want to remove it, thats all

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
1 minute ago, LeeC2202 said:

I have never used flashing blips, so I honestly don't know about that... I would think any blip can flash though.

 

You can't detach a blip, that's the problem. If you notice, there is an Entity.AddBlip but not an Entity.RemoveBlip, once it's attached, I think it's attached for the life of the entity.

So what option do i have now? Forget about the flashing and attach stuff. I want to remove it

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
5 minutes ago, LeeC2202 said:

Well you already know how to remove a blip that isn't attached to anything, you already have the code for that.

But like i said. It doesn't work.

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
18 minutes ago, LeeC2202 said:

This code works perfectly:

if (!CollectedVehicles[key].Exists() || CollectedVehicles[key].IsDead)
{
    CollectedVehicles.Remove(key);
    if (CarBlips[key].Exists()) CarBlips[key].Remove();
    CarBlips.Remove(key);
    UI.Notify("Removing car because it's dead or doesn't exist");
}

That's the code in that project, with the fixed line I posted last night. If that isn't working in your project, then you've changed something, because it still works fine for me... watch the minimap and the messages. You will see the BF Injection blip disappear when the message is shown and when I open the pause map, there are no blips on it at all.

Ohh, wait. The whole checkvehicleexist function is for removing the blip? So when i set, if Playerisonfoot

checkVehicleExist(); including a remove function for on foot in checkVehicleExist?

 

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
6 minutes ago, LeeC2202 said:

CheckVehiclesExist() should be run all the time, because cars can stop existing while you are doing anything.

hmmm, well i can put if Spieler.isOnFoot everywhere and remove the Blips then. But that doesn'T work.

Is on foot really outside of vehicles?

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
56 minutes ago, LeeC2202 said:

Why are you putting IsOnFoot anywhere, when the collecting vehicles is the only thing done inside a vehicle? That project I sent doesn't have any OnFoot checks, because you specifically had this in the code you showed.

if (Spieler.IsSittingInVehicle())
{
}

Everything outside that will be presumed to be on foot.

Because i am not able to remove the CarBlips on the onTick event, because he is asking for key which doesn't exist in that context. The video u sent wasn'T for for each statements. And my whole script is now different filtered instead of isSittinginVehicle. I created a global variable for key, which doesn't help.

My plan is to filter the current vehicle type by bool statements from the XML File to make different actions. So i will use more filters in the CollectedVehicles function first. Lateron i will split it into ordered voids.

        private void onTick(object sender, EventArgs e)
        {
            // Exits from the loop if the game is loading
            if (Game.IsLoading) return;

            if (Spieler.IsOnBoat)
            {
                CollectVehicles();
                CheckVehiclesExist();
            }
            else
            {
                CarBlips.Remove(key);
            }

 

EDIT: You showed me 2 links that explains using private, public methods. But my problem is again, i wanna use single decerations in new voids.

 

        void Benachrichtigungsfunktion()
        {
            UI.Notify("The " + veh.DisplayName + " supports a Bicycle rack");
        }

Using veh as global variable would need to declare the whole thing what veh is, outside of the collectedVehicles(); function 🙄

isn't there any other way? When a void put out something like this, i wanna use it in other voids. I tried to make the whole collectedVehicles(); method as public one. But as the guy in the video you post said: I can't access the single things inside from outside, because its like a box that needs to keep it secret.

So how would you do it? I don't really get the logic of that box system much.

Edited by MrGTAmodsgerman

Share this post


Link to post
Share on other sites
MrGTAmodsgerman
3 minutes ago, LeeC2202 said:

I don't understand and I don't even know what to say... you seem to be adding layer upon layer of complexity and I don't really understand what the end-goal is.

 

You can't have a global key value if it's being created in a loop, because it will always be the last value that the loop gave it. So you'll almost be removing a random blip, that just happens to be the last one in the list.

 

My advice... is plan everything now and don't write any more code until you have a clear plan. If you try to add things as you go along, you're going to get a neverending stream of mod-breaking errors. You need to work out what all the filtered sections are going to be and you need to work out which sections share the same actions. The more logical and ordered you make things now, the easier it will be to deal with, when things go wrong.

 

I don't know what else to say other than that, but don't get tempted to just turn everything into global variables, because just having access to a variable, doesn't mean you're using it at the right time.

I have a plan, but i am trying to figure your code out. For my knowledge of coding, i should able to say, remove.Blip and it should do it, when i need it :/

I have no idea how you would remove the blip when the player is not in any vehicle situation. Because you said, its anyting else in action when its not isinVehicle. But how the hell can i work with the single catched vehicle, if the methods only allow me to do things with the collected vehicle inside one void. You said, i should order everything, thats what i am trying. So i don't have that kind of experience of scripting that you have, to know that a loop can't be a global key value.

I think i am gonna tell you my whole idea in private message to tell you what i am trying to do, because this is going to be a big off topic thread here 😴

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.