Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Happy Holidays from the GTANet team!

.net Some questions about heli spawning police search event and playing animated image


SayagoHren
 Share

Recommended Posts

Hi guys! I am a newer in scripting, but was inspired by many amazing mods for gta 5. I have some questions, was searching for them in this forum, but had no success in it. Hope you can give me some answers.

 

Firstly, in my mod I spawn helicopters, which should chase and attack player. Everything is working fine, but I have a problem: if I mark heli and peds in it AsNoLongerNeeded the heli is starting to fly away althouth it hask taks to chase the player. If i do not mark it  AsNoLongerNeeded heli chases player correctly but after desroying heli its "dead body" exists constantly on the map, it is not good at all. Also tried to make "heli.IsPersistent = false" This does not help.

 

Secondly, I Want to know, is it possible to make spawned by script vehicles and helis behave like vanilla s police cars and helicopters in search mode - randomly fly and ride near the player searching for him?

 

And last thing, does scripthook have a function to draw animated images on the screen like gif? Or the only way is to create the loop and put there Ui.Drawtexture commands? Hope you can help me, thank you for your attention.

Edited by SayagoHren
Link to comment
Share on other sites

2 hours ago, SayagoHren said:

Firstly, in my mod I spawn helicopters, which should chase and attack player. Everything is working fine, but I have a problem: if I mark heli and peds in it AsNoLongerNeeded the heli is starting to fly away althouth it hask taks to chase the player. If i do not mark it  AsNoLongerNeeded heli chases player correctly but after desroying heli its "dead body" exists constantly on the map, it is not good at all. Also tried to make "heli.IsPersistent = false" This does not help.

The best way I can think of doing that, is to check if each of the peds and heli with .IEntity.sAlive or Entity.IsDead or !Entity.Exists() each frame and if anything fails that check, mark that entity as no longer needed.

 

So you'd do something like this:

    if (!heli.IsAlive || heli.IsDead || !heli.Exists())
    {
        heli.MarkAsNoLongerNeeded();
    }

I'd probably store them in a List<Entity> as well, so that you can remove the dead ones from the list and just check the ones that are left in the list until they are all dead.

 

If you do that, make sure to go through the List backwards, or you will get a "Can't modify collection error" if you remove anything. Start from List.Count - 1 and then go backwards to zero and you'll be fine as it is only ever removing the one on the end of the list.

 

2 hours ago, SayagoHren said:

Secondly, I Want to know, is it possible to make spawned by script vehicles and helis behave like vanilla s police cars and helicopters in search mode - randomly fly and ride near the player searching for him?

You could make them drive to the player's position, or a position around it using Ped.Position.Around. Use the _CAN_PED_SEE_PED Native when they get there and if that returns true. make them head to the player, if it returns false, make them head to a position in the player's general area instead.

 

If you store your position every 1 or 2 seconds or so and then send them to where you were, it would make it seem like they were responding to a "Last seen at..." report, instead of magically knowing exactly where you are.

 

There are several FOLLOW and CHASE natives that will help you here. Search this site for natives and some info on how some of them work. http://www.dev-c.com/nativedb/

 

Edit: I should have mentioned, many of these are in the Entity.Task. behaviours as well, along with TaskSequences, which you also might find useful.

 

2 hours ago, SayagoHren said:

And last thing, does scripthook have a function to draw animated images on the screen like gif? Or the only way is to create the loop and put there Ui.Drawtexture commands? Hope you can help me, thank you for your attention.

You could have several frames stored as images and then play them back in sequence, that's about as close as you're going to get to animated images.

 

If you name them image_0.jpg, image_1.jpg, image_2.jpg etc... and then use an index to create the filename, something like this...

    // Declare as Global variables
    private int ImageIndex = 0;
    private int NumberOfImages = 10;

    // Call from onTick()
    private void DrawImages()
    {
        string filename = "";
        Size imageSize = new Size(256, 256); // Whatever size your image is
        Point imagePosition = new Point(UI.WIDTH / 2, UI.HEIGHT / 2); // Draws to the centre of the screen

        filename = string.Format("image_{0}.jpg", ImageIndex);
        UI.DrawTexture(filename, 0, 0, 50, imagePosition, imageSize);
        ImageIndex = (ImageIndex + 1) % NumberOfImages;
    }

... that will animate the images. Make sure you include the path to the image as well in the filename, before you pass it to the UI.DrawTexture command.

 

You'd need to put a delay in there for changing onto the next frame, or it's going to be too fast. If you want transparent images, then you'd use PNG files instead of JPG.

 

If any of that is confusing, let me know and I will clarify for you. I'm currently drinking Vodka, so my thinking is a little fuzzy.

Edited by LeeC22
  • Like 2
Link to comment
Share on other sites

21 hours ago, LeeC22 said:

The best way I can think of doing that, is to check if each of the peds and heli with .IEntity.sAlive or Entity.IsDead or !Entity.Exists() each frame and if anything fails that check, mark that entity as no longer needed.

 

So you'd do something like this:

    if (!heli.IsAlive || heli.IsDead || !heli.Exists())
    {
        heli.MarkAsNoLongerNeeded();
    }

I'd probably store them in a List<Entity> as well, so that you can remove the dead ones from the list and just check the ones that are left in the list until they are all dead.

 

If you do that, make sure to go through the List backwards, or you will get a "Can't modify collection error" if you remove anything. Start from List.Count - 1 and then go backwards to zero and you'll be fine as it is only ever removing the one on the end of the list.

 

Hi, tank you for your answer,  I want to say about checking entity, I also tried this trick, but script crashes with error of null exception or something like this, I guess it is so because before first spawn it tries to check the entity which does not exist yet.  I think that saving all dead helis in variable is complicated because the idea of my script is in endless spawning of enemies-helis. This is my code:

 If Native.Function.Call(Of Boolean)(Native.Hash.IS_ENTITY_DEAD, heli_6_1) = True Then
                If heli_6_1.exists() = true
                heli_6_1.MarkAsNoLongerNeeded()// this peace of cod makes script crash
                End If
                heli_6_1 = World.CreateVehicle("Annihilator", Game.Player.Character.Position + new Vector3(0, 0, 100.0F) + Game.Player.Character.ForwardVector * 400.0F)
                If Game.Player.Character.IsInVehicle = True Then
                heli_6_1.Heading = Game.Player.Character.CurrentVehicle.Heading - 180
                End If
                                        
                    ped_heli_6_1_1 = heli_6_1.CreatePedOnSeat(VehicleSeat.Driver, "s_m_m_fibsec_01")
                    weapselect()
                    ped_heli_6_1_1.Weapons.Give(weaphash, 999, True, True)
                    Native.Function.Call(Native.Hash.TASK_HELI_CHASE, ped_heli_6_1_1, Game.Player.Character, 0.0, 0.0, 50.0)
                    ped_heli_6_1_1.AlwaysKeepTask = True

                    ped_heli_6_1_2 = heli_6_1.CreatePedOnSeat(VehicleSeat.RightFront, "s_m_m_fibsec_01")
                    weapselect()
                    ped_heli_6_1_2.Weapons.Give(weaphash, 999, True, True)

                    ped_heli_6_1_3 = heli_6_1.CreatePedOnSeat(VehicleSeat.LeftRear, "s_m_m_fibsec_01")
                    weapselect()
                    ped_heli_6_1_3.Weapons.Give(weaphash, 999, True, True)

                    ped_heli_6_1_4 = heli_6_1.CreatePedOnSeat(VehicleSeat.RightRear, "s_m_m_fibsec_01")
                    weapselect()
                    ped_heli_6_1_4.Weapons.Give(weaphash, 999, True, True)

                    Native.Function.Call(Native.Hash.SET_PED_AS_COP, ped_heli_6_1_1, true)
                    Native.Function.Call(Native.Hash.SET_PED_AS_COP, ped_heli_6_1_2, true)
                    Native.Function.Call(Native.Hash.SET_PED_AS_COP, ped_heli_6_1_3, true)
                    Native.Function.Call(Native.Hash.SET_PED_AS_COP, ped_heli_6_1_4, true)
                    
                    'ped_heli_6_1_1.Task.Wait(2000)
                    'ped_heli_6_1_2.Task.Wait(2000)
                    'ped_heli_6_1_3.Task.Wait(2000)
                    'ped_heli_6_1_4.Task.Wait(2000)

                    'ped_heli_6_1_1.MarkAsNoLongerNeeded()
                    'ped_heli_6_1_2.MarkAsNoLongerNeeded()
                    'ped_heli_6_1_3.MarkAsNoLongerNeeded()
                    'ped_heli_6_1_4.MarkAsNoLongerNeeded()
                  
            
End If
End Sub

 

Possibly I can make a boolean IsHeliSpawnedFirstTime and add it to exists check code, but the question is: how the game will store heli6_1 dead and heli_6_1 spawned and alive, maybe nolonger nedeeded will be applied also to new spawned helis?

Edited by SayagoHren
Link to comment
Share on other sites

34 minutes ago, SayagoHren said:

Possibly I can make a boolean IsHeliSpawnedFirstTime and add it to exists check code, but the question is: how the game will store heli6_1 dead and heli_6_1 spawned and alive, maybe nolonger nedeeded will be applied also to new spawned helis?

When you spawn a new heli, add that to the List<Entity> and it will get checked with the rest.

 

    // Declare as Global variable
    List<Entity> ActiveEntities = new List<Entity>();
      
    // Spawn a heli
    Vehicle heli = World.CreateVehicle("frogger", position, heading);
    ActiveEntities.Add(heli);
      
    // In onTick()
    // Check for dead etc...
    if (ActiveEntities.Count > 0)
    {
        for (int i = ActiveEntities.Count - 1; i >= 0; i--)
        {
            if (ActiveEntities[i].IsDead || !ActiveEntities[i].IsAlive || !ActiveEntities[i].Exists())
            {
                ActiveEntities[i].MarkAsNoLongerNeeded();
                ActiveEntities.RemoveAt(i);
            }
        }
    }

The game knows if things are alive or dead, all you need to do, is check that and remove them when they die. You can add Vehicles and Peds into that List<Entity> and they will all get checked and removed.

Link to comment
Share on other sites

10 minutes ago, LeeC22 said:

When you spawn a new heli, add that to the List<Entity> and it will get checked with the rest.

 

    // Declare as Global variable
    List<Entity> ActiveEntities = new List<Entity>();
      
    // Spawn a heli
    Vehicle heli = World.CreateVehicle("frogger", position, heading);
    ActiveEntities.Add(heli);
      
    // In onTick()
    // Check for dead etc...
    if (ActiveEntities.Count > 0)
    {
        for (int i = ActiveEntities.Count - 1; i >= 0; i--)
        {
            if (ActiveEntities[i].IsDead || !ActiveEntities[i].IsAlive || !ActiveEntities[i].Exists())
            {
                ActiveEntities[i].MarkAsNoLongerNeeded();
                ActiveEntities.RemoveAt(i);
            }
        }
    }

The game knows if things are alive or dead, all you need to do, is check that and remove them when they die. You can add Vehicles and Peds into that List<Entity> and they will all get checked and removed.

Thanks man, but i have just solved the problem in the easy way, used native instead of vehicle.exists(), this is the code:

If Native.Function.Call(Of Boolean)(Native.Hash.IS_ENTITY_DEAD, heli_6_1) = True Then
                If  Native.Function.Call(Of Boolean)(Native.Hash.DOES_ENTITY_EXIST, heli_6_1) = true Then
                ped_heli_6_1_1.MarkAsNoLongerNeeded()
                    ped_heli_6_1_2.MarkAsNoLongerNeeded()
                    ped_heli_6_1_3.MarkAsNoLongerNeeded()
                ped_heli_6_1_4.MarkAsNoLongerNeeded()
               heli_6_1.MarkAsNoLongerNeeded()
                End If
                heli_6_1 = World.CreateVehicle("Annihilator", Game.Player.Character.Position + new Vector3(0, 0, 100.0F) + Game.Player.Character.ForwardVector * 400.0F)
                 If Game.Player.Character.IsInVehicle = True Then
                heli_6_1.Heading = Game.Player.Character.CurrentVehicle.Heading - 180
                End If

If I have any new questions hope you can give some answers, really appreciate it, thanks=)

Link to comment
Share on other sites

Well it's good that you found a solution that you feel is simple but if I look back through your comments, I think it is going to be even more complicated for you. If you want more than one heli at a time, you're going to need this code for each one. If you also spawn multiple police cars, you're going to need this code for each one. What if you wanted to spawn a heli with only two people in it? I have written mods that handle over a hundred cars/helicopters/buses, can you imagine how bad it would be if you had to have this code for each individual vehicle?

 

There are some useful natives like GET_VEHICLE_NUMBER_OF_PASSENGERS, IS_VEHICLE_SEAT_FREE and GET_PED_IN_VEHICLE_SEAT, which all make it easier to see exactly how many people are in the vehicle and where they are sitting. When I am writing a mod, I tend to find things like that and then add them in a comment section at the bottom of the script file as a reminder.

 

One other thing you do need to be careful of, is you're still checking if the entity is dead, before you are checking if it exists... I would advise checking if it exists first, because if it isn't for any reason, checking if it is dead will cause an exception. You're also marking all the peds as no longer needed, without checking if they exist either. They might have been shot, they might have fallen out of the helicopter, they might not be where you expect them to be. Think of it like real-life... if you wanted to check if someone was dead, you'd have to see if there was a someone there first to check.

Edited by LeeC22
Link to comment
Share on other sites

SayagoHren
7 hours ago, LeeC22 said:

Well it's good that you found a solution that you feel is simple but if I look back through your comments, I think it is going to be even more complicated for you. If you want more than one heli at a time, you're going to need this code for each one. If you also spawn multiple police cars, you're going to need this code for each one. What if you wanted to spawn a heli with only two people in it? I have written mods that handle over a hundred cars/helicopters/buses, can you imagine how bad it would be if you had to have this code for each individual vehicle?

 

There are some useful natives like GET_VEHICLE_NUMBER_OF_PASSENGERS, IS_VEHICLE_SEAT_FREE and GET_PED_IN_VEHICLE_SEAT, which all make it easier to see exactly how many people are in the vehicle and where they are sitting. When I am writing a mod, I tend to find things like that and then add them in a comment section at the bottom of the script file as a reminder.

 

One other thing you do need to be careful of, is you're still checking if the entity is dead, before you are checking if it exists... I would advise checking if it exists first, because if it isn't for any reason, checking if it is dead will cause an exception. You're also marking all the peds as no longer needed, without checking if they exist either. They might have been shot, they might have fallen out of the helicopter, they might not be where you expect them to be. Think of it like real-life... if you wanted to check if someone was dead, you'd have to see if there was a someone there first to check.

I fully agree with you that it is neccesary to make code more optimized and flexible and i will also pay attention to this, simply now my purpose is to write anything that will basicly simply work :D if I manage to do this i will be lokking for code optimization. I will fix the thing you said about chencking if exists firstly. By the way  I have as new question, when i Spawn extra police cars sometimes they spawn without active siren and behave as simple peds althouth I made them as cops and forced siren to be active:

 Case 3
                v = World.CreateVehicle("Firetruk", Game.Player.Character.Position + Game.Player.Character.ForwardVector * 250.0F)
                v.PlaceOnNextStreet()
                If Game.Player.Character.IsInVehicle = True Then
                v.Heading = Game.Player.Character.CurrentVehicle.Heading - 180
                End If
                v.SirenActive = true
                v.MarkAsNoLongerNeeded()
                                                   
                    s1 = v.CreatePedOnSeat(VehicleSeat.Driver, "s_m_y_fireman_01")
                    weapselect()
                    s1.Weapons.Give(weaphash, 999, True, True)

                    pedselect()
                    s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, "s_m_y_fireman_01")
                    weapselect()
                    s2.Weapons.Give(weaphash, 999, True, True)
                    Native.Function.Call(Native.Hash.SET_PED_AS_COP, s1, true)
                    Native.Function.Call(Native.Hash.SET_PED_AS_COP, s2, true)                   

                s1.MarkAsNoLongerNeeded()
                s2.MarkAsNoLongerNeeded()

I guess that in can maybe be fixed by giving task vehicle chase and  task combat ped (not tried yet) but do not understand why in most cases it works without these functions.

Edited by SayagoHren
Link to comment
Share on other sites

Yeah, sorry about my last post. Too much code stress puts me into an overly-analytical mood and adding alcohol into the mix just makes it worse. I would normally tell people to start simple, get it working, then expand it and I broke my own rules of logic... sorry.

 

Not sure what's causing the problem with the peds and sirens though. There is a native GET_PED_TYPE, you could maybe use that on your peds after you have created them, to check if they are really cops. I don't know if the game tries to do anything with peds that are spawned as cops, this is a part of modding I have never dealt with I am afraid.

Link to comment
Share on other sites

SayagoHren

After spending hours or searching variants of correct spawning and chasing player by vehicles i partially succeed in it. Maybe this information will be useful for somebody:

If Game.Player.Character.IsInVehicle = False Then
Native.Function.Call(Native.Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, s1, v, Game.Player.Character.Position.X, Game.Player.Character.Position.Y, Game.Player.Character.Position.Z, 100f, 4 + 8 + 16 + 32 + 262144, 5f) // s1-driver, v-vehicle, 100 f - speed of vehicle,  4+8 etc - driving style, taken from random mod searched in github, 5f -distance betwwen player and chaser
                    Else
                    Native.Function.Call(Native.Hash.TASK_VEHICLE_CHASE, s1, Game.Player.Character) 
                    Native.Function.Call(Native.Hash.SET_TASK_VEHICLE_CHASE_BEHAVIOR_FLAG, s1, 1, true)

It is important to make the task depending on the current player state -in vehicle or not. So why the problem is solved partially? Because i do not have success in doing such kind of trick with vehicle FireTruk - when player on foot vehicle comes and stuck (peds in vehicle do nothing just staying inside the car) when player in vehicle Firemen just go through you away (not stopping or chasing). Seems to me that this vehicle is hardly scripted at low level gaming process. 

 

I have a new question, is it possible to spawn car at a certain distance in front of player at current road (where the player is now) On next sreet method can spawn cars at neighbor roads, this is not good for cars that are chasing player, especcially out of city where are many pits trees and other things that disturb cars chasing player. It seems to me that in this topic guy had the same question but reading this tread did not give me understanding about this question.

Edited by SayagoHren
Link to comment
Share on other sites

Peds have something called a relationship group and that decides how each sets of peds behave to others. Like normal peds don't bother with Trevor, but if you go anywhere near The Lost MC, they will attack Trevor. Maybe when you spawn the peds in the firetruck, you need to set their relationship group for them to want to attack the player. This is the list of relation group types:

Relationship types:
0 = Companion
1 = Respect
2 = Like
3 = Neutral
4 = Dislike
5 = Hate
255 = Pedestrians

When you set it, you have to do it twice, once for the player to the ped and once for the ped to the player. You can even create custom relationship groups and assign specific peds to it. ScriptHookVDotNet has functions for setting them up and there are natives like SET_RELATIONSHIP_BETWEEN_GROUPS. But your first check might be to use this native GET_RELATIONSHIP_BETWEEN_PEDS and use it on the player and a spawned fireman, see what that is set to. I think SHVDN has the hashes for each group built in but if not, this is the list I have:

 

PLAYER = 0x6F0783F5
CIVMALE = 0x02B8FA80
CIVFEMALE = 0x47033600
COP = 0xA49E591C
SECURITY_GUARD = 0xF50B51B7
PRIVATE_SECURITY = 0xA882EB57
FIREMAN = 0xFC2CA767
GANG_1 = 0x4325F88A
GANG_2 = 0x11DE95FC
GANG_9 = 0x8DC30DC3
GANG_10 = 0x0DBF2731
AMBIENT_GANG_LOST = 0x90C7DA60
AMBIENT_GANG_MEXICAN = 0x11A9A7E3
AMBIENT_GANG_FAMILY = 0x45897C40
AMBIENT_GANG_BALLAS = 0xC26D562A
AMBIENT_GANG_MARABUNTE = 0x7972FFBD
AMBIENT_GANG_CULT = 0x783E3868
AMBIENT_GANG_SALVA = 0x936E7EFB
AMBIENT_GANG_WEICHENG = 0x6A3B9F86
AMBIENT_GANG_HILLBILLY = 0xB3598E9C
DEALER = 0x8296713E
HATES_PLAYER = 0x84DCFAAD
HEN = 0xC01035F9
WILD_ANIMAL = 0x7BEA6617
SHARK = 0x229503C8
COUGAR = 0xCE133D78N
O_RELATIONSHIP = 0xFADE4843
SPECIAL = 0xD9D08749
MISSION2 = 0x80401068
MISSION3 = 0x49292237
MISSION4 = 0x5B4DC680
MISSION5 = 0x270A5DFA
MISSION6 = 0x392C823E
MISSION7 = 0x024F9485
MISSION8 = 0x14CAB97B
ARMY = 0xE3D976F3
GUARD_DOG = 0x522B964A
AGGRESSIVE_INVESTIGATE = 0xEB47D4E0
MEDIC = 0xB0423AA0
PRISONER = 0x7EA26372D
OMESTIC_ANIMAL = 0x72F30F6E
DEER = 0x31E50E10

 

As for your traffic spawn, you could possibly use your speed to predict a position ahead of your vehicle, then use something like GET_NTH_CLOSEST_VEHICLE_NODE_WITH_HEADING to get a position. If you then used GET_STREET_NAME_AT_COORD on your current position and the one from that native, if they matched, you would know they are on the same street. Vehicle nodes can be a tricky thing though and you can sometimes get back positions that don't seem to make sense. Be prepared for lots of experimentation and frustration.

 

One thing I would suggest, is get these https://www.gta5-mods.com/tools/v1290-decompiled-scripts-rootcause

 

Those are the scripts that the game uses and what they can do, is help to you understand how certain natives are used and which natives they are used with. They're an incredibly helpful resource, I would be lost without them.

Edited by LeeC22
Link to comment
Share on other sites

SayagoHren

Tried your advice about peds in FireTruck but does not help. Put just another DLC vehicle and everything is fine 😃  Hove some two new questions:

 

1) How it is possible to detect that police started to loose player (stars begin to flash)? Looked through the natives, tried to use GET_WANTED_LEVEL_RADIUS (shows all the time the same value), GET_PLAYER_WANTED_CENTRE_POSITION (always shows 0,0,0), GET_WANTED_LEVEL_THRESHOLD (shows radius of search zone for each star installed in dispatch.meta),  ARE_PLAYER_FLASHING_STARS_ABOUT_TO_DROP, ARE_PLAYER_STARS_GREYED_OUT (shows everytime false). Have no more ideas how to detect entrance in "search by police" state

 

2) Wanted to try making animated image, using (pseudocode)
 

Loop starts 
ui.drawtexture (picture1)
delay(1000 ms)
ui.drawtexture (picture2)
Loop ends

Visual basic does not have standard delay function, sleep and script.wait freeze all script. So I decided to write test code:

Private Sub keyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.Y Then
Dim delayer As Integer
delayer = Native.Function.Call(Of Integer)(Native.Hash.GET_GAME_TIMER) + 1000
Do
DoEvents:
Loop Until Native.Function.Call(Of Integer)(Native.Hash.GET_GAME_TIMER) = delayer
End If
End Sub

It just freezes like the loop is endless and then game crashes after 20-30 seconds . So the question is how to make a normal delay in visual basic?

Edited by SayagoHren
Link to comment
Share on other sites

27 minutes ago, SayagoHren said:

1) How it is possible to detect that police started to loose player (stars begin to flash)?

The natives for the stars both change values for me.

    DropWanted = Function.Call<bool>(Hash.ARE_PLAYER_FLASHING_STARS_ABOUT_TO_DROP, Game.Player);
    GreyStars = Function.Call<bool>(Hash.ARE_PLAYER_STARS_GREYED_OUT, Game.Player);

    string wantedString = string.Format("Drop: {0}, Grey: {1}", DropWanted, GreyStars);
    UI.ShowSubtitle(wantedString);

If I use that code, it shows true for GreyStars when they are flashing and it shows true for DropWanted when they are flashing. When the stars are solid white, it shows False for both of them. Are you sure you are using Game.Player and not Game.Player.Character?

 

27 minutes ago, SayagoHren said:

2) Wanted to try making animated image, using (pseudocode)

You already asked about animating images and I answered that in the first comment I made in this thread.

 

As for the delay problem, you can't just stop the code for several seconds, you have to use some kind of timer system. When the timer is active, you have to stop doing other things until the timer has run out, then you can carry on. But you have to decrease the timer every frame, not all in one go. I wrote some code in another thread here about timers and delays https://gtaforums.com/topic/953788-c-wait-seems-to-delay-whole-script/?do=findComment&comment=1071195815

 

You might find some info in there that will help. All my code is in C# though as I said previously, you'll need to convert it into VB. It's not complex code though, so it should convert okay.

Edited by LeeC22
Link to comment
Share on other sites

SayagoHren

Thanks man, so easy solution (about grey stars). And I thought that it is necessary to use character🙂  It seems to me that almost all the things I wanted to know at this moment I learned. Remains the issue about spawning cars on current road, if I succeed in it, will place the working code here.

Link to comment
Share on other sites

SayagoHren

Tried to call native  GET_CLOSEST_VEHICLE_NODE but did not succeed it it. The game just gives a crash. Also I do not understand why native db says that this native is bool althouth it gives Vector 3 coords. Searching code with this native in github and on this forum did not help me because there is no examples of using this in visual basic (how to use syntax correctly). Hope you can help me to figure it out. The purpose is to get coordinates in variable car_spawn_point to spawn car on nearest asphalt road in distance 200F in front of player.

 

Private car_spawn_point As Vector3 
Native.Function.Call(Native.Hash.GET_CLOSEST_VEHICLE_NODE, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.X, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.Y, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.Z, car_spawn_point, 0, 3.0, 2.5)

Also tried 

Native.Function.Call(Of Boolean)(Native.Hash.GET_CLOSEST_VEHICLE_NODE, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.X, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.Y, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.Z, car_spawn_point, 0, 3.0, 2.5) //as bool

Native.Function.Call(Of Vector3)(Native.Hash.GET_CLOSEST_VEHICLE_NODE, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.X, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.Y, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 200.0F.Z, car_spawn_point, 0, 3.0, 2.5) //as Vector3



 

Link to comment
Share on other sites

Jitnaught
Private Function GetClosestVehicleNode(ByVal pos As Vector3, ByVal nodeType As Integer) As Vector3
    Dim outPosition As OutputArgument = New OutputArgument()
    GTA.Native.Function.Call(Of Boolean)(Hash.GET_CLOSEST_VEHICLE_NODE, pos.X, pos.Y, pos.Z, outPosition, nodeType, 3.0F, 0F)
    Return outPosition.GetResult(Of Vector3)()
End Function

I used a converter to convert from C# to VB.NET, so no idea if this function will work or not.

Link to comment
Share on other sites

SayagoHren
3 hours ago, Jitnaught said:
Private Function GetClosestVehicleNode(ByVal pos As Vector3, ByVal nodeType As Integer) As Vector3
    Dim outPosition As OutputArgument = New OutputArgument()
    GTA.Native.Function.Call(Of Boolean)(Hash.GET_CLOSEST_VEHICLE_NODE, pos.X, pos.Y, pos.Z, outPosition, nodeType, 3.0F, 0F)
    Return outPosition.GetResult(Of Vector3)()
End Function

I used a converter to convert from C# to VB.NET, so no idea if this function will work or not.

Just crashes the game,  also tried like this

Private Function GetClosestVehicleNode(ByVal pos As Vector3, ByVal nodeType As Integer) As Vector3
    Dim outPosition As Vector3
    GTA.Native.Function.Call(Of Boolean)(Hash.GET_CLOSEST_VEHICLE_NODE, pos.X, pos.Y, pos.Z, outPosition, nodeType, 3.0F, 0F)
    Return outPosition
End Function

The same result.

Is it possible to make custom library with this function writen in c# like scripthook, just with changes to search only asphalt rode coords and include this library to script? But it seems to me that it is not the right way, calling native should work directly without any dog-nails.

Link to comment
Share on other sites

Just tried it on my game. Works fine. I tested with nodeType set as 0. The only difference is I wrote it in C#...

private Vector3 GetClosestVehicleNodePos(Vector3 pos, int nodeType)
{
	var outNodePos = new OutputArgument();

	Function.Call<bool>(Hash.GET_CLOSEST_VEHICLE_NODE, pos.X, pos.Y, pos.Z, outNodePos, nodeType, 3f, 0f);

	return outNodePos.GetResult<Vector3>();
}

I also modified the function to use the native properly, but it didn't make any difference for me. Maybe it will for you.

private Vector3 GetClosestVehicleNodePos(Vector3 pos, int nodeType)
{
	var outNodePos = new OutputArgument();

	bool success = Function.Call<bool>(Hash.GET_CLOSEST_VEHICLE_NODE, pos.X, pos.Y, pos.Z, outNodePos, nodeType, 3f, 0f);

	if (success) return outNodePos.GetResult<Vector3>();
	return Vector3.Zero;
}

 

Edited by Jitnaught
Info about nodeType
  • Like 2
Link to comment
Share on other sites

SayagoHren

I made a decision to rewrite code from visual basic to c# because as I understand now almost all mods are writen in it and community works with it. Simply when I decided to start coding  firstly found video tutor using visual basic. Now it seems to me that it is pretty sh*ty. Anyway thanks for help will try to use your code while converting mod. 

 

One more question: how is it possible to spawn ambulance heli? As I understand it is simply the police maverick with ambulance skin, which drops randomly. Which is the way to specify spawning heli in this skin?

Edited by SayagoHren
Link to comment
Share on other sites

In one of my mods, I force it to always be a Police maverick by setting the livery to 0, try setting it to 1.

mySpawnedHeli.Livery = 1;

I think it only has two liveries, so if Police is 0, Ambulance should be 1.

  • Like 2
Link to comment
Share on other sites

SayagoHren
4 hours ago, LeeC22 said:

In one of my mods, I force it to always be a Police maverick by setting the livery to 0, try setting it to 1.

mySpawnedHeli.Livery = 1;

I think it only has two liveries, so if Police is 0, Ambulance should be 1.

As always exact and working answer, thanks=)

Link to comment
Share on other sites

SayagoHren

As I promised working code to spawn vehicle in adjustable distance in front of player on the  road, maybe will be useful for somebody:

Vehicle v_test;
Ped[] peds_test = new Ped[16]; //variable to fill the car automatically with max possible amount of passengers
int ped_index = 0;                  // variables for spawn
int PassengerCapacity;
float spawn_distance;  
Vector3 car_spawn_position;

spawn_distance = 150.0F; 
car_spawn_position = GetClosestVehicleNodePos(Game.Player.Character.Position + Game.Player.Character.ForwardVector * spawn_distance, 0);
v_test = World.CreateVehicle("Ambulance", car_spawn_position);
v_test.PlaceOnGround();
if (Game.Player.Character.IsInVehicle() ) 
{
    v_test.Heading = Game.Player.Character.CurrentVehicle.Heading - 180;
} 
else
{
    v_test.Heading = Game.Player.Character.Heading - 180;
}
v_test.EngineRunning = true;
v_test.SirenActive = true;
PassengerCapacity = Function.Call<int>(Hash.GET_VEHICLE_MAX_NUMBER_OF_PASSENGERS, v_test);
                    for (int i = -1; i < PassengerCapacity; i++)
            {   
               if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter
               peds_test[ped_index] = v_test.CreatePedOnSeat((VehicleSeat)i, "s_m_y_swat_01");
            }
            peds_test[0].Task.VehicleChase(Game.Player.Character);
            peds_test[0].AlwaysKeepTask = true;
            ped_index = 0;


Sorry for bad tabulation 😃

private Vector3 GetClosestVehicleNodePos(Vector3 pos, int nodeType)
{
	var outNodePos = new OutputArgument();

	Function.Call<bool>(Hash.GET_CLOSEST_VEHICLE_NODE, pos.X, pos.Y, pos.Z, outNodePos, nodeType, 3f, 0f);

	return outNodePos.GetResult<Vector3>();
}
Edited by SayagoHren
Link to comment
Share on other sites

  • 3 weeks later...
SayagoHren

Hi everybody, did not think that I will have a complicated question, not linked with scripting directly, but here it is.  In my mod 25 cars spawn in one moment (at different distance) and after this the game just crashes without any error (only rockstar launcher error). I can not beleive that in 2020 year the game can not be able to spawn such amount of cars, but maybe I am not right? I also tried installing gameconfig for limitless vehucles and heap size adjusted, these things did not help. Possibly it is necessary to spawn such amount or cars in script in a specific way?

Link to comment
Share on other sites

If I ever have to spawn more than a single vehicle, I will only ever spawn them one per frame. If ever you teleport somewhere, you will notice that the traffic builds up gradually over a period of time, this is because it doesn't just spawn everything at once.

 

So create something like this:

public struct CarSpawnConfig
{
    int ModelHash;
    Vector3 SpawnPosition;
    float SpawnHeading;
}

Then have a collection and an index

private List<CarSpawnConfig> CarSpawns;
private int CarSpawnIndex;

Then have a function that spawns a car from the CarSpawns collection using the CarSpawnIndex. Once that car has been spawned, increment the index and then next time round, spawn the next car. Keep doing that until CarSpawnIndex== CarSpawns.Count, at which point all your cars will have spawned.

 

Even if each car takes 2 or 3 frames to spawn while you are waiting for models to load into memory, it will still be less than 2 seconds at 60fps... which isn't a long time.

Edited by LeeC22
Link to comment
Share on other sites

SayagoHren

Honestly do not understand how I can use this method because in my mod cars respawn each second if destroyed and all peds in it are dead, so the spawn is not "static". Tthere is no dependence in spawning cars  between each other (if second car spawned third car should also be spawned).

My current code is like this:

 

if ( WANTED_LEVEL_GUI.extra_wantedlevel == 14 & !CheckPedsAreAlive(ref peds_14_1) & Function.Call<bool>(Hash.IS_ENTITY_DEAD, v_14_1)) 
         {
             SpawnStandardEmergencyCar( ref v_14_1, ref peds_14_1, 150.0F);
         }
  
  if ( WANTED_LEVEL_GUI.extra_wantedlevel == 14  & !CheckPedsAreAlive(ref peds_14_6) & Function.Call<bool>(Hash.IS_ENTITY_DEAD, v_14_6)) 
         { 
             SpawnRandomFBICar(ref v_14_6, ref peds_14_6, 200.0F);
         }
  
  if ( WANTED_LEVEL_GUI.extra_wantedlevel == 14 & !CheckPedsAreAlive(ref peds_14_16) & Function.Call<bool>(Hash.IS_ENTITY_DEAD, v_14_16)) 
         { 
             SpawnRandomHeavyEmergencyCar(ref v_14_16, ref peds_14_16, 300.0F);
         }
  
  if ( WANTED_LEVEL_GUI.extra_wantedlevel == 14 & !CheckPedsAreAlive(ref peds_14_23) & Function.Call<bool>(Hash.IS_ENTITY_DEAD, v_14_23)) 
      { 
           SpawnRandomMilitaryEmergencyCar(ref v_14_23, ref peds_14_23, 370.0F);
      }
  

Maybe it is possible to insert a  10-50 ms delay in each spawn command by using wait function?

Edited by SayagoHren
Link to comment
Share on other sites

52 minutes ago, SayagoHren said:

in my mod cars respawn each second if destroyed and all peds in it are dead, so the spawn is not "static".

That is not what your post said, you said:

20 hours ago, SayagoHren said:

In my mod 25 cars spawn in one moment

and

20 hours ago, SayagoHren said:

Possibly it is necessary to spawn such amount or cars in script in a specific way?

So you asked for a solution to spawn 25 cars instantly... that's a "static" spawn and that's what the solution solves.

 

I don't understand how people are expected to answer questions that are always changing... If you have a specific problem, provide all the details, or people will get frustrated and stop answering.

Link to comment
Share on other sites

SayagoHren

I said so because the first spawn happens to all cars in one moment, then cars respawn. I saw the solution with using list, which solved this question, but I could not predict which kind of solution can be proposed and that it can not work with respawning so that is why i did not say about respawning cars. Anyway, thanks for the help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.