Jump to content
LtFlash

Small programming questions - API

Recommended Posts

I've been thinking lately about recurrence and lack of unpredictability while only using callouts as a core-element of gameplay. I've got some nice ideas for world events and I'd love to use 'em but the technical details (eg. ownership of objects; when to create, when to dispose) discourage me to touch it, especially when I've got so little free time. It would be great if you could add one example of a world event to the "API Example", eg hand-to-hand drug trade to 1.0d version.

Edited by LtFlash

Share this post


Link to post
Share on other sites

That's a good idea. I'm currently working on migrating all examples to GitHub and adding a few scenarios as well. Stay tuned.


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

Share this post


Link to post
Share on other sites

I've been thinking about existence check of resources we create. Do you think is it sufficient check it only once in the beginning of Process() or it's safer to check Exists() on every call of a ped/veh? If the first option is OK - what about RegisterState()?

 

Let me use examples:

1)

public override void Process()
{
    if (!CheckExistance(ref ped))
    {
        FailureEnd();
    }

    //code   

    ped.Task.WanderAround();
 
    //code    

    ped.Task.Wait(-1);
}

2)

public override void Process()
{
    //code
    
    if (CheckExistence(ref ped))
    {
        ped.Task.WanderAround();       
    }
    else FailureEnd();
   
    //code 

    if (CheckExistence(ref ped))
    {
        ped.Task.Wait(-1);        
    }
    else FailureEnd();
}

Share this post


Link to post
Share on other sites

It is, unless you delete the resource elsewhere during the same tick. For example, our ped intelligence class performs an existence check at the very beginning of a tick before processing all assigned tasks and AI logic. If it succeeds, there is no need to check for the ped's existence in any of its tasks. To solve the "deleted" issue, I have overriden the function and let all assigned tasks and scenarios know when a ped is deleted so they can safely shut down. So yes, if you have a good design, it is totally fine if you only call it once every tick.


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

Share this post


Link to post
Share on other sites

For all of those who would ever want to display an image from the level of LCPD:FR plugin:

you need to use GTA.Forms.Imagebox as a Control of GTA.Forms.Form. Setting the Transparency property of the main form to 100 and it's TitleSize to 0 will make your image the only visible object except of a mouse cursor (which can be used to Close() the form by imagebox_Click event). Happy programming!

 

 

Share this post


Link to post
Share on other sites

I've been thinking lately about recurrence and lack of unpredictability while only using callouts as a core-element of gameplay. I've got some nice ideas for world events and I'd love to use 'em but the technical details (eg. ownership of objects; when to create, when to dispose) discourage me to touch it, especially when I've got so little free time. It would be great if you could add one example of a world event to the "API Example", eg hand-to-hand drug trade to 1.0d version.

 

I'd be really excited for this.  This past week I've started playing with scripting for GTA IV - and while I'm starting to get the hang of some basic native stuff, I've got no real idea how to tie them into LCPDFR as a plugin off that (like callouts ++).

 

Didn't mean to high-jack.  I've been keeping up with all your questions Flash because I know I'll be asking them shortly myself.


logov1_zpsd8d8fbe3.jpeg

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

Share this post


Link to post
Share on other sites

I'd be really excited for this.  This past week I've started playing with scripting for GTA IV - and while I'm starting to get the hang of some basic native stuff, I've got no real idea how to tie them into LCPDFR as a plugin off that (like callouts ++).

 

Didn't mean to high-jack.  I've been keeping up with all your questions Flash because I know I'll be asking them shortly myself.

 

 

Ohi FinKone, "API Example" with world events is already available in LCPD:FR release package (GTAIVLCPDFRAPI Example) and @GitHub: https://github.com/LMSDev/LCPDFR-API

 

Feel free to ask, I might know answers to some simple question about 'cooperating' with GTA by script   :thumbsup:

Share this post


Link to post
Share on other sites

Ohi FinKone, "API Example" with world events is already available in LCPD:FR release package (GTAIVLCPDFRAPI Example) and @GitHub: https://github.com/LMSDev/LCPDFR-API

 

Feel free to ask, I might know answers to some simple question about 'cooperating' with GTA by script   :thumbsup:

 

Ty for the Github.  Do you mind if I also ask related API / scripting questions in this thread as compared to making a new one?


logov1_zpsd8d8fbe3.jpeg

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

Share this post


Link to post
Share on other sites

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!... ;)

 

 

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!

Share this post


Link to post
Share on other sites

If I were you I'd read ScripHook.NET help file, then API documentation and then make plans. Eg. you don't have to create peds/vehicles for your callout, you can claim ownership of one of existing entities so player won't ever see a creation of a car that pulls over to buy drugs.

 

The sequence with dealers is doable but I'd reduce it to one ped and a car. You can browse animation you can use with OpenIV.

Share this post


Link to post
Share on other sites

LMS,

I've got two issues I need your help with:

 

1) RegisterStateCallback + State

I thought it work like an improved version of switch..case but the State property of my script changes without my "help". I guess it works on basis of if() scanning them in all registered functions am I right? I'd like to decide myself when I want to change State and do it in the predefined order, is there a way to do it without additional bools?

 

2) Functions.GetAreaStringFromPosition()

It returns "Cervaza Heights" instead of "Cerveza Heights".

Share this post


Link to post
Share on other sites

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.


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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
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!

Share this post


Link to post
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?

 

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.

Share this post


Link to post
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!

Share this post


Link to post
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!

 

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.

Share this post


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