Reputation Activity
-
Captain Victory reacted to ToastinYou in Give a ped a specific modelI'd like to add in a few things here just so you can look back on this when you are further into coding and want to know this and that about spawning Ped's/Vehicle's so you don't have to start a new topic later on, as the answer will be right here :)
First, you have your simple spawning of your Ped.
//myCopPed1 is the name of the ped you will use throughout your code, I used myCopPed1 as 1) it's a cop, 2) I have another cop Ped which is named myCopPed2. //= new Ped creates the Ped, and then you can sift through the arrow keys up and down to find (Model model, SpawnPoint spawnpoint, float heading); // under Model model you can put whatever model ID you want, so in my case I want a police officer, so I did "s_m_y_cop_01". // I have set my SpawnPoint as SpawnPointmyCopPed1.Position, yours could be called just plain SpawnPoint, but mine is from a more complex callout. // and then, I believe (never used it), float heading is ho high or low the ped is. Generally you would want your Ped at 0.0f unless you have some weird callout that spawns the guy in the air lol (Suicidal Guy Jumped off Building? CALLOUT IDEA! :) ) myCopPed1 = new Ped("s_m_y_cop_01", SpawnPointmyCopPed1.Position, 0.0f); Now, you may be wondering later on.. can I list off a few different models and just get it to randomly pick from that list/string of models? Yes, you can! It's pretty simple too..
// Okay, in this example I'm using a Vehicle style, same thing as Ped but spawning a Vehicle. // We use Model[] VehicleModels = new Model[] to start off and initialise it, and then we do { }; and inside those brackets we list off in strings what models we want spawned. So since I want a cop car, I could put any cop car models in there, which I have done. Model[] VehicleModels = new Model[] { "POLICE", "POLICE2", "POLICE3", "POLICE4", "FBI" }; // Here, we're just doing the same thing we did for our CopPed. we do myCopCar1 to start it off, = new Vehicle to tell the code we're creating a new Vehicle, then (VehicleModels[new Random().Next(VehicleModels.Length)] okay that might sound confusing, but it's just taking the VehicleModels we created, creating a new Random generator type of sorts, and creating the next vehicle to spawn, except randomly. Then we have SpawnPointmyCopCar1.Position to tell it where to spawn the car, again, yours could be as simple as "SpawnPoint". myCopCar1 = new Vehicle(VehicleModels[new Random().Next(VehicleModels.Length)], SpawnPointmyCopCar1.Position); Hope this helped or helps you in the future, if you need any further explaining or have some questions let me know! I'm always here :)
-
Captain Victory reacted to PNWParksFan in Creating an INI file?It makes it a lot easier to keep things organized when you break out code for different features into different functions. I try to keep as little as possible in EntryPoint, for what it's worth.
To elaborate on my suggestion from earlier:
Create a new file called Settings.cs.
Within it, create a static class called Settings. Add all of the settings you'll want in your file as static fields:
internal static class Settings { internal static bool PlayMusic = true; internal static bool DoSomeOtherThing = false; internal static Keys SomeHotKeyOrWhatever = Keys.D8; internal static string PlayerName = "Name Not Set"; } Now add a static method called LoadSettings to load the settings:
internal static class Settings { internal static bool PlayMusic = true; internal static bool DoSomeOtherThing = false; internal static Keys SomeHotKeyOrWhatever = Keys.D8; internal static string PlayerName = "Name Not Set"; internal static void LoadSettings() { // initialize the INI file // read each setting and set it // For details on how to do all this, look at docs.ragepluginhook.net under the InitializationFile class // I don't have access to look it up myself at this moment but will update this example later. } } In your Initialize function, call Settings.LoadSettings(). Then, whenever you need to use a setting in your code, just call it like so:
if(Settings.PlayMusic) { // Play the music } -
Captain Victory reacted to PNWParksFan in Creating an INI file?Here is a look at how I do it, with just a few of the settings shown for the sake of example:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Rage; using System.Windows.Forms; namespace BetterEMS { internal static class Settings { internal static Keys DispatchKey = Keys.OemSemicolon; internal static ControllerButtons DispatchButton = ControllerButtons.RightShoulder; internal static float DriveSpeed = 20f; internal static bool ShowReport = true; internal static void LoadSettings() { LogWrapper.LogTrivial("Loading EMS settings"); string path = "Plugins/LSPDFR/BetterEMS.ini"; InitializationFile ini = new InitializationFile(path); ini.Create(); DispatchKey = ini.ReadEnum<Keys>("Keybindings", "DispatchEMSKey", Keys.OemSemicolon); DispatchButton = ini.ReadEnum<ControllerButtons>("Keybindings", "DispatchEMSControllerButton", ControllerButtons.RightShoulder); DriveSpeed = (float)ini.ReadDouble("Response", "DriveSpeed", 20f); ShowReport = ini.ReadBoolean("Cleanup", "ShowIncidentReport", true); } } } Basically, you need to create an InitializationFile object, then call various Read[Something] methods to get the values you want. Details here: http://docs.ragepluginhook.net/html/DEEB0B71.htm
There are methods to read pretty much all common types of values. For enums you have to specify what type of enum you're trying to read in the <brackets>, as shown for the key and button examples in the code snippet above. If you want to read a float you need to coerce it from a double, as shown.
Your INI file should be layed out with sections and variables then, like so. Note how the [section names] are the first parameter in the Read functions above, and the variable names are the second.
[Keybindings] DispatchEMSKey = OEMSemicolon DispatchEMSControllerButton = RightShoulder [Response] DriveSpeed = 20 [Cleanup] ShowIncidentReport = true
You also need to make sure that you actually call that LoadSettings() method at some point. For example, in your Initialize() method would be a good place to put Settings.LoadSettings(). If you don't do that, you'll never actually load the settings, so it'll always use the defaults.
-
Captain Victory reacted to SzbZsmbr in Create Callout dialogue?In the process you can make an IF with a boolean, like if(Game.LocalPlayer.Character.Position.DistanceTo(Ped)<=2f && onlyonce==false){.....(dialogue)....... and you will make the bool true in the end so the dialogue will not be restarted.}
If you know what i mean. If you are 2 meters from the Ped you want to speak with, then the program will allow you to speak.