How do i get random player and set a gps marker to it.
-
im tryin to create a script and im trying to get a random player from all the peds in the game and set a gps marker to that ped, how can i do this? I know how to get all the peds with World.getAllPeds() but dont know how to get a random one from here and set a market to it.
-
I assume you are using SHVDN for your scripting purposes. If yes, then, Here, This will pretty much give you what you want.
using System; using GTA; using GTA.Native; using System.Windows.Forms; namespace RandomPed { public class Class1 : Script { Ped Player, RandomPedToSpawn; private bool spawnARandomPed; public Class1() { Intialize(); } private void Intialize() { Tick += OnTick; Player = GTA.Game.Player.Character; KeyDown += onKeyDown; spawnARandomPed = false; } private void onKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.L) //Assign any key you wish to press { spawnARandomPed = true; } } private void OnTick(object sender, EventArgs e) { if (spawnARandomPed) { RandomPedToSpawn = World.CreateRandomPed(Player.Position.Around(100f)); //Define the Distance you wish to spawn the player near to. if (RandomPedToSpawn.IsAlive || RandomPedToSpawn != null) { if (Function.Call<bool>(Hash.IS_WAYPOINT_ACTIVE)) { Function.Call(Hash.SET_WAYPOINT_OFF); Function.Call(Hash.SET_NEW_WAYPOINT, RandomPedToSpawn.Position.X, RandomPedToSpawn.Position.Y); } } spawnARandomPed = false; } } } }
Please do let me know if there are any errors, as I did this on notepad, and do not have have access to my home pc which has ScripthookDotNet.
P.S. Sorry forgot to mention, you might will need to add the System.windows.forms namespace, from the references. Else, it will not recognize the KeyEventArgs class and will end up throwing an error.
-
@ashishcw said in How do i get random player and set a gps marker to it.:
SHVDN
this creates a random player, im trying to get a random player that is already spawned in the world. But for some reason World.getAllPeds() returns 1.
-
@ashishcw quick question im pretty new to modding just started yesterday is there any api for this script hook, and what is this Function.call, is this calling from the native gta code? It looks similar to Spigot coding when i did nms.
-
@zerzox
The Tutorials section has some basics on getting started with GTA V modding.You can probably just add a reference to the ScriptHookVDotNet project inside Visual Studio and it should magically work.