Jump to content

API Shooting.cs crash


jordRiot

Recommended Posts

Good Evening one and all,

Another one for y'all to ponder...

 

 if (this.IsPrankCall)
            {
                DelayedCaller.Call(
                    delegate
                    {
                        // Tell control it was a prank
                        Functions.PlaySound("EMERG_PRANK_CALL", true, false);
                        Functions.PrintText(Functions.GetStringFromLanguageFile("CALLOUT_SHOOTOUT_PRANK_END"), 5000);
                        Functions.AddTextToTextwall(Functions.GetStringFromLanguageFile("CALLOUT_SHOOTOUT_PRANK_END_TW"), Functions.GetStringFromLanguageFile("POLICE_SCANNER_CONTROL"));
                        this.End();
                    },
                    this,
                    10000);
 
                this.State = EShootoutState.Prank;
            }
            else
            {
                Log.Info("WAITING FOR SPOT", this);
                bool playerHasBeenSpotted = false;
                bool randomFight = Common.GetRandomBool(0, 300, 1);
 
                // Check whether player has been spotted
                foreach (LPed criminal in this.criminals)
                {
                    Log.Info("LOOP THROUGH CRIMINALSx", this);
                    if (criminal.Exists())
                    {
                        Log.Info("CRIMINAL EXISTS", this);
                        if (criminal.HasSpottedPed(LPlayer.LocalPlayer.Ped, false))
                        {
                            Log.Info("POLICE SPOTTED", this);
                            playerHasBeenSpotted = true;
                            break;
                        }
                    }
                }
                Log.Info("IF SPOTTED", this);
                // If player has been spotted
                if (playerHasBeenSpotted || randomFight)
                {
                    this.State = EShootoutState.Fighting;
                    this.Engage();
 
                    Functions.PrintText(Functions.GetStringFromLanguageFile("CALLOUT_SHOOTOUT_FIGHT_SUSPECTS"), 5000);
                }
            }
With regards to the above section of code, I've placed a number of Log.Info's to trace the crash, if the call turns out to be a prank, then it works fine and Ends however if not, and it ends up in the latter ELSE statement, the last log I get is "CRIMINAL EXISTS" which would leave me to believe that that the "HasSpottedPed" is causing a crash...any ideas why?!

Mainly aimed at LMS tbh, as you're the most likely to understand the function :)

Thanks!

J

Edited by LMS
Link to comment
Share on other sites

  • Management Team

Hello,

 

you had the code tag wrong, I fixed that for better readability. As for your problem, it might be caused by a handle mismatch of the player, that's at least the only thing I can think of, since it passes through all existance checks before. Can you try adding this line before the spotted check?

 

                       

Log.Info("Handle: " + Game.LocalPlayer.Character.pHandle + " -- LCPDFR handle: " + LPlayer.LocalPlayer.Ped.GPed.pHandle, this);

 

You may need to reference the ScriptHookDotNet.asi (rename to dll) shipped with LCPDFR to access the pHandle field.

 

Edit: Also can you try putting the .PDB file where your script is (might have to compile it in debug mode)? That should give you the exact function name and line number of where the crash happened (note that the LCPDFR inner stracktrace will not be available/have scrambled names due to obfuscation).

 

LMS

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

Link to comment
Share on other sites


[iNFO - 7:09:03 PM] [script.Shooting] Handle: 1027 -- LCPDFR handle: 1027
[iNFO - 7:09:03 PM] [script.Shooting] CRIMINAL EXISTS

 

 

:(

 

I'll attempt the other potential solutions :)

 

EDIT: Copied the pdb into the plugins folder alongside my dll but it doesn't produce an output ;/

Edited by jordRiot
Link to comment
Share on other sites

Sharing is caring and all that jazz... so it appears to work perfectly fine using the GTA Native Function rather than the LCPDFR function. Which for those who are interested is:

if (GTA.Native.Function.Call<bool>("HAS_CHAR_SPOTTED_CHAR",criminal.GPed.Model.Handle,LPlayer.LocalPlayer.Ped.GPed.pHandle))

instead of the current:

if (criminal.HasSpottedPed(LPlayer.LocalPlayer.Ped, false))

To explain the parameters, argument 1 is the HANDLE (int) of the character doing the spotting and argument 2 is the HANDLE (int) of the character to be spotted and it returns true or false. It is however a 360degree detection on it's own!

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