Jump to content

Small programming questions - API


LtFlash

Recommended Posts

Ohi,

that's me again. I'd like to ask you, LMS, if you could add a possibility to set custom PersonaData for the newly created ped, eg. as a param for an additional constructor. Correct me if I'm wrong but it seems that ped's data is impossible to change atm. Having a chance to control it would let me create a couple of interesting features  :wink:

Link to comment
Share on other sites

I failed in finding a solution so I gotta ask for a consult:

 

I want to display an image on the screen. I can't use a native since it seems to handle only build-in GTA files and PerFrameDrawing from a newly created class that inherits from GTA.Script doesn't work within LCPD:FR plugin. Is there any way to call e.Graphics.DrawXYZ() from the plugin or I need to recreate d3D function from SHDN?

Edited by LtFlash
Link to comment
Share on other sites

  • Management Team

Ohi,

that's me again. I'd like to ask you, LMS, if you could add a possibility to set custom PersonaData for the newly created ped, eg. as a param for an additional constructor. Correct me if I'm wrong but it seems that ped's data is impossible to change atm. Having a chance to control it would let me create a couple of interesting features  :wink:

 

Sure, you're not the first to ask and I can understand why people want to be able to change it, so the next version will have it.

 

I failed in finding a solution so I gotta ask for a consult:

 

I want to display an image on the screen. I can't use a native since it seems to handle only build-in GTA files and PerFrameDrawing from a newly created class that inherits from GTA.Script doesn't work within LCPD:FR plugin. Is there any way to call e.Graphics.DrawXYZ() from the plugin or I need to recreate d3D function from SHDN?

 

To redirect events from a newly GTA.Script, add a static event PerFrameDrawing to the script and invoke that in the class event. Then you can subscribe to the static event from everywhere and it gets invoked locally.

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

If I understand that correctly, a new static event ("helper") would only let to redirect an internal event of GTA.Script. The problem is that after creating a new instance of a class TestPerFrameDraw : GTA.Script inside the *.dll of lcpdfr mod (which is not located in .scripts obviously) the PerFrameDrawing isn't raised at all. I can only guess that SH doesn't "handle" the class and that's the reason of the issue because exactly the same TestPerFrameDraw as *.cs/*.net.dll located in .scripts works perfectly fine.

Link to comment
Share on other sites

  • Management Team

Correct, you'd have to add a helper dll and drop it into the scripts folder and then reference that from your LCPDFR script.

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

  • 3 months later...

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
Link to comment
Share on other sites

  • Management Team

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.

Link to comment
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();
}
Link to comment
Share on other sites

  • Management Team

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.

Link to comment
Share on other sites

  • 2 weeks later...

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!

 

 

Link to comment
Share on other sites

  • 1 month later...

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!

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

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

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

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

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

  • Management Team

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.

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