Jump to content

Small programming questions - API


LtFlash

Recommended Posts

Great!

 

For starters, not really API related, but does someone have a good read for accessing/creating/altering a INI file using 4.5 frame in VS C# - mostly in regards to letting players set their own keys.

I found a few examples with the Settings.Get's - but some of the args are often unclear (I hate it when I find a tutorial about something and the only thing they don't comment is the lines I'm really interested in learning about!)  Found decent reading on it.

 

Secondly I've got a few things I'd be interested in making, but I am not sure if I can even access the methods for them.  I'll explain.  One of my callout ideas was to have a corner thats got 3 or so guys hustlin' drugs.  The game already has a great method I'd like to hijack for this purpose - the one at which a Joe pulls up to pick up a random hooker, could be used so very little coding would have to be done...

So is there a way for me to hijack that native series of events, and jump off it when I need to?  (Once the drug dealer goes up to the Joes window, the Joe pulls off with drugs in his Car/Person, and the drug dealer either has some more drugs on him or has sold out.  Rather then spawn the AI on foot, spawn the car,the guy in the car, deal with the pathfinding, making the animations, and having it all reset while making sure the player doesn't see the next car spawn in for the new deal (if he chooses to sit and watch the dealer) I could just spawn the drug dealer "as a hooker", and add drugs to the buyer once done - yanno?  I'm not asking for code just asking if this type of hooking is already a thing.  I've yet to look into what behaviors I can trigger in the peds themselves.

 

Third is there any type of already made ragdoll rope like object in the game?  Or is there a way to apply a kind of ragdoll state to a series of objects chained together that anyone can think of?

 

Ok' I'll stop for now!... ;)

 

I don't think there's any such thing as a ragdoll object.  As far as I know there are only dynamic objects which react to simple forces (e.g. being pushed or shot or caught in an explosion) and animated objects which are animated with predefined animations, like the various US/other flags in the game.

 

 

LtFlash,

 

from a quick check I can tell that the State property is not changed by LCPDFR. I'd recommend having a look at your code again and verify you didn't miss a reference. State is only changed when you assign it, internally we just have a loop comparing its value against all registered states. In fact, State also supports flags, so you could have more than one state at the same time (not that this is always a wise design choice...). Let me know if issues persist.

 

2.) Not sure how I can help you with that, just a typo. Will change.

 

This may be a deliberate typo to match it up with the way it is spelled in the game's audio files?  Not sure, but I remember a few of the zones being spelled incorrectly.

"You tell me exactly what you want, and I will very carefully explain to you why it cannot be."

Link to comment
Share on other sites

1) Let me show an example as I discovered where's the problem:

[Flags]
private enum EState
{
    Away = 0x0,
    Close = 0x1,
    Scenario = 0x2,
    Wait = 0x3,
    End = 0x4,
};
this.RegisterStateCallback(EState.Away, Away);
this.RegisterStateCallback(EState.Close, Close);
this.RegisterStateCallback(EState.Scenario, Scenario);
this.RegisterStateCallback(EState.Wait, Wait);
this.RegisterStateCallback(EState.End, StateEnd);
this.State = EState.Away;
private void Away()
{
    if (LPlayer.LocalPlayer.Ped.Position.DistanceTo(spawn.Position) < 50.0f)
    {
        blipSpawn.Delete();
        this.State = EState.Close;
    }
    Log.Info("Away()", "CallbackState");
}

private void Close()
{
    if (LPlayer.LocalPlayer.Ped.Position.DistanceTo(spawn.Position) < 15.0f && LPlayer.LocalPlayer.Ped.CanSeePed(pedSuspect))
    {
        this.State = EState.Scenario;
    }
    Log.Info("Close()", "CallbackState");
}

private void Scenario()
{
    pedSuspect.Task.ClearAllImmediately();
    pedSuspect.Task.FleeFromChar(LPlayer.LocalPlayer.Ped);

    this.State = EState.Wait;

    Log.Info("Scenario()", "CallbackState");       
}

private void Wait()
{
    Log.Info("Wait()", "CallbackState");

    this.State = EState.End;
}

private void StateEnd()
{
    Log.Info("StateEnd()", "CallbackState");
}

Here's the outcome in the log file when State == EState.End:

[INFO - 4:59:41 PM] [CallbackState] Away()
[INFO - 4:59:41 PM] [CallbackState] Close()
[INFO - 4:59:41 PM] [CallbackState] Scenario()
[INFO - 4:59:41 PM] [CallbackState] Wait()
[INFO - 4:59:41 PM] [CallbackState] StateEnd()
[INFO - 4:59:41 PM] [CallbackState] Away()
[INFO - 4:59:41 PM] [CallbackState] Close()
[INFO - 4:59:41 PM] [CallbackState] Scenario()
[INFO - 4:59:41 PM] [CallbackState] Wait()
[INFO - 4:59:41 PM] [CallbackState] StateEnd()

That's how State is being changed without my control - on the stage of the last registered state all previous ones are being called = if any conditional clause returns true the current State is changed. Am I doing something wrong?

 

2) I hope you guys can fix in the next next update, I don't need nothing more about it xD. @Sam It seems to me that one or another Easton area was misspelled, I'm not sure though.

Edited by LtFlash
Link to comment
Share on other sites

  • Management Team

This may be a deliberate typo to match it up with the way it is spelled in the game's audio files?  Not sure, but I remember a few of the zones being spelled incorrectly.

 

Yeah right, that might be.

 

1) Let me show an example as I discovered where's the problem:

[Flags]
private enum EState
{
    Away = 0x0,
    Close = 0x1,
    Scenario = 0x2,
    Wait = 0x3,
    End = 0x4,
};

 

You are using the whole bit flags concept incorrectly.

 

In your case, a normal (non-flags) enum would do, as you don't need the State property to cover two cases at the same time. This is useful when you want a certain check to occur all the time, but don't want to call it explicitly from other states, so you can combine them. But when you make use of bitfields, you have to set the values to powers of two. It also recommended not to use 0x0 for an actual state, but rather as a None field. I will show you why below (that's also your main issue here).

The first column is how the flags look like in your setup in memory, the second one is how they should look like:

 

 

Away        00000000    00000001
Close       00000001    00000010
Scenario    00000010    00000100
Wait        00000011    00001000
End         00000100    00010000

 

 

They are compared each tick using a logical AND operation. So what happens when State is set to End is this (first iteration, comparing against EState.Away):

 

00000100 (State)

00000000 (EState.Away)

-------------

00000000

 

The result of the operation is 0, which you have defined as being EState.Away. Hence that state is called, setting State to EState.Close again, which then triggers the next state etc. That's why all states are called again. So never use 0 for an actual state value and use power of twos as values when working with flags. I hope this cleared it up a little.

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

OK, now I got it worked out. When I tried to locate the issue I've tried to use enum : int which gave me the same result as [Flags] - that where an idea of posting here comes from. With your tips I managed to understand the whole concept, it's damn genius. I wish I discovered it earlier :sick:  :teehee:

 

I want to add one more thing to your explanation, maybe it turn our to be helpful for someone. 0x0..0x10 are numbers in hexadecimal notation. In this (already working) example:

[Flags]
        internal enum EState
        {
            None = 0x0,
            Away = 0x1,
            Close = 0x2,
            Scenario = 0x4,
            Wait = 0x8,
            End = 0x10,
            MoreEnd = 0x20,
            EvenMoreEnd = 0x40,
        };

...you can see powers of two which is easier to read in this form:

[Flags]
        internal enum EState
        {
            None = 0,
            Away = 1,
            Close = 2,
            Scenario = 4,
            Wait = 8,
            End = 16,
            MoreEnd = 32,
            EvenMoreEnd = 64,
        };

...and works the same way.

 

Using bit flags you can have more than one State active:

this.State = EState.Scenario | EState.End; //OR

you can turn off one of active States with XOR:

this.State = this.State ^ EState.Scenario;

Once more thanks, it'll bring new quality into my simple scripts.

 

Edited by LtFlash
Link to comment
Share on other sites

This was a big help.  I also was using them wrong - and I was watching the log bounce around without my understand.  I used Enums before a good bit - but when I applied them in the API, I was really confused what and why the jump around was happening also.

 

I still don't fully understand - it might be because I've had a few beers, but I'm going to keep reading this until I get it.  :D

Edited by FinKone

logov1_zpsd8d8fbe3.jpeg

Help my channel grow and I can explain to my wife why this addiction to coding is a good thing!

Link to comment
Share on other sites

Small API question because I can't seem to find if its a option.  For Officers responding, is there a way to make sure they are set to passive driving, other then having the player have to use the keys to set this option?  I mean it works fine using the keys, but the one LPed Officer I'm using seems to have a "RAM RAM RAM" right away if a chase pops off.  Not a big issue, I was just wondering if I have a way to set his driving behavior in a functions call?

logov1_zpsd8d8fbe3.jpeg

Help my channel grow and I can explain to my wife why this addiction to coding is a good thing!

Link to comment
Share on other sites

  • Management Team

No, I don't think you can control that. The only kind of control about behavior is forcing suspects to fight.

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

  • Management Team

Small API question because I can't seem to find if its a option.  For Officers responding, is there a way to make sure they are set to passive driving, other then having the player have to use the keys to set this option?  I mean it works fine using the keys, but the one LPed Officer I'm using seems to have a "RAM RAM RAM" right away if a chase pops off.  Not a big issue, I was just wondering if I have a way to set his driving behavior in a functions call?

 

Added SetPursuitTactics and SetPursuitHelicopterTactics to the API :)

Will be available soon.

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

Talking about new API functions; would it be possible to get all peds arrested by a player? It would let us to teleport LocalPlayer + partners + arrested peds (all we need), eg. from a roof of a bldg without an interior.

 

...and SetPursuitTactics() is something I definitely need for a new call. Thanks!

Link to comment
Share on other sites

  • Management Team

Talking about new API functions; would it be possible to get all peds arrested by a player? It would let us to teleport LocalPlayer + partners + arrested peds (all we need), eg. from a roof of a bldg without an interior.

 

...and SetPursuitTactics() is something I definitely need for a new call. Thanks!

 

Do you mean the peds that are currently following the player, i.e. where the player opted to take them to the PD? If so, that should be easy to add.

 

Great to hear! :)

 

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

  • 1 year later...
  • Management Team
1 minute ago, LtFlash said:

@LMS The new VS versions does not work with LCPD:FR library - shows no classes in dll. Is there any way to by-pass this or I got to download VS 2012?

Could you elaborate on that, i.e. show an error log? Or doesn't it show any functions at all?

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

@LMS

I opened the previously working *.sln file in VS 2015, it does not recognize any identifier nor namespace (reference not found) from LCPD First Response.dll file (I re-downloaded the latest version ofc and included it into the project). When I open Object Browser I can browse all namespaces and content of ScriptHook.NET, SlimDX but LCPDFR seems empty, when trying to expand only the arrow changes from closed (>) to opened (_|) and nothing shows up. The file itself seems OK - I opened it in ILSpy and it shows the content properly. Solution platform is set to x86 and .NET to 4.5.

I can download VS12 but that's 12 gigs of an installation folder just for 1 project.

Edited by LtFlash
Link to comment
Share on other sites

  • Management Team
20 hours ago, LtFlash said:

@LMS

I opened the previously working *.sln file in VS 2015, it does not recognize any identifier nor namespace (reference not found) from LCPD First Response.dll file (I re-downloaded the latest version ofc and included it into the project). When I open Object Browser I can browse all namespaces and content of ScriptHook.NET, SlimDX but LCPDFR seems empty, when trying to expand only the arrow changes from closed (>) to opened (_|) and nothing shows up. The file itself seems OK - I opened it in ILSpy and it shows the content properly. Solution platform is set to x86 and .NET to 4.5.

I can download VS12 but that's 12 gigs of an installation folder just for 1 project.

Okay I see, I will try it myself this weekend and report back. In case I forget, don't hesitate to tag me again in a few days.

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

how does one create callouts?

I know it might be big but you guys might be able to help!

 

Nvidia GTX 1070FE, MSI Z170A SLI PLUS, I7 6700K

Chandler, Az

Steam: The_Lone_Wolf293                               GTA5-Mods.com: TheLoneWolf293

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