Log in to reply
 

Ped Spaw - Help please



  • I am making a hitman script with random ped spawns. I have done that BUT, the peds spawn in the air, in the water, on top of buildings, etc. They all spawn on shitty positions where peds normally wouldn't be. Could someone tell me how I can fix this problem?

    • ped = GTA.World.CreatePed("g_m_y_ballaorig_01", getRandomPos()); ped.AddBlip(); ped.Task.WanderAround();
      ^ is my current ped creation line.


  • This post is deleted!




  • @Jonizz
    Try using World.GetSafeCoordForPed(). That was the only one I could get to work.

    look:

    using GTA;
    using GTA.Math;
    
    namespace Helideck_Signaling
    {
        class Class2 : Script
        {
            private Ped _ped;
            private Blip _blip;
    
            public Class2()
            {
                Tick += (o, e) =>
                {
                    if (_ped != null &&
                        _blip != null)
                    {
                        _blip.Position =
                            _ped.Position;
                    }
                };
    
                Aborted += (o, e) =>
                {
                    if (_ped != null)
                        _ped.Delete();
    
                    if (_blip != null)
                        _blip.Delete();
                };
    
                KeyUp += (o, e) =>
                {
                    if (e.Shift && e.KeyCode is System.Windows.Forms.Keys.U)
                    {
                        if (_ped == null)
                        {
                            var model =
                                "g_m_y_ballaorig_01";
    
                            var position =
                                GetRandomPosition();
    
                            _ped =
                                World
                                    .CreatePed(model,
                                               position);
    
                            _ped.Task
                                .WanderAround();
    
                            _blip =
                                World
                                    .CreateBlip(_ped.Position);
    
                            _blip.Name =
                                model;
    
                            _blip.Scale =
                                0.60f;
                        }
                    }
                };
            }
    
            private Vector3 GetRandomPosition()
            {
                var randomXYZ =
                    new Vector3(Game.Player.Character.Position.X,
                                Game.Player.Character.Position.Y,
                                Game.Player.Character.Position.Z).Around(50f);
    
                return World
                        .GetSafeCoordForPed(randomXYZ);
            }
        }
    }
    
    
    
    

    alt text



  • @Niziul said in Ped Spaw - Help please:

    World.GetSafeCoordForPed()

    Nice.
    Never saw a native function for that, although for my purposes I just spawn based on player position.

    Edit:
    GET_SAFE_COORD_FOR_PED(float x, float y, float z, BOOL onGround, Vector3* outPosition, int flags) // 0xB61C8E878A4199CA 0xB370270A b323

    Flags are:
    1 = 1 = B02_IsFootpath
    2 = 4 = !B15_InteractionUnk
    4 = 0x20 = !B14_IsInterior
    8 = 0x40 = !B07_IsWater
    16 = 0x200 = B17_IsFlatGround
    When onGround == true outPosition is a position located on the nearest pavement.

    When a safe coord could not be found the result of a function is false and outPosition == Vector3.Zero.

    In the scripts these flags are used: 0, 14, 12, 16, 20, 21, 28. 0 is most commonly used, then 16.

    16 works for me, 0 crashed the script.



  • @JohnFromGWN

    the real problem is that it is very problematic, because if there is no safe coordinate to create the ped, it ends up returning a vector with position zero. and that is very annoying.



  • @Jonizz @Niziul I think the whole concept of random spawning is completely flawed in the first place, without a reference point.

    It should be randomized with respect to the player. Hell, you could have the player at the Northern tip of San Andreas and the spawn of the ped at the Southern tip. How would that be useful?

    Imagine if the ped spawns in another game? Just kidding.



  • I think I can come up with something:

    using GTA;
    using GTA.Math;
    
    namespace Helideck_Signaling
    {
        class Class2 : Script
        {
            private Ped _ped;
            private Blip _blip;
    
            private Vector3 _position;
    
            public Class2()
            {
                var isCompatiblePosition =
                    false;
    
                _position =
                    GetRandomPosition();
    
                Tick += (o, e) =>
                {
                    switch (isCompatiblePosition)
                    {
                        case true:
                            {
                                CreateThePedestrianInACompatiblePosition();
                            }
                            break;
                        case false:
                            {
                                if (_position != new Vector3(0f, 0f, 0f))
                                {
                                    isCompatiblePosition =
                                        true;
    
                                    return;
                                }
    
                                _position =
                                    GetRandomPosition();
                            }
                            break;
                    }
    
                    if (_ped != null &&
                        _blip != null)
                    {
                        _blip.Position =
                            _ped.Position;
                    }
                };
    
                Aborted += (o, e) =>
                {
                    if (_ped != null)
                        _ped.Delete();
    
                    if (_blip != null)
                        _blip.Delete();
                };
    
                KeyUp += (o, e) =>
                {
                    if (e.Shift && e.KeyCode is System.Windows.Forms.Keys.U) { }
                };
            }
    
            private void CreateThePedestrianInACompatiblePosition()
            {
                if (_ped == null)
                {
                    var model =
                        "g_m_y_ballaorig_01";
    
                    _ped =
                        World
                            .CreatePed(model,
                                       _position);
    
                    _ped.Task
                        .WanderAround();
    
                    _blip =
                        World
                            .CreateBlip(_ped.Position);
    
                    _blip.Name =
                        model;
    
                    _blip.Scale =
                        0.60f;
                }
            }
    
            private Vector3 GetRandomPosition()
            {
                var randomXYZ =
                    new Vector3(Game.Player.Character.Position.X,
                                Game.Player.Character.Position.Y,
                                Game.Player.Character.Position.Z).Around(250f);
    
                var safeCoordForPed =
                    World.GetSafeCoordForPed(new Vector2(randomXYZ.X, randomXYZ.Y), true, 16);
    
    
                return safeCoordForPed;
            }
        }
    }
    
    


  • @JohnFromGWN Yes, and I think "GetSafeCoordForPed" only works near the player.



  • @Jonizz
    A tip for you to generate that feeling of randomness in your missions. First create a blip in a random place on the map, like this:
    alt text
    "like the location of the last sighting of the target". And from that you create the "npc", that the player has to exercise, in that area.



  • Honestly, this business of changing accounts is getting on my nerves. Just for the record the last post is mine ("niziul").



  • @AlexSam How do we know it's actually you. And how do you know this is me?



  • @AlexSam but what if it is a roof or in the women's washroom? I'll repeat myself, why not just keep it a reasonable and safe distance relative to the player ped? The game itself, for memory reasons, doesn't spawn assets randomly where they can't be seen.



  • @JohnFromGWN Exactly. The truth is that it can be done in infinite ways.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.