Jump to content

My API Questions


Matties

Recommended Posts

Spoiler

using System;
using Rage;
using Rage.Native;
using LSPD_First_Response;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Engine.Scripting.Entities;

//Our namespace (aka folder) where we keep our callout classes
namespace Callouts.Callouts
{
    //Give your callout a string name and a probability of spawning. We also inherit from the Callout class, as this is a callout
    [CalloutInfo("ExampleCallout", CalloutProbability.VeryHigh)]
    public class Robbery : LSPD_First_Response.Mod.Callouts.Callout
    {
        //Here we declare our variables, things we need or our callout
        private Ped Robber; //Our robber ped
        private Ped Storekeeper; //Our storekeeper
        private EMuggingState state; //our mugging state
        private LHandle Pursuit; //Pursuit API
        private Vector3 Store; //Location of the store
        private Blip Location; //Location of the robber
        private Weapon gun1; //our weapon
        private Robbery robberyApi; //Robbery API

        /// <summary>
        /// OnBeforeCalloutDisplayed is where we create a blip for the user to see where the pursuit is happening, we initiliaize any variables above and set
        /// the callout message and position for the API to display
        /// </summary>
        /// <returns></returns>
        public override bool OnBeforeCalloutDisplayed()
        {
            //Our Spawnpoint
            Store = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(300f));
            Robber = new Ped(Store);

            //Spawn the storekeeper in front of the robber
            Storekeeper = new Ped(Robber.GetOffsetPosition(new Vector3(0, 1.8f, 0)));

            //If the peds did not correctly spawn, the callout will be disregarded
            if (!Robber.Exists()) return false;
            if (!Storekeeper.Exists()) return false;

            //If they did, display the location of the callout
            this.ShowCalloutAreaBlipBeforeAccepting(Store, 15f);
            this.AddMinimumDistanceCheck(5f, Store);

            //Give the aggressor his weapon
            gun1 = new Weapon("WEAPON_PISTOL", Store, 100);
            Robber.GiveNewWeapon("gun1");
            
            //Set the dispatch message and location
            this.CalloutMessage = "Mugging";
            this.CalloutPosition = Store;

            //Play dispatch audio
            Functions.PlayScannerAudioUsingPosition("CITIZENS_REPORT_03 CRIME_POSSIBLE_MUGGING IN_OR_ON_POSITION", this.Store);

            return base.OnBeforeCalloutDisplayed();
        }


        /// <summary>
        /// Called when the player accepts the callout
        /// </summary>
        /// <returns></returns>
        public override bool OnCalloutAccepted()
        {
            //Set state to en-route
            state = EMuggingState.EnRoute;

            //Attach a blip to the robber
            Location = Robber.AttachBlip();

            //Have the robber aim his gun at the storekeeper
            NativeFunction.CallByName<uint>("TASK_AIM_GUN_AT_ENTITY", Robber, Storekeeper, -1, true);
            Storekeeper.Tasks.PutHandsUp(-1, Robber);

            //Block ambient events from disrupting the callout
            Storekeeper.BlockPermanentEvents = true;

            //En-Route Message
            Game.DisplaySubtitle("Get to the ~r~Crime Scene~w~.", 6500);
            return base.OnCalloutAccepted();
        }

        /// <summary>
        /// Called if the callout is not accepted
        /// </summary>
        public override void OnCalloutNotAccepted()
        {
            base.OnCalloutNotAccepted();
            //Clean up what we spawned earlier, since the player didn't accept the callout.
            if (Robber.Exists()) Robber.Delete();
            if (Storekeeper.Exists()) Storekeeper.Delete();
            if (Location.Exists()) Location.Delete();
        }

        /// <summary>
        /// All callout logic should be done here.
        /// </summary>
        public override void Process()
        {
            base.Process();

            //If the player is driving to the scene, and their distance to the scene is less than 15, start the callout's logic.
            if (state == EMuggingState.EnRoute && Game.LocalPlayer.Character.Position.DistanceTo(Store) <= 15)
            {
                //Set state to on-scene
                state = EMuggingState.OnScene;

                //Start the callout's logic
                StartMuggingScenario();
            }

            //If the state is DecisionMade(The aggressor already decided what random outcome to execute), and the pursuit isn't running anymore, end the callout.
            if (state == EMuggingState.DecisionMade && !Functions.IsPursuitStillRunning(Pursuit))
            {
                this.End();
            }
        }

        /// <summary>
        /// Called when the callout ends
        /// </summary>
        public override void End()
        {

            //Dismiss the aggressor and victim, so they can be deleted by the game once the player leaves the scene.
            if (Robber.Exists()) Robber.Dismiss();
            if (Storekeeper.Exists()) Storekeeper.Dismiss();

            //Delete the blip attached to the aggressor
            if (Location.Exists()) Location.Delete();
            base.End();
        }

        /// <summary>
        /// The method that contains the logic
        /// </summary>
        public void StartMuggingScenario()
        {
            //ALWAYS START A NEW GAME FIBER IF YOU'RE GOING TO USE GameFiber.Sleep, DON'T SLEEP THE MAIN FIBER.
            GameFiber.StartNew(delegate
            {
                //Create the pursuit
                this.Pursuit = Functions.CreatePursuit();

                //Pick a random number, to choose a random outcome
                int r = new Random().Next(1, 4);

                //Set the state to decision made, since the outcome is chosen.
                state = EMuggingState.DecisionMade;

                //Execute one of the random outcomes
                if (r == 1)
                {
                    //The aggressor kills the victim before fleeing from the scene, and the victim flees the scene, trying to escape the aggressor.
                    NativeFunction.CallByName<uint>("TASK_COMBAT_PED", Robber, Storekeeper, 0, 1);
                    NativeFunction.CallByName<uint>("TASK_REACT_AND_FLEE_PED", Storekeeper, Robber);

                    //The aggressor shoots at the victim for 5 seconds, which either kills them, or severely injures them.
                    GameFiber.Sleep(5000);

                    NativeFunction.CallByName<uint>("TASK_REACT_AND_FLEE_PED", Storekeeper, Robber);
                    //Now for another random outcome
                    if (new Random().Next(1, 3) == 2)
                    {
                        //The aggressor attacks the player.
                        NativeFunction.CallByName<uint>("TASK_COMBAT_PED", Robber, Game.LocalPlayer.Character, 0, 1);

                        //We wait 4.5 seconds before adding the ped to a pursuit, since as soon as we add the aggressor to a pursuit, LSPDFR takes over the AI, and they won't attack the player anymore. They'll flee instead.
                        GameFiber.Sleep(4500);
                    }
                }
                else
                {
                    //The aggressor doesn't attack the victim, instead, both peds flee. We don't need to tell the aggressor to flee, as LSPDFR's pursuit system does that for us.
                    NativeFunction.CallByName<uint>("TASK_REACT_AND_FLEE_PED", Storekeeper, Robber);
                }
                //Dismiss the aggressor from our plugin
                Robber.Dismiss();

                //Add the aggressor to a pursuit
                Functions.AddPedToPursuit(this.Pursuit, Robber);

                //Dispatch a backup unit.
                Functions.RequestBackup(Game.LocalPlayer.Character.Position, LSPD_First_Response.EBackupResponseType.Pursuit, LSPD_First_Response.EBackupUnitType.LocalUnit);
            });
        }
    }
    /// <summary>
    /// Mugging States
    /// </summary>
    public enum EMuggingState
    {
        EnRoute,
        OnScene,
        DecisionMade
    }
}

 

 

Link to comment
Share on other sites

Ped.GiveNewWeapon was deprecated in RPH 34, I think.

myPed.Inventory.GiveNewWeapon(new WeaponDescriptor("WEAPON_PISTOL"), 56, false);

56 = the ammo count, and false means they don't have the weapon in their hand. (Change to true to make them hold it in their hand)

Edited by Stealth22

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
Share on other sites

2 hours ago, Stealth22 said:

Ped.GiveNewWeapon was deprecated in RPH 34, I think.

 

Yes, It was. As of 0.36 or even 0.34 its no longer memeber of Ped but instead a member of ped.inventory

In 0.33 it was marked as deprecated as far as I recall.

Edited by w35
Link to comment
Share on other sites

Inventory is not a reference am I missing something, our outdated?

7 hours ago, Stealth22 said:

Ped.GiveNewWeapon was deprecated in RPH 34, I think.

myPed.Inventory.GiveNewWeapon(new WeaponDescriptor("WEAPON_PISTOL"), 56, false);

56 = the ammo count, and false means they don't have the weapon in their hand. (Change to true to make them hold it in their hand)

Inventory is not a reference am I missing something, our outdated?

Link to comment
Share on other sites

Make sure you have referenced v0.36 of the RPH DLL in your project. 

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
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.

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.



×
×
  • Create New...