Jump to content

LtFlash

Members
  • Posts

    610
  • Joined

  • Last visited

 Content Type 

Forums

Gallery

Downloads

Tutorials

News Stories

Wiki

Community Guidelines

LSPDFR BOLO Series

GTA5 Native Database

GTA5 Native Parameters

Release Highlights

LSPDFR Mod Showcase

LML User Contributions

Posts posted by LtFlash

  1. Pawel,
    one of the most troublesome and important aspect of scripting for GTA/LCPD:FR is to create chunks of code that will work in sequence. There were many techniques: switch...case + enum, bool flags, while loops but I managed to create probably the best solution which is to use a list of functions that might be switched on and off. Here are some resources:
    https://github.com/LtFlash/LtFlash.Common/blob/master/LtFlash.Common/Processes/ProcessHost.cs

    https://github.com/LtFlash/LtFlash.Common/blob/master/Examples/Processes/ProcessHost.cs

    In your code it could be used like this:

     

    public override void OnCalloutBegin()
    {
      proc.ActivateProcess(IsPlayerClose);
    }
    
    public override void Process() 
    {
      proc.Process()
    }
    
    public void IsPlayerClose()
    {
      if(DistanceToPlayer < 200f)
      {
        //createblips
        proc.SwapStages(IsPlayerClose, HasPlayerClearTheArea);
        proc.ActivateStage(DisplayPlayerTaskOnScreen);
      }
    }
    
    private void DisplayPlayerTaskOnScreen()
    {
      //print msg "Eliminate enemies
    }
    
    private void HasPlayerClearTheArea()
    {
      if(AreEnemiesDead())
      {
        //print msg
        End();
      }
    }
    
    private bool AreEnemiesDead()
    {
      return (!Enemy1.Valid() || Enemy1.IsDead) && (!Enemy2.Valid() || Enemy2.IsDead);
    }

     

    Here's some information on Action delegate behind that technique:

    https://www.dotnetperls.com/action

    Using that, I believe you can solve your problem quickly.

  2. It is possible and not complicated at all if you familiarize yourself with files hierarchy.  Try to analyze StagesData.xml of any case and follow IDs of entites to their config files, eg. SuspectsData.xml, VictimsData.xml, DialogsData.xml and so on. Every piece of information that form a case is located in those files. 20-30 minutes of learning and I'm sure you'll be an expert in creating cases. We are checking the forum regularly so feel free to ask questions. You might also contact us via our Discord server.

    We'll probably push an update with some cosmetic changes to file formats, so have in mind you'll have to adapt your new case when this happens.

    Fiskey is working on dedicated tools for creating cases but the release date is unknown due to how busy we are in real life.

  3. The current version has huge unused potential but the coding scene is pretty much dead. I'm still working on The Wasteland and it's refreshed version will be eventually released but that would be it in terms of active development for LCPD:FR. Despite of the available know-how we didn't have back in the days, no one seems to be interested in creating scripting mods nowadays. I just realized IV was released TEN years and nine days ago...

  4. You can start a new fiber with an infinite loop in the entry method like that:

    void Main()
    {
      var fiber = GameFiber.StartNew(Process);
    }
    
    void Process()
    {
      while(true)
      {
        //your code
        GameFiber.Yield();
      }
    }

    That's only a general idea ofc. You can do whatever you want: a custom callout subsystem, world events, GUI. There are no limitations.

  5. Okay, let's try to not to over-complicate it.

    1) Extension methods:

    create a separate static class and put your extension methods inside:

    public static class MyExtensions
    {
      public static bool Valid(this LPed ped)
      {
        return ped != null && ped.Exists();
      }
    }

    then you can use Valid() on all LPeds like this:

    LPed myPed = new LPed(...);
    
    if(myPed.Valid())
    {
    	//do something
    }

    2) You need to understand classes to break your plugin into more comprehensible parts. For now I'd say keep it as it is and get some theory on classes.

    3) You are not checking if the result of GetClosestVehicle() is a valid entity. It should be like this:

    private bool GetEnforcerArmoryState()
    {
      Vehicle v = World.GetClosestVehicle(lcpdfrPlayer.Ped.Position, 3f);
      if(v != null && v.Exists())
      {
      	LVehicle closestVehicle = LVehicle.FromGTAVehicle(v);
      	return closestVehicle != null && closestVehicle.Exists() && closestVehicle.Model.ModelInfo.Hash == Enforcer;
      }
      else return false;
    }

     

  6. You use an existence check with an improper condition: "entity != null || entity.Exists()" means that it is enough for an entity to be not null. It should look like this: "entity != null && entity.Exists()". I recommend to add to your project an extension methods for all entities so you can make your life easier.

    public static bool Valid(this LPed ped)
    {
    	return ped != null && ped.Exists();
    }
    
    public static bool Valid(this LVehicle veh)
    {
    	return veh != null && veh.Exists();
    }
    
    public static bool Valid(this GTA.@base.Object obj)
    {
    	return obj != null && obj.Exists();
    }

    If you are not aware of what extension methods are and how to implement them, google will help you.

     

    One more thing, you should consider breaking your class into smaller (eg. you could create a dedicated class for a squad). 2k lines is too much to comprehend.

×
×
  • Create New...