Foxtrot64 Posted July 13, 2015 Share Posted July 13, 2015 I've tried searching for the best way to do this however I'm not entirely sure how to word it best. I know we can use Game.Player.Character.Position.Around(distance) but this often spawns your ped under or above ground. Yes, the game does eventually pull them to the surface but I would like the Z axis to be determined as above ground before they are spawned there. Again, offsetting the player coordinates will can spawn them above/over ground and in walls. I'm also working on a mod that has no world peds/vehicles so I can't really latch on those that the game has already made. I'm running a loop and will be spawning up to 50 peds in the vicinity of the player. They all need to be above ground and not stuck in a building etc. Thanks Link to comment Share on other sites More sharing options...
Colata Posted July 13, 2015 Share Posted July 13, 2015 (edited) I've tried searching for the best way to do this however I'm not entirely sure how to word it best. I know we can use Game.Player.Character.Position.Around(distance) but this often spawns your ped under or above ground. Yes, the game does eventually pull them to the surface but I would like the Z axis to be determined as above ground before they are spawned there. Again, offsetting the player coordinates will can spawn them above/over ground and in walls. I'm also working on a mod that has no world peds/vehicles so I can't really latch on those that the game has already made. I'm running a loop and will be spawning up to 50 peds in the vicinity of the player. They all need to be above ground and not stuck in a building etc. Thanks Can i just ask, what are you intending to do with "50" Peds? If you are intending to make them all do tasks, that is not going to go down well. You can do something like Ped player = Game.Player.Character; public PedSpawner() { Tick += OnTick; Interval = 10000; } void OnTick(object sender, EventArgs f) { World.CreateRandomPed(player.Position + (player.ForwardVector * 10) + (player.UpVector * 20)); } } Don't go to like 10; on the interval or peds will just start dropping from the air and probably crash your game.. But this is basically all you need. Change the (player.forwardvector) to a distance you like (test it out) then if the peds arent falling from high enough in the air (even though they'll probably die if you go much higher) then adjust that too. Also, like I said, if you intend to make the peds do tasks, you will have to define the peds and you should probably only have 5-7 doing tasks at the same time or a lot of them may just stop responding and stand still. If you want to make them spawn at different times, i think you can just make a randomizer and make a time period and let it pick a time between that period (not too sure about that) if you want to make the peds location random, (or at least appear random around the players location) you can also make a list of positions around the player and then make a randomizer to pick out of one of those positions Vector3 playerNorth = player.ForwardVector * 20; Vector3 playerSouth = player.ForwardVector * -20; Vector3 PlayerEast = player.RightVector * 20; Vector3 PlayerWest = player.RightVector * -20; then just make a radomizer to pick out of the list above. (im not too sure about this as i cant make a "List<Vector3>") Just a pointer, i dont think this will have any guarantee that the peds wont spawn in a building, as we're telling them to spawn at Vector locations, regardless of buildings, but it should be close to a radius around the player, especailly if you do it like the compas (north, south, east, west), if you're making them run around buildings to hunt the player down, they spread out and make it look like they're coming from within the player radius and not just North, South, East or West, or if you wanted to go even farther, you could probably make cords for SouthWest, NorthEast, etc. I doubt this is what you want, but this is all i can picture in my head Edited July 13, 2015 by Colata frodzet 1 Link to comment Share on other sites More sharing options...
Prof_Farnsworth Posted July 13, 2015 Share Posted July 13, 2015 There are a couple of ways to go about this. One is to spawn them high in the air, then use "GetGroundZ" function to drop them to the ground, however, this will drop them into buildings on occasion still. I am sure you can also use "GET_NTH_VEHICLE_NODE" but I have no experience with that. The way I do it is cheating. I spawn a car, then use "PlaceOnGround" and "PlaceOnNextStreet", create the ped in the car, then delete the car. This is the best way I have found to make sure they always spawn somewhere reliable. Here is an excerpt from my assassination mod: new Model("cavalcade").Request();while (!new Model("cavalcade").IsLoaded) Wait(10);Vehicle tempspawn = World.CreateVehicle("cavalcade", playerped.Position.Around(650f));if (Entity.Exists(tempspawn)){tempspawn.PlaceOnGround();tempspawn.PlaceOnNextStreet();targets[i] = tempspawn.CreatePedOnSeat(VehicleSeat.RightRear, pedTemp);if (Entity.Exists(targets[i])) { tempspawn.MarkAsNoLongerNeeded(); tempspawn.Delete(); }} frodzet 1 Link to comment Share on other sites More sharing options...
Foxtrot64 Posted July 14, 2015 Author Share Posted July 14, 2015 I got a weird warning tell me that GetGroundZ was deprecated. GetGroundHeight worked fine. I can make a random spawn location with set distance from the player, then update it's Z axis to always spawn it above ground. This often means that they'll just spawn on top of buildings. I'm going to run a few tests and perhaps make the program come up with a new random spawn if the difference between player and GetGroundHeight Z coordinates are too different. Likewise, if the spawn location so happens in water, they spawn at the bottom of the ocean/pool/lake etc. I could run a number checks to see if they are in water, and again spawn elsewhere. They also get pushed out of vehicles if they so happen to spawn inside them. I wish the game would do the same for buildings but whatever. Here's some code: Ped player = Game.Player.Character;Vector3 spawn = player.Position + (player.ForwardVector * 20);spawn.Z = World.GetGroundHeight(spawn); Both of your suggestions are great. Thanks guys. Link to comment Share on other sites More sharing options...
Prof_Farnsworth Posted July 14, 2015 Share Posted July 14, 2015 Right, GetGroundZ was updated, sorry. And water spawns is why I started to use the car to spawn them, now that you remind me, since it was easier than respawning and chancing water again. There was a native I found that was something like "IS_PED_SPAWN_RELIABLE". If I can find it I'll edit this, but I didn't ever get it working. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now