Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Game freeze and crash with this code

Featured Replies

This code is the process() part of an objects on the road callout:

public override void Process()
        {
            base.Process();
            if (Game.IsKeyDown(System.Windows.Forms.Keys.End))
            {
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            }
            if (onScene == false && Game.LocalPlayer.Character.DistanceTo(spawnPosition) < 10)
            {
                onScene = true;
                Game.DisplayHelp("Approach the ~p~objects~w~, and press ~b~Delete~w~ to move the objects off the road.");
                if(calloutArea.Exists()) { calloutArea.Delete(); }
                prop0Blip = prop0.AttachBlip();
                prop0Blip.Color = System.Drawing.Color.Purple;
                prop1Blip = prop1.AttachBlip();
                prop1Blip.Color = System.Drawing.Color.Purple;
                prop2Blip = prop2.AttachBlip();
                prop2Blip.Color = System.Drawing.Color.Purple;
                while (!Game.IsKeyDown(System.Windows.Forms.Keys.Delete))
                {
                    Game.DisplayHelp("Press ~b~Delete~w~ to move the objects out of the road.");
                }
                Game.DisplayNotification("Please wait ~g~10 seconds~w~ for the objects to be moved from the road.");
                GameFiber.Sleep(10000);
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            
            }
            



        }

However, when the if statement is done after the player reaches 10 meteres away from the object(s), the game freezes and crashes. Any ideas?

  • Replies 21
  • Views 672
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • I really don't see anything, sorry! are you sure it's the if statement? try using Game.LogTrival("Text here"); With this you can log things, put this before the if statement and a couple of

  • Just replace the while with if, that should work

  • Oh okay, nice

1 minute ago, techgamer15 said:

This code is the process() part of an objects on the road callout:


public override void Process()
        {
            base.Process();
            if (Game.IsKeyDown(System.Windows.Forms.Keys.End))
            {
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            }
            if (onScene == false && Game.LocalPlayer.Character.DistanceTo(spawnPosition) < 10)
            {
                onScene = true;
                Game.DisplayHelp("Approach the ~p~objects~w~, and press ~b~Delete~w~ to move the objects off the road.");
                if(calloutArea.Exists()) { calloutArea.Delete(); }
                prop0Blip = prop0.AttachBlip();
                prop0Blip.Color = System.Drawing.Color.Purple;
                prop1Blip = prop1.AttachBlip();
                prop1Blip.Color = System.Drawing.Color.Purple;
                prop2Blip = prop2.AttachBlip();
                prop2Blip.Color = System.Drawing.Color.Purple;
                while (!Game.IsKeyDown(System.Windows.Forms.Keys.Delete))
                {
                    Game.DisplayHelp("Press ~b~Delete~w~ to move the objects out of the road.");
                }
                Game.DisplayNotification("Please wait ~g~10 seconds~w~ for the objects to be moved from the road.");
                GameFiber.Sleep(10000);
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            
            }
            



        }

However, when the if statement is done after the player reaches 10 meteres away from the object(s), the game freezes and crashes. Any ideas?

Try <= 10) instead of < 10)

  • Author
35 minutes ago, HazyTube said:

Oh okay, weird isue =I cant find anything wrong atm

Ive changed it to game.localcharacter.position.distanceto and it still does it so I am completely clueless.

 

 

Just now, techgamer15 said:

Ive changed it to game.localcharacter.position.distanceto and it still does it so I am completely clueless.

 

 

Yeah, but you have to use distanceto2D

  • Author
5 minutes ago, HazyTube said:

Yeah, but you have to use distanceto2D

This is the entire callout code, if it helps:

 

Spoiler

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using Rage;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Engine.Scripting.Entities;

namespace BasicCallouts.Callouts
{
    [CalloutInfo("ObjectsObstructingRoadway", CalloutProbability.VeryHigh)]
    class ObjectsObstructingRoadway : Callout
    {
        // 11 objects total for each

        private Rage.Object prop0;
        private Rage.Object prop1;
        private Rage.Object prop2;
        string[] props0 = {"prop_bin_04a", "prop_bin_10b", "prop_table_01", "prop_bench_11", "prop_table_03"};
        string[] props1 = {"prop_bin_04a", "prop_bin_10b", "prop_table_01", "prop_bench_11", "prop_table_03"};
        string[] props2 = {"prop_bin_04a", "prop_bin_10b", "prop_table_01", "prop_bench_11", "prop_table_03"};
        private Vector3 spawnPosition;
        private Blip prop0Blip, prop1Blip, prop2Blip, calloutArea;
        private bool onScene;
        Random prop0Number = new Random();
        Random prop1Number = new Random();
        Random prop2Number = new Random();

        public override bool OnBeforeCalloutDisplayed()
        {
            spawnPosition = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(400f));
            ShowCalloutAreaBlipBeforeAccepting(spawnPosition, 30f);
            AddMinimumDistanceCheck(85f, spawnPosition);
            CalloutMessage = "Objects Obstructing Roadway";
            CalloutPosition = spawnPosition;
            Functions.PlayScannerAudioUsingPosition("CITIZENS_REPORT_01 ROAD_BLOCK_01 IN_OR_ON_POSITION", spawnPosition);
            return base.OnBeforeCalloutDisplayed();
        }
        public override bool OnCalloutAccepted()
        {
            Functions.PlayScannerAudio("RESPOND_CODE_2");
            Game.DisplayNotification("Respond ~r~Code 2~w");
            Game.DisplayHelp("Press ~b~End~w~ to end the callout.");
            Game.DisplayNotification("Drivers have reported several ~p~objects~w~ in the ~y~roadway~w~. Respond quickly to prevent any accidents.");
            int prop0Chosen = prop0Number.Next(5);
            int prop1Chosen = prop0Number.Next(5);
            int prop2Chosen = prop0Number.Next(5);
            Game.LogTrivial("Prop0 number: " + prop0Chosen);
            Game.LogTrivial("Prop1 number: " + prop1Chosen);
            Game.LogTrivial("Prop2 number: " + prop2Chosen);
            prop0 = new Rage.Object(props0[prop0Chosen], spawnPosition, 0);
            prop1 = new Rage.Object(props1[prop1Chosen], prop0.GetOffsetPositionFront(2f), 0);
            prop2 = new Rage.Object(props2[prop2Chosen], prop1.GetOffsetPositionRight(2.5f), 0);
            calloutArea = new Blip(spawnPosition, 40f);
            calloutArea.Color = (System.Drawing.Color.Yellow);
            calloutArea.Alpha = 0.5f;
            calloutArea.EnableRoute(System.Drawing.Color.Yellow);
            
            



            return base.OnCalloutAccepted();
        }
        public override void Process()
        {
            base.Process();
            if (Game.IsKeyDown(System.Windows.Forms.Keys.End))
            {
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            }
            if (onScene == false && Game.LocalPlayer.Character.Position.DistanceTo(spawnPosition) <= 10)
            {
                onScene = true;
                Game.DisplayHelp("Approach the ~p~objects~w~, and press ~b~Delete~w~ to move the objects off the road.");
                if(calloutArea.Exists()) { calloutArea.Delete(); }
                prop0Blip = prop0.AttachBlip();
                prop0Blip.Color = System.Drawing.Color.Purple;
                prop1Blip = prop1.AttachBlip();
                prop1Blip.Color = System.Drawing.Color.Purple;
                prop2Blip = prop2.AttachBlip();
                prop2Blip.Color = System.Drawing.Color.Purple;
                while (!Game.IsKeyDown(System.Windows.Forms.Keys.Delete))
                {
                    Game.DisplayHelp("Press ~b~Delete~w~ to move the objects out of the road.");
                }
                Game.DisplayNotification("Please wait ~g~10 seconds~w~ for the objects to be moved from the road.");
                GameFiber.Sleep(10000);
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            
            }
            



        }
        public override void End()
        {
            base.End();
            if (prop0.Exists()) { prop0.Delete(); }
            if (prop1.Exists()) { prop1.Delete(); }
            if (prop2.Exists()) { prop2.Delete(); }
            if (calloutArea.Exists()) { calloutArea.Delete(); }
            if (prop0Blip.Exists()) { prop0Blip.Delete(); }
            if (prop1Blip.Exists()) { prop1Blip.Delete(); }
            if (prop2Blip.Exists()) { prop2Blip.Delete(); }
        }

    }
}

 

 

Edited by techgamer15

1 minute ago, techgamer15 said:

This is the entire callout code, if it helps:

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using Rage;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Engine.Scripting.Entities;

namespace BasicCallouts.Callouts
{
    [CalloutInfo("ObjectsObstructingRoadway", CalloutProbability.VeryHigh)]
    class ObjectsObstructingRoadway : Callout
    {
        // 11 objects total for each

        private Rage.Object prop0;
        private Rage.Object prop1;
        private Rage.Object prop2;
        string[] props0 = {"prop_bin_04a", "prop_bin_10b", "prop_table_01", "prop_bench_11", "prop_table_03"};
        string[] props1 = {"prop_bin_04a", "prop_bin_10b", "prop_table_01", "prop_bench_11", "prop_table_03"};
        string[] props2 = {"prop_bin_04a", "prop_bin_10b", "prop_table_01", "prop_bench_11", "prop_table_03"};
        private Vector3 spawnPosition;
        private Blip prop0Blip, prop1Blip, prop2Blip, calloutArea;
        private bool onScene;
        Random prop0Number = new Random();
        Random prop1Number = new Random();
        Random prop2Number = new Random();

        public override bool OnBeforeCalloutDisplayed()
        {
            spawnPosition = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(400f));
            ShowCalloutAreaBlipBeforeAccepting(spawnPosition, 30f);
            AddMinimumDistanceCheck(85f, spawnPosition);
            CalloutMessage = "Objects Obstructing Roadway";
            CalloutPosition = spawnPosition;
            Functions.PlayScannerAudioUsingPosition("CITIZENS_REPORT_01 ROAD_BLOCK_01 IN_OR_ON_POSITION", spawnPosition);
            return base.OnBeforeCalloutDisplayed();
        }
        public override bool OnCalloutAccepted()
        {
            Functions.PlayScannerAudio("RESPOND_CODE_2");
            Game.DisplayNotification("Respond ~r~Code 2~w");
            Game.DisplayHelp("Press ~b~End~w~ to end the callout.");
            Game.DisplayNotification("Drivers have reported several ~p~objects~w~ in the ~y~roadway~w~. Respond quickly to prevent any accidents.");
            int prop0Chosen = prop0Number.Next(5);
            int prop1Chosen = prop0Number.Next(5);
            int prop2Chosen = prop0Number.Next(5);
            Game.LogTrivial("Prop0 number: " + prop0Chosen);
            Game.LogTrivial("Prop1 number: " + prop1Chosen);
            Game.LogTrivial("Prop2 number: " + prop2Chosen);
            prop0 = new Rage.Object(props0[prop0Chosen], spawnPosition, 0);
            prop1 = new Rage.Object(props1[prop1Chosen], prop0.GetOffsetPositionFront(2f), 0);
            prop2 = new Rage.Object(props2[prop2Chosen], prop1.GetOffsetPositionRight(2.5f), 0);
            calloutArea = new Blip(spawnPosition, 40f);
            calloutArea.Color = (System.Drawing.Color.Yellow);
            calloutArea.Alpha = 0.5f;
            calloutArea.EnableRoute(System.Drawing.Color.Yellow);
            
            



            return base.OnCalloutAccepted();
        }
        public override void Process()
        {
            base.Process();
            if (Game.IsKeyDown(System.Windows.Forms.Keys.End))
            {
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            }
            if (onScene == false && Game.LocalPlayer.Character.Position.DistanceTo2D(spawnPosition) <= 10)
            {
                onScene = true;
                Game.DisplayHelp("Approach the ~p~objects~w~, and press ~b~Delete~w~ to move the objects off the road.");
                if(calloutArea.Exists()) { calloutArea.Delete(); }
                prop0Blip = prop0.AttachBlip();
                prop0Blip.Color = System.Drawing.Color.Purple;
                prop1Blip = prop1.AttachBlip();
                prop1Blip.Color = System.Drawing.Color.Purple;
                prop2Blip = prop2.AttachBlip();
                prop2Blip.Color = System.Drawing.Color.Purple;
                while (!Game.IsKeyDown(System.Windows.Forms.Keys.Delete))
                {
                    Game.DisplayHelp("Press ~b~Delete~w~ to move the objects out of the road.");
                }
                Game.DisplayNotification("Please wait ~g~10 seconds~w~ for the objects to be moved from the road.");
                GameFiber.Sleep(10000);
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            
            }
            



        }
        public override void End()
        {
            base.End();
            if (prop0.Exists()) { prop0.Delete(); }
            if (prop1.Exists()) { prop1.Delete(); }
            if (prop2.Exists()) { prop2.Delete(); }
            if (calloutArea.Exists()) { calloutArea.Delete(); }
            if (prop0Blip.Exists()) { prop0Blip.Delete(); }
            if (prop1Blip.Exists()) { prop1Blip.Delete(); }
            if (prop2Blip.Exists()) { prop2Blip.Delete(); }
        }

    }
}

 

I really don't see anything, sorry!

are you sure it's the if statement? try using Game.LogTrival("Text here");

With this you can log things, put this before the if statement and a couple of other places, then you can see what causes the issue

  • Author
1 minute ago, HazyTube said:

I really don't see anything, sorry!

are you sure it's the if statement? try using Game.LogTrival("Text here");

With this you can log things, put this before the if statement and a couple of other places, then you can see what causes the issue

Ill try adding some more. 

  • Author
7 minutes ago, HazyTube said:

I really don't see anything, sorry!

are you sure it's the if statement? try using Game.LogTrival("Text here");

With this you can log things, put this before the if statement and a couple of other places, then you can see what causes the issue

Apparently its not the if statement. Becuase I put a log trivial under the statement and it got written into the RAGE log so what else could it be?

Just now, techgamer15 said:

Apparently its not the if statement. Becuase I put a log trivial under the statement and it got written into the RAGE log so what else could it be?

Does it happen when you accept the callout?

  • Author
1 minute ago, HazyTube said:

Does it happen when you accept the callout?

No its only after I get less than 10 meteres from the object, hence why I thought it was the if statement.

Just now, techgamer15 said:

No its only after I get less than 10 meteres from the object, hence why I thought it was the if statement.

Yeah I think it's the if statement then, it gets loaded, but it only happens when your 10m from the object, have a look at the if statement and maybe the objects

  • Author
2 minutes ago, HazyTube said:

Yeah I think it's the if statement then, it gets loaded, but it only happens when your 10m from the object, have a look at the if statement and maybe the objects

Its the while loop, 

while (!Game.IsKeyDown(System.Windows.Forms.Keys.Delete))
                {
                    Game.DisplayHelp("Press ~b~Delete~w~ to move the objects out of the road.");
                }
                Game.DisplayNotification("Please wait ~g~10 seconds~w~ for the objects to be moved from the road.");
                GameFiber.Sleep(10000);
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();

This checks to see if the player presses the delete key, and keeps the display help on there until they do. It must be something to do with this.

Just now, techgamer15 said:

Its the while loop, 


while (!Game.IsKeyDown(System.Windows.Forms.Keys.Delete))
                {
                    Game.DisplayHelp("Press ~b~Delete~w~ to move the objects out of the road.");
                }
                Game.DisplayNotification("Please wait ~g~10 seconds~w~ for the objects to be moved from the road.");
                GameFiber.Sleep(10000);
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();

This checks to see if the player presses the delete key, and keeps the display help on there until they do. It must be something to do with this.

I think this has to be a if statement instead of while

  • Author
5 minutes ago, HazyTube said:

I think this has to be a if statement instead of while

How might I do that becuase its giving me syntax errors at the moment.

  • Author
33 minutes ago, HazyTube said:

Just replace the while with if, that should work

All fixed now, turns out the issue was with me not adding GameFiber.Yield()

 

Heres the code for anyone who comes across this topic in the future:

 

Spoiler

 public override void Process()
        {
            base.Process();
            GameFiber.StartNew(delegate
            { 
            if (Game.IsKeyDown(System.Windows.Forms.Keys.End))
            {
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();
            }
            if (onScene == false && Game.LocalPlayer.Character.Position.DistanceTo(spawnPosition) <= 10)
            {
                Game.LogTrivial("If statement executed");
                onScene = true;
                Game.LogTrivial("Boolean changed.");
                Game.DisplayHelp("Approach the ~p~objects~w~, and press ~b~Delete~w~ to move the objects off the road.");
                if (calloutArea.Exists()) { calloutArea.Delete(); }
                Game.LogTrivial("If statement 2 done.");
                prop0Blip = prop0.AttachBlip();
                Game.LogTrivial("blip 0 done");
                prop0Blip.Color = System.Drawing.Color.Purple;
                prop1Blip = prop1.AttachBlip();
                Game.LogTrivial("blip 1 done");
                prop1Blip.Color = System.Drawing.Color.Purple;
                prop2Blip = prop2.AttachBlip();
                Game.LogTrivial("blip 2 done");
                prop2Blip.Color = System.Drawing.Color.Purple;
                Game.DisplayHelp("Press ~b~Delete~w~ to move the objects out of the road.");
                while (true)
                {
                   GameFiber.Yield();
                    if (Game.IsKeyDown(System.Windows.Forms.Keys.Delete))
                    {
                        break;
                    }

                }
                Game.DisplayNotification("Please wait ~g~10 seconds~w~ for the objects to be moved from the road.");
                GameFiber.Sleep(10000);
                Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
                Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
                End();

            }


        });
        }

 

 

Edited by techgamer15

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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.