WesternGamer 48 Posted September 1, 2021 Share Posted September 1, 2021 (edited) I am making a mod and I need help spawning a ped. I tried finding the function that spawns peds in Visual Studio 2019 by using Find but was not successful. Can someone tell me what function spawns peds and show me how it is used? Edited September 1, 2021 by WesternGamer Marked post as solved Quote Link to comment Share on other sites More sharing options...
crossed99 43 Posted September 1, 2021 Share Posted September 1, 2021 Ped spawnPed(Hash pedModel, float coordX, float coordY, float coordZ) { STREAMING::REQUEST_MODEL(pedModel, true); while (!STREAMING::HAS_MODEL_LOADED(pedModel)) WAIT(0); Ped pedSpawn = PED::CREATE_PED(pedModel, coordX, coordY, coordZ, 0, 1, 1, 1, 1); PED::_SET_RANDOM_OUTFIT_VARIATION(pedSpawn, 1); ENTITY::PLACE_ENTITY_ON_GROUND_PROPERLY(pedSpawn, 1); ENTITY::FREEZE_ENTITY_POSITION(pedSpawn, 0); STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(pedModel); return pedSpawn; } I do it like this. So you can do something like this for example, this should spawn Charles next to you: Vector3 plCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true, false); Ped myPed = spawnPed(MISC::GET_HASH_KEY("CS_charlessmith"), plCoords.x + 2, plCoords.y, plCoords.z); Quote Link to comment Share on other sites More sharing options...
WesternGamer 48 Posted September 1, 2021 Author Share Posted September 1, 2021 1 hour ago, crossed99 said: Ped spawnPed(Hash pedModel, float coordX, float coordY, float coordZ) { STREAMING::REQUEST_MODEL(pedModel, true); while (!STREAMING::HAS_MODEL_LOADED(pedModel)) WAIT(0); Ped pedSpawn = PED::CREATE_PED(pedModel, coordX, coordY, coordZ, 0, 1, 1, 1, 1); PED::_SET_RANDOM_OUTFIT_VARIATION(pedSpawn, 1); ENTITY::PLACE_ENTITY_ON_GROUND_PROPERLY(pedSpawn, 1); ENTITY::FREEZE_ENTITY_POSITION(pedSpawn, 0); STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(pedModel); return pedSpawn; } I do it like this. So you can do something like this for example, this should spawn Charles next to you: Vector3 plCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true, false); Ped myPed = spawnPed(MISC::GET_HASH_KEY("CS_charlessmith"), plCoords.x + 2, plCoords.y, plCoords.z); @crossed99 Thanks for the info, this will definitely help! Quote Link to comment Share on other sites More sharing options...
SAC 28 Posted December 18, 2021 Share Posted December 18, 2021 On 9/2/2021 at 12:30 AM, crossed99 said: Ped spawnPed(Hash pedModel, float coordX, float coordY, float coordZ) { STREAMING::REQUEST_MODEL(pedModel, true); while (!STREAMING::HAS_MODEL_LOADED(pedModel)) WAIT(0); Ped pedSpawn = PED::CREATE_PED(pedModel, coordX, coordY, coordZ, 0, 1, 1, 1, 1); PED::_SET_RANDOM_OUTFIT_VARIATION(pedSpawn, 1); ENTITY::PLACE_ENTITY_ON_GROUND_PROPERLY(pedSpawn, 1); ENTITY::FREEZE_ENTITY_POSITION(pedSpawn, 0); STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(pedModel); return pedSpawn; } I do it like this. So you can do something like this for example, this should spawn Charles next to you: Vector3 plCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true, false); Ped myPed = spawnPed(MISC::GET_HASH_KEY("CS_charlessmith"), plCoords.x + 2, plCoords.y, plCoords.z); Not working for me, need further instructions Ped spawnPed(Hash pedModel, float coordX, float coordY, float coordZ) { STREAMING::REQUEST_MODEL(pedModel, true); while (!STREAMING::HAS_MODEL_LOADED(pedModel)) WAIT(0); Ped pedSpawn = PED::CREATE_PED(pedModel, coordX, coordY, coordZ, 0, 1, 1, 1, 1); // PED::_SET_RANDOM_OUTFIT_VARIATION(pedSpawn, 1); // ENTITY::PLACE_ENTITY_ON_GROUND_PROPERLY(pedSpawn, 1); // ENTITY::FREEZE_ENTITY_POSITION(pedSpawn, 0); STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(pedModel); return pedSpawn; } // lines due to compiler errors while (true) { if (IsKeyJustUp(VK_F3)) // F3 to spawn a female { Vector3 plCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true, false); Ped myPed = spawnPed((GAMEPLAY::GET_HASH_KEY("sac_female")), plCoords.x + 2, plCoords.y, plCoords.z); DrawText(0, 0, "Spawning NPC"); } Pressing F3, nothing happens (no spawn), besides "spawning NPC" appearing briefly on the screen, signaling F3 keypress was registered Quote My Fallout 4 and Skyrim mods: SAC - LoversLab Link to comment Share on other sites More sharing options...
crossed99 43 Posted December 18, 2021 Share Posted December 18, 2021 (edited) Without the _SET_RANDOM_OUTFIT_VARIATION line they're invisible when they spawn in, so it might be working you just can't see them. You can also try instead: ENTITY::SET_ENTITY_VISIBLE(pedSpawn, true); Or maybe they fall under the ground without the PLACE_ENTITY_ON_GROUND line. But they shouldn't give you compiler errors. What errors are you getting? Edited December 18, 2021 by crossed99 Quote Link to comment Share on other sites More sharing options...
SAC 28 Posted December 19, 2021 Share Posted December 19, 2021 9 hours ago, crossed99 said: Without the _SET_RANDOM_OUTFIT_VARIATION line they're invisible when they spawn in, so it might be working you just can't see them. You can also try instead: ENTITY::SET_ENTITY_VISIBLE(pedSpawn, true); Or maybe they fall under the ground without the PLACE_ENTITY_ON_GROUND line. But they shouldn't give you compiler errors. What errors are you getting? Turns out my natives.h was outdated. SgtJoe helped me update it, now your code works and spawns the peds as intended Thank you Quote My Fallout 4 and Skyrim mods: SAC - LoversLab Link to comment Share on other sites More sharing options...
SAC 28 Posted December 19, 2021 Share Posted December 19, 2021 17 hours ago, crossed99 said: Without the _SET_RANDOM_OUTFIT_VARIATION line they're invisible when they spawn in, so it might be working you just can't see them. You can also try instead: ENTITY::SET_ENTITY_VISIBLE(pedSpawn, true); Or maybe they fall under the ground without the PLACE_ENTITY_ON_GROUND line. But they shouldn't give you compiler errors. What errors are you getting? I'd like to refine this a little further: - I'd like the ped to spawn in front of the player, but no matter how I offset x and y, the spawn point seems random - I'd like the ped to turn to face the player, have tried TASK::TASK_TURN_PED_TO_FACE_ENTITY(myPed, player, 2000, 0, 0, 0); but it doesn't seem to do anything Quote My Fallout 4 and Skyrim mods: SAC - LoversLab Link to comment Share on other sites More sharing options...
crossed99 43 Posted December 19, 2021 Share Posted December 19, 2021 Modifying X and Y moves the spawn point east / west and north / south from you, regardless of your facing. You can get the coordinates in front of a ped with this: Vector3 front = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(playerPed, 0.0f, 2.0f, 0.0f); I can't test it right now, but your native to turn them should work, pretty sure I used that before. Make sure "player" is PLAYER::PLAYER_PED_ID() and not PLAYER::PLAYER_ID() or something, other than that not sure... 1 Quote Link to comment Share on other sites More sharing options...
SAC 28 Posted December 20, 2021 Share Posted December 20, 2021 18 hours ago, crossed99 said: Vector3 front = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(playerPed, 0.0f, 2.0f, 0.0f); Works perfectly, tyvm! 1 Quote My Fallout 4 and Skyrim mods: SAC - LoversLab Link to comment Share on other sites More sharing options...
SAC 28 Posted December 22, 2021 Share Posted December 22, 2021 Follow-up / tune-up: I have a custom ped model added to metapeds, containing outfits from multiple groups of peds (a mashup, so to speak) PED::_SET_RANDOM_OUTFIT_VARIATION(pedSpawn, 1); ^^ this is very "sticky", returns outfits from the same group of peds, resulting in uniform populations PED::_SET_PED_OUTFIT_PRESET(pedSpawn, (std::rand() % (PED::GET_NUM_META_PED_OUTFITS(pedSpawn) - 1)), false); ^^ this offers true (or, anyway, better) randomization Quote My Fallout 4 and Skyrim mods: SAC - LoversLab Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.