Jump to content

Hayden Almeida

Members
  • Posts

    9
  • Joined

  • Last visited

  • Days Won

    1

Hayden Almeida last won the day on January 21 2021

Hayden Almeida had the most liked content!

Personal Information

  • Country
    Brazil
  • Gender
    Male

Recent Profile Visitors

1,224 profile views

Hayden Almeida's Achievements

Feller

Feller (1/10)

2

Reputation

  1. Today i will try to teach how to spawn your first ped in RedM with C#. first you need to create a "ENUM" to make your list of your peds (you can see they here: https://www.mod-rdr.com/wiki/peds/ ) public enum PedHash : uint { AcHorseAndalusianDarkbay = 0xE57FC660, AcHorseAndalusianRosegray = 0x2C80A080 } ATENTION! If you are using other Class to create this enum, you put "public enum". If this enum was created in the same class, you use "private enum". Second lets create our function to spawn and load the ped: public static async Task<bool> LoadModel(int hash) { if (Function.Call<bool>(Hash.IS_MODEL_VALID, hash)) { Function.Call((Hash)0xFA28FE3A6246FC30, hash); while (!Function.Call<bool>(Hash.HAS_MODEL_LOADED, hash)) { Debug.WriteLine($"Esperando o modelo {hash} carregar!"); await BaseScript.Delay(200); } Debug.WriteLine("Modelo carregado!"); return true; } else { Debug.WriteLine($"Model {hash} nao e valido!"); return false; } } public static async Task<bool> LoadPed(PedHash ped) { if (!await LoadModel((int)ped)) return true; else return false; } This function ^ will load the ped. Before creating the main function to spawn the ped, we need to create other function to "randomize" the outfit of the ped. Without this the ped will not spawn! So i only created in a "beautiful" name 😄 public static void SetRandomOutfitVariation(int ped) { Function.Call((Hash)0x283978A15512B2FE, ped, true); } Now lets create the main function to spawn de ped: public static async Task<int> CriarPed(PedHash ped, float posx, float posy, float posz, float heading) { var task = LoadPed(ped); // this will call the function we already created before bool result = await task; // this line will only proceed if we have something in return from "LoadPed" int ped_ = API.CreatePed((uint)ped, posx, posy, posz, heading, true, true, true, true); Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, ped_, true, true); // setting this true for this ped not "despawn" SetRandomOutfitVariation(ped_); // every ped to spawn we need to random his outfit or variation... API.SetModelAsNoLongerNeeded((uint)ped); // clear the model in memory return ped_; } Now with our functions created, we can now create our command to spawn any ped that are inside ENUM. The command will work this way: /createped [ped name] Lets go to our main CLIENT file, inside our Main public: public Main() { API.RegisterCommand("createped", new Action<int, List<object>, string>((src, argumentos, raw) => { CMD_CriarPed(argumentos); // this is the function we will excute }), false); } This is the function our command will execute: private async void CMD_CriarPed(List<object> argumentos) { playerid = API.PlayerPedId(); var argList = argumentos.Select(o => o.ToString()).ToList(); if (argList.Any() && Enum.TryParse(argList[0], true, out PedHash pedi)) // this line will compare if the param we write, exists inside ENUM. { // argList[0] is to get the first argumento we wrote. // TIP: // if we want another parameter for our command we can call this: // int number = Convert.ToInt32(argumentos[1]); // Now our command can use: /createped [ped name] [number] // and so on... Vector3 pos = API.GetEntityCoords(playerid, false, false); Vector3 forwardpos = API.GetEntityForwardVector((uint)playerid); float hdg = API.GetEntityHeading(playerid); pos += (forwardpos * 5); var ped_criado = CriarPed(pedi, pos.X, pos.Y, pos.Z + 2.0F, hdg); int result = await ped_criado; Debug.WriteLine($"Ped ID created={result}"); } } Hope this will help begginers to program in RedM! Cya 🧲
  2. public static void RemovePedWeapon(int pedid, WeaponHash weapon) { Function.Call(Hash.REMOVE_WEAPON_FROM_PED, pedid, weapon, true); // USE: RemovePedWeapon(playerid, WeaponHash.Bow); } 🧲
  3. Example in C#: public static void GivePlayerWeapon(int playerid, WeaponHash weapon, int ammo) { if(Function.Call<bool>((Hash)0x8DECB02F88F428BC, playerid, (uint)weapon, 0, true)) // Has ped Got Weapon API.SetPedAmmo(playerid, (uint)weapon, ammo); // will give only ammo else Function.Call((Hash)0x5E3BDDBCB83F3D84, playerid, (uint)weapon, ammo, false, true, 1, false, 0.5F, 1.0F, false, 0); }
  4. public static bool HasPedGotWeapon(int ped, WeaponHash weapon) { return Function.Call<bool>((Hash)0x8DECB02F88F428BC, ped, (uint)weapon, 0, true); } 🧲
  5. Example in C#: public static uint GetCurrentPedWeapon(int ped) { // Retorna um numero decimal da arma que o ped está na mão. // Returns a decimal number of the weapon the ped is in hand. uint weapon = 0; API.GetCurrentPedWeapon(ped, ref weapon, false, 0, false); return weapon; }
  6. Example in C#: 🙂 // ENTER button on keyboard if (API.IsControlJustReleased(0, 0x2CD5343E)) { // Do something } Some links: https://github.com/summeryukata/redm-simple-trainer/blob/master/Native/Controls.cs#L106 https://github.com/femga/rdr3_discoveries/tree/master/Controls https://pastebin.com/WA2mfvA0
  7. Hayden Almeida

    TASK_PLAY_ANIM

    Example Use in C#: public static async void PlayClipset(string dict, string anim, int flag, int duration = -1) { // PlayClipset("mech_loco_m@generic@reaction@handsup@unarmed@tough", "loop", 31); // https://rdr2.mooshe.tv/animations/ API.RequestAnimDict(dict); while (!API.HasAnimDictLoaded(dict)) { await BaseScript.Delay(100); } if (API.IsEntityPlayingAnim(API.PlayerPedId(), dict, anim, 3)) API.ClearPedSecondaryTask(API.PlayerPedId()); else Function.Call(Hash.TASK_PLAY_ANIM, API.PlayerPedId(), dict, anim, 1.0f, 8.0f, duration, flag, 0, true, 0, false, 0, false); }
  8. How to stop scenario correctly? Some scenarios create a prop. How to delete this prop?
  9. This function already have in the API: API.NetworkClockTimeOverride(int ,int,int, int, bool); Example use: API.NetworkClockTimeOverride(int hour ,int minute,int second, int ms transition time, bool FreezeTime); API.NetworkClockTimeOverride(14,30,0, 10000, false); // This will set the time to 2:30 PM and the transition will occur in 10 seconds and the time will not freeze
×
×
  • Create New...