Log in to reply
 

[C#] How to change ped model?



  • Hi,
    I am trying to make a script where I need to intimidate a shop keeper for a code but I don't know how I can delete the current shopkeeper and replace it for one I manually put in for my intimidation part to work. Does anyone know how I can delete and specific ped and replace it with another model that I have in my code.

    Any would would be great.

    Thanks.



  • @Kieran_S Simple as Ped1.Delete, where Ped 1 is your variable name.
    AFAIK you need to spawn all characters (except player) in a script, so you will need to script your shopkeeper spawn, delete it, and then replace it.
    To replace it you spawn a new ped.
    To spawn with absolute:
    World.CreatePed(PedHash.Michael, New Vector3(-1279, 315, 65))
    and there are dozens of ways to spawn relative to the player
    World.CreatePed(PedHash.Michael, Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0)))
    I code in vb.net but I think only the variable declarations are different and ofc no semicolon to terminate statement in vb.net
    For vb, Dim Ped 1 as Ped
    For C#, Var Ped1 =



  • @JohnFromGWN Ah OK, I know how I can use a ped that I have spawned but I wondered how I can delete a ped spawned by the game in this case a shopkeeper and then replace it with one that I can spawn in its place.



  • @Kieran_S

    I don't know how you would identify a ped spawned by the game. I would love to know how to do that but it's beyond my beginner expertise.
    Would love to know the same for props as well. How to identify a prop that is already in place. Certainly not obvious and I've researched and posted this without success.
    Some scripts work by identifying the closest ped to the player for example, so that might be the solution.

    I spawn and manipulate - works fine.
    So back to Ped1.Delete() (or whatever your variable name is)

    also a good idea for memory

    Ped1.MarkAsNoLongerNeeded()

    Don't know if this would help you? Seems to use the "closest ped" approach.

    https://forums.gta5-mods.com/topic/22708/script-ped-remover



  • @JohnFromGWN OK, thanks for the feedback. I will have a look at this link now and see if I can find anything lol.



  • @Kieran_S
    Here is the code,, should work for you. Author is
    Jitnaught

    using GTA;
    using System.Collections.Generic;
    using System.Windows.Forms;

    namespace PedRemover
    {
    public class PedRemover : Script
    {
    bool deletePed, removeTargetedPed, showSubtitles;
    Keys removalKey;

        string pedCalled;
    
        public PedRemover()
        {
            deletePed = Settings.GetValue("SETTINGS", "DELETE_PED", true);
            removeTargetedPed = Settings.GetValue("SETTINGS", "TARGETED_PED", true);
            showSubtitles = Settings.GetValue("SETTINGS", "SHOW_SUBTITLES", true);
            removalKey = Settings.GetValue("SETTINGS", "REMOVE_KEY", Keys.X);
    
            pedCalled = (removeTargetedPed ? "Targeted ped" : "Closest ped");
    
            KeyDown += PedRemover_KeyDown;
        }
    
        private Ped GetClosestPedToMe(float radius = 100f)
        {
            Ped me = Game.Player.Character;
    
            List<Ped> allPeds = new List<Ped>(World.GetAllPeds());
    
            //only run if greater than 1, because if equals 1 that means the player is the only available ped
            if (allPeds.Count > 1)
            {
                //don't allow player to be returned as closest ped
                allPeds.Remove(me);
    
                return World.GetClosest(me.Position, allPeds.ToArray());
            }
    
            return null;
        }
    
        private void PedRemover_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == removalKey)
            {
                Ped removePed = null;
    
                if (removeTargetedPed)
                {
                    Entity target = Game.Player.GetTargetedEntity();
    
                    if (target != null && target.Exists() && target is Ped)
                    {
                        removePed = (Ped)target;
                    }
                }
                else
                {
                    Ped closestPed = GetClosestPedToMe();
    
                    if (closestPed != null && closestPed.Exists())
                    {
                        removePed = closestPed;
                    }
                }
    
                if (removePed != null)
                {
                    if (deletePed)
                    {
                        removePed.Delete();
                        if (showSubtitles) UI.ShowSubtitle(pedCalled + " deleted");
                    }
                    else
                    {
                        removePed.MarkAsNoLongerNeeded();
                        if (showSubtitles) UI.ShowSubtitle(pedCalled + " marked no longer needed");
                    }
                }
                else if (showSubtitles) UI.ShowSubtitle("No ped found");
            }
        }
    }
    

    }



  • @JohnFromGWN Thanks a tonne. I'll have a look at that now.



  • @Kieran_S Hmmm. Not working for me. No error, just returns "No ped found" from the last statement in the code.



  • @JohnFromGWN Yes, after trying it myself this morning I has the same issue. I think I have found an alternative way. Just hope it works properly.


Log in to reply
 

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