Setting up Hotkey to Spawn Ped Model
-
I would like to set up a hotkey to spawn a specific ped model without having to go through a trainer. Could someone point me in the right direction on how to go about this via tutorial or personal knowledge? Thanks in advance to anyone that can answer.
-
Someone might have a different perspective on how to solve this but here is mine
Use ScriptHookV or RagePluginHook
create a script and assign a hotkey to a ped model so everytime you press that key... that ped spawns
Using RagePluginHook to spawn a random ped. Your code would look like this
CODE PROVIDED BY TitanSloth || It's a ped generatorinternal static class EntryPoint { public static void Main() { Vector3 spawnPoint; Ped Player = Game.LocalPlayer.Character; Ped myPed; Blip myBlip; while (true) { bool player_Has_Weapon = false; // Sets the spawnPoint spawnPoint = Player.GetOffsetPosition(Vector3.RelativeFront * 10); if (Game.IsKeyDown(Keys.F)) { myPed = new Ped(spawnPoint); myBlip = myPed.AttachBlip(); if (!myPed.Exists()) break; if (!myBlip.Exists()) break; // While the player DOES NOT have the weapon... while (!player_Has_Weapon) { // Give the Ped a weapon myPed.Inventory.GiveNewWeapon("WEAPON_ADVANCEDRIFLE", 150, true); // Set this to true player_Has_Weapon = true; if (player_Has_Weapon) { break; } } myPed.RelationshipGroup = new RelationshipGroup("ATTACKER"); Game.SetRelationshipBetweenRelationshipGroups("ATTACKER", "PLAYER", Relationship.Hate); myPed.Tasks.FightAgainstClosestHatedTarget(20f); } GameFiber.Yield(); } } }
}
-
Thanks for responding. Would this script spawn the model as a playable character, or as a bodyguard/attacker? Trying to replace the player.
-
@NotOfTheWorld That code spawns an attacker.
This is how you would change the model of the player using Script Hook V .NET:
using GTA; using System; using System.Windows.Forms; public class ChangePlrModel : Script { Keys changeModelKey = Keys.E; Model modelToChangeTo = "Abigail"; public ChangePlrModel() { KeyDown += ChangePlrModel_KeyDown; } private void ChangePlrModel_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == changeModelKey) { Game.Player.ChangeModel(modelToChangeTo); } } }
To use this, install Script Hook V .NET, create a file named "ChangePlrModel.cs" in the scripts folder in your GTA V directory, then copy the code I provided into that file and save. Edit the model/key to your liking.
-
@NotOfTheWorld Not sure I haven't reviewed the code. To replace the player I think some additional code is required. Quick google is possible. Hope you know how to compile code
EDIT
yeah it spawns a ped that acts as an attacker I believe. If you read the comments in the codebut im just showing you that if you want to change your player without a menu. This is what your gonna have to do because everyone uses a menu and no one has made something that your asking about. It's weird but yeah.. i guess you don't like menu's
-
@zeroxzerotwo It spawns an attacker, not a bodyguard.
-
@Jitnaught said in Setting up Hotkey to Spawn Ped Model:
@zeroxzerotwo It spawns an attacker, not a bodyguard.
that code you provided. Is that HookV or RAGE hook ?
-
@zeroxzerotwo Script Hook V .NET.
-
@NotOfTheWorld Yeah so use his code and compile it wit Hook V in visual studio and you don't need to use a mod menu
-
@zeroxzerotwo I already provided instructions on how to use the code. You don't need to compile it to use it
-
@Jitnaught said in Setting up Hotkey to Spawn Ped Model:
@zeroxzerotwo I already provided instructions on how to use the code. You don't need to compile it to use it
yeah but doesnt none compiled code create more lag? using it compiled makes it less stressful on the engine right ?
-
@zeroxzerotwo SHVDN automatically compiles the code on startup, that way you don't need to install Visual Studio to use the mod. The lag is no different than if you compiled it with Visual Studio.
-
@Jitnaught this is exactly what I was looking for, Thank you!
And If I was to use zeroxzerotwo's code to spawn a ped, what should I name It, and should I save it as a .cs file as well?
-
@NotOfTheWorld That code is for RagePluginHook. I don't know how their system works so I have no idea if you can just save it to a CS file or if you have to compile it with Visual Studio
-
@Jitnaught this thread gave me the idea that I'd like to be able to make a fish appear in front of the player with a hot key. Would be great if it was as easy as putting that cs file together, holy cow!
-
@NotOfTheWorld This should do what you want (SHVDN script, save it as CS file in scripts folder):
using GTA; using GTA.Math; using System; using System.Windows.Forms; public class CreatePed : Script { Keys createPedKey = Keys.E; Model pedModel = "Fish"; public CreatePed() { KeyDown += CreatePed_KeyDown; } private void CreatePed_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == createPedKey) { Vector3 position = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, 2f, 0.5f)); World.CreatePed(pedModel, position); } } }
-
Title it CreatePed.cs?
-
@NotOfTheWorld Sure, although you can name it anything you like.
-
@Jitnaught Well, Can't get it to work, LOL, but you solved the original question I had though, so thank you.
-
@NotOfTheWorld What does your ScriptHookVDotNet.log file say? I just wrote that code in notepad so I may have messed something up.
-
[23:19:54] [DEBUG] Created script domain 'ScriptDomain_8AE9C2E6' with v2.10.3.
[23:19:54] [DEBUG] Loading scripts from 'C:\Program Files\Rockstar Games\Grand Theft Auto V\scripts' into script domain 'ScriptDomain_8AE9C2E6' ...
[23:19:55] [DEBUG] Successfully compiled 'ChangePlrModel.cs'.
[23:19:55] [DEBUG] Found 1 script(s) in 'ChangePlrModel.cs'.
[23:19:55] [DEBUG] Successfully compiled 'CreatePed.cs'.
[23:19:55] [DEBUG] Found 1 script(s) in 'CreatePed.cs'.
-
@NotOfTheWorld That's the log after pressing E to test right?
-
@Jitnaught Changed key to X but yeah, does nothing. Aiming to do what happens at the end of this video(3:30secs) that I made but with a hotkey instead of a spooner:
-
@Jitnaught Holy Moley!! Got it to work! The Ped Model name for the fish was A_C_Fish. It works perfect now, Thank you!
-
@NotOfTheWorld said in Setting up Hotkey to Spawn Ped Model:
@Jitnaught Holy Moley!! Got it to work! The Ped Model name for the fish was A_C_Fish. It works perfect now, Thank you!
glad everything worked out for you