Cyron43 Posted May 15, 2015 Share Posted May 15, 2015 (edited) [information and a some questions;] My apologies, I forgot that. Vehicle RaceCar01;Ped Racer01;TaskSequence RacerTask01; Vector3 Point01 = new Vector3(float f, float f, float f); void Initialize(int NumberOfAI, string VehicleModel){//NumberOfAI is not in use until I got the first Ai to work decently.RaceCar01 = World.CreateVehicle(VehicleModel, Vector3 spawnpoint, Heading float);Racer01 = World.CreatePed(GTA.Native.PedHash.Barry, Vector3 spawnpointForPed);RacerTask01 = new TaskSequence();RacerTask01.AddTask.DriveTo(RaceCar01, Point01, 5f, 100 / 2f, DrivingStyle.Rushed);RacerTask01.Close();Racer01.Task.PerformSequence(RacerTask01);}This is basically what I got. Might aswell include this error; Error 2 Argument 5: cannot convert from 'GTA.DrivingStyle' to 'int' C:\Users\PlayPrey\Documents\Visual Studio 2013\Projects\SPraceMod\SPraceMod\Races\Race01.cs 46 75 SPraceMod Now you are talking. So you spawned a vehicle and you spawned a ped BUT you don't tell your ped to enter the vehicle. That type error is simply because *cough* the developers forgot *cough* to change the signature of the DriveTo method. It still expects an integer as driving style. Simply cast to int. Here is how: RacerTask01.AddTask.DriveTo(RaceCar01, Point01, 5f, 100 / 2f, (int)DrivingStyle.Rushed); EDIT: This is not your actual code, is it? RaceCar01 = World.CreateVehicle(VehicleModel, Vector3 spawnpoint, Heading float);Racer01 = World.CreatePed(GTA.Native.PedHash.Barry, Vector3 spawnpointForPed); You just inserted the types for better understanding, right? I mean your code looks more like this or not? RaceCar01 = World.CreateVehicle(vehicleModel, spawnpoint, heading);Racer01 = World.CreatePed(GTA.Native.PedHash.Barry, spawnpointForPed); Edited May 15, 2015 by Cyron43 Link to comment Share on other sites More sharing options...
Cyron43 Posted May 15, 2015 Share Posted May 15, 2015 @Crosire: I don't know, is it okay to post programming tips here? Please tell me if you rather want us to make separate threads. Link to comment Share on other sites More sharing options...
PlayPrey Posted May 15, 2015 Share Posted May 15, 2015 (edited) EDIT: This is not your actual code, is it? RaceCar01 = World.CreateVehicle(VehicleModel, Vector3 spawnpoint, Heading float);Racer01 = World.CreatePed(GTA.Native.PedHash.Barry, Vector3 spawnpointForPed); You just inserted the types for better understanding, right? I mean your code looks more like this or not? RaceCar01 = World.CreateVehicle(vehicleModel, spawnpoint, heading);Racer01 = World.CreatePed(GTA.Native.PedHash.Barry, spawnpointForPed); Yes, It was only for better understanding; Its not actually my code. It wouldnt run with what I wrote here But all I have managed is make the AI go a little faster, he still stops if I block his path... I created a github so I dont fill the forum page with code that wont work; https://github.com/PlayPrey/SPraceMod Where the classes I have made are "Main.cs" and "Races\Race01.cs". Could you take a look at it and see if anything is obviously wrong? Current issues; *Ai stops for traffic; Edit: Fixed *Ai does not go to point02, after point01 the ai goes random directions. Edit: Fixed EDIT: I forgot to call the method that sets up the task sequence... I feel really dumb now. haha. Edited May 16, 2015 by PlayPrey Link to comment Share on other sites More sharing options...
Cyron43 Posted May 16, 2015 Share Posted May 16, 2015 (edited) @PlayPrey: Sh** happens. So the script does what it's supposed to do now? Fine. Just a quick note on naming conventions: Private local members (class wide) should start with an underscore and a small letter. So it's _point01 and not Point01 for example. That way everyone can clearly distinguish them from members outside the scope of the class. Variables which are defined inside a method should start with a small letter (no leading underscore). It helps to better see in which scope they are used. Edited May 16, 2015 by Cyron43 Link to comment Share on other sites More sharing options...
crosire Posted May 16, 2015 Author Share Posted May 16, 2015 @Crosire: I don't know, is it okay to post programming tips here? Please tell me if you rather want us to make separate threads. It's alright if the conversations don't get too long =P. Just a quick note on naming conventions: Private local members (class wide) should start with an underscore and a small letter. So it's _point01 and not Point01 for example. That way everyone can clearly distinguish them from members outside the scope of the class.Variables which are defined inside a method should start with a small letter (no leading underscore). It helps to better see in which scope they are used. Note that everybody has his own conventions and there isn't a global one everybody follows. I usually mark member variables with a "m" prefix for instance (like "mMyMemberVar"), statics with a "s" (like "sMyStaticVar") and even though that distinguishes from function scope variables already, I still explicitly access them via "this->mMyMemberVar" to make that 100% clear. No explanation, these are just some rules one decides for oneself at some point. Link to comment Share on other sites More sharing options...
julionib Posted May 16, 2015 Share Posted May 16, 2015 1) What exactly does it do (never really understood the purpose of the method)? Since the scripts are executed sequentially you can call methods and access variables between scripts without problems and without having to worry about race conditions etc. can you show a example? Link to comment Share on other sites More sharing options...
crosire Posted May 16, 2015 Author Share Posted May 16, 2015 can you show a example? There is always only one single instance of a script, so you can safely mark stuff you want to share between them "static": using System;using System.Windows.Forms;using GTA;class Script1 : Script{ public Script1() { Tick += OnTick; } public static int sSpacebarCounter = 0; void OnTick(object sender, EventArgs e) { if (sSpacebarCounter > 5) { UI.Notify("You pressed space 5 times already!"); Abort(); } }}class Script2 : Script{ public Script2() { KeyDown += OnKeyDown; } void OnKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { Script1.sSpacebarCounter++; } }} Link to comment Share on other sites More sharing options...
julionib Posted May 16, 2015 Share Posted May 16, 2015 but in the case where we have the scripts in separated .dll files? this will not work right? Link to comment Share on other sites More sharing options...
crosire Posted May 16, 2015 Author Share Posted May 16, 2015 but in the case where we have the scripts in separated .dll files? this will not work right? Sure, why not? They are all loaded into the same AppDomain so that works perfectly fine (as long as you mark them "public" to let them cross assembly boundaries, "internal" would only allow usage in the same DLL). Link to comment Share on other sites More sharing options...
FunGt Posted May 16, 2015 Share Posted May 16, 2015 (edited) I can't make work any mod written in .NET. I tried reinstallin 4.5 net framework and 2013 c++ redistributable, no chance. With any script I try, I get this error: [13:48:20] [DEBUG] Instantiating script 'Vigilante' in script domain 'ScriptDomain_83A524CC' ...[13:48:20] [ERROR] Failed to instantiate script 'Vigilante' because constructor threw an exception:System.NullReferenceException: Object reference not set to an instance of an object. at GTA.ScriptDomain.ExecuteTask(IScriptTask task) at GTA.Native.Function.Call[T](UInt64 hash, InputArgument[] arguments) at GTA.Game.get_Player() at Vigilante..ctor() Using v0.8, someone knows how to solve?! Edited May 16, 2015 by FunGt Link to comment Share on other sites More sharing options...
crosire Posted May 16, 2015 Author Share Posted May 16, 2015 I can't make work any mod written in .NET. I tried reinstallin 4.5 net framework and 2013 c++ redistributable, no chance. With any script I try, I get this error: Using v0.8, someone knows how to solve?! 0.8 does not currently allow the use of natives in the constructor (forgot about that), but this mod uses them there and thus fails. Link to comment Share on other sites More sharing options...
FunGt Posted May 16, 2015 Share Posted May 16, 2015 I can't make work any mod written in .NET. I tried reinstallin 4.5 net framework and 2013 c++ redistributable, no chance. With any script I try, I get this error: Using v0.8, someone knows how to solve?! 0.8 does not currently allow the use of natives in the constructor (forgot about that), but this mod uses them there and thus fails. Ok I solved everything now. What I did: - unistalled any .NET Framework I had (4.5, 4.5.1, etc) - unistalled any c++ redistributable I had - reinstalled .NET Framework 4.5 - reinstalled 2013 c++ redistributable x64 - installed the updates from Windows Update that appeared - now it works (vigilante with v0.6 and this with v0.8) Sorry for bothering Link to comment Share on other sites More sharing options...
Cyron43 Posted May 16, 2015 Share Posted May 16, 2015 @Crosire: I don't know, is it okay to post programming tips here? Please tell me if you rather want us to make separate threads. It's alright if the conversations don't get too long =P. Just a quick note on naming conventions: Private local members (class wide) should start with an underscore and a small letter. So it's _point01 and not Point01 for example. That way everyone can clearly distinguish them from members outside the scope of the class.Variables which are defined inside a method should start with a small letter (no leading underscore). It helps to better see in which scope they are used. Note that everybody has his own conventions and there isn't a global one everybody follows. I usually mark member variables with a "m" prefix for instance (like "mMyMemberVar"), statics with a "s" (like "sMyStaticVar") and even though that distinguishes from function scope variables already, I still explicitly access them via "this->mMyMemberVar" to make that 100% clear. No explanation, these are just some rules one decides for oneself at some point. Sure no one is forced to go with any conventions but as soon as you work in a team then all members should agree on a common ground. https://msdn.microsoft.com/en-us/library/vstudio/ms229045%28v=vs.100%29.aspx Above that I use the Resharper naming conventions as this is the tool most professionals use. Link to comment Share on other sites More sharing options...
Guad Posted May 16, 2015 Share Posted May 16, 2015 I can't make work any mod written in .NET. I tried reinstallin 4.5 net framework and 2013 c++ redistributable, no chance. With any script I try, I get this error: Using v0.8, someone knows how to solve?! 0.8 does not currently allow the use of natives in the constructor (forgot about that), but this mod uses them there and thus fails. So how are we supposed to make calls on script start? Link to comment Share on other sites More sharing options...
PlayPrey Posted May 16, 2015 Share Posted May 16, 2015 @Cyron43 : I don't work in a team though. Link to comment Share on other sites More sharing options...
GTAGeek123 Posted May 16, 2015 Share Posted May 16, 2015 I tested the latest release with the Simple Passenger Mod and it is now working. Thanks. Link to comment Share on other sites More sharing options...
Cyron43 Posted May 16, 2015 Share Posted May 16, 2015 @Cyron43 : I don't work in a team though. I didn't say you or anyone has to go with conventions. It was just a recommendation. Link to comment Share on other sites More sharing options...
crosire Posted May 16, 2015 Author Share Posted May 16, 2015 Released v0.9, now allows calling natives inside the script constructor again. Inco 1 Link to comment Share on other sites More sharing options...
qwerasdzxc Posted May 16, 2015 Share Posted May 16, 2015 I'm trying to set plate number text in spawned vehicle but I'm getting errors in function SET_VEHICLE_NUMBER_PLATE_TEXT: using GTA;using System;using System.Windows.Forms;public class FirstMod : Script{ public FirstMod() { Tick += OnTick; KeyDown += OnKeyDown; KeyUp += OnKeyUp; Interval = 10000; //Notify test NotifyText("Welcome to my first mod!\nHope you'll have fun!"); } //Function for printing text in-game public void PrintText(string text, int time = 2500) { GTA.Native.Function.Call(GTA.Native.Hash._0xB87A37EEB7FAA67D, "STRING"); GTA.Native.Function.Call(GTA.Native.Hash._ADD_TEXT_COMPONENT_STRING, text); GTA.Native.Function.Call(GTA.Native.Hash._0x9D77056A530643F6, time, 1); } //Function for printing text in-game above map public void NotifyText(string text) { UI.Notify(text); } //Testing ground - where script throws errors unsafe public void NumberPlate(string plateText) { GTA.Native.Function.Call(GTA.Native.Hash.SET_VEHICLE_NUMBER_PLATE_TEXT, Vehicle vehicle, char *plateText); } void OnTick(object sender, EventArgs e) { } void OnKeyDown(object sender, KeyEventArgs e) { } void OnKeyUp(object sender, KeyEventArgs e) { Ped player = Game.Player.Character; GTA.Math.Vector3 spawnLoc = player.Position + (player.ForwardVector * 5); if (e.KeyCode == Keys.H) { //Defining and spawning car string model_name = "fbi"; Vehicle car = GTA.World.CreateVehicle(model_name, spawnLoc); NumberPlate("TEXT"); Game.Player.Character.Task.WarpIntoVehicle(car, VehicleSeat.Driver); //Prints text in-game PrintText("Car Spawned!", 2500); } } } Link to comment Share on other sites More sharing options...
Mcfloy Posted May 16, 2015 Share Posted May 16, 2015 (edited) I'm trying to set plate number text in spawned vehicle but I'm getting errors in function SET_VEHICLE_NUMBER_PLATE_TEXT: using GTA;using System;using System.Windows.Forms;public class FirstMod : Script{ public FirstMod() { Tick += OnTick; KeyDown += OnKeyDown; KeyUp += OnKeyUp; Interval = 10000; //Notify test NotifyText("Welcome to my first mod!\nHope you'll have fun!"); } //Function for printing text in-game public void PrintText(string text, int time = 2500) { GTA.Native.Function.Call(GTA.Native.Hash._0xB87A37EEB7FAA67D, "STRING"); GTA.Native.Function.Call(GTA.Native.Hash._ADD_TEXT_COMPONENT_STRING, text); GTA.Native.Function.Call(GTA.Native.Hash._0x9D77056A530643F6, time, 1); } //Function for printing text in-game above map public void NotifyText(string text) { UI.Notify(text); } //Testing ground - where script throws errors unsafe public void NumberPlate(string plateText) { GTA.Native.Function.Call(GTA.Native.Hash.SET_VEHICLE_NUMBER_PLATE_TEXT, Vehicle vehicle, char *plateText); } void OnTick(object sender, EventArgs e) { } void OnKeyDown(object sender, KeyEventArgs e) { } void OnKeyUp(object sender, KeyEventArgs e) { Ped player = Game.Player.Character; GTA.Math.Vector3 spawnLoc = player.Position + (player.ForwardVector * 5); if (e.KeyCode == Keys.H) { //Defining and spawning car string model_name = "fbi"; Vehicle car = GTA.World.CreateVehicle(model_name, spawnLoc); NumberPlate("TEXT"); Game.Player.Character.Task.WarpIntoVehicle(car, VehicleSeat.Driver); //Prints text in-game PrintText("Car Spawned!", 2500); } } } you can assign a plate to your car with it like that : car.NumberPlate = "L33T" (I assume that you understand that car is the name you've given to your vehicle object.) And i recommend you to use Visual Studio to have a look on available functions ;-) Edited May 16, 2015 by Mcfloy Link to comment Share on other sites More sharing options...
qwerasdzxc Posted May 16, 2015 Share Posted May 16, 2015 I'm trying to set plate number text in spawned vehicle but I'm getting errors in function SET_VEHICLE_NUMBER_PLATE_TEXT: using GTA;using System;using System.Windows.Forms;public class FirstMod : Script{ public FirstMod() { Tick += OnTick; KeyDown += OnKeyDown; KeyUp += OnKeyUp; Interval = 10000; //Notify test NotifyText("Welcome to my first mod!\nHope you'll have fun!"); } //Function for printing text in-game public void PrintText(string text, int time = 2500) { GTA.Native.Function.Call(GTA.Native.Hash._0xB87A37EEB7FAA67D, "STRING"); GTA.Native.Function.Call(GTA.Native.Hash._ADD_TEXT_COMPONENT_STRING, text); GTA.Native.Function.Call(GTA.Native.Hash._0x9D77056A530643F6, time, 1); } //Function for printing text in-game above map public void NotifyText(string text) { UI.Notify(text); } //Testing ground - where script throws errors unsafe public void NumberPlate(string plateText) { GTA.Native.Function.Call(GTA.Native.Hash.SET_VEHICLE_NUMBER_PLATE_TEXT, Vehicle vehicle, char *plateText); } void OnTick(object sender, EventArgs e) { } void OnKeyDown(object sender, KeyEventArgs e) { } void OnKeyUp(object sender, KeyEventArgs e) { Ped player = Game.Player.Character; GTA.Math.Vector3 spawnLoc = player.Position + (player.ForwardVector * 5); if (e.KeyCode == Keys.H) { //Defining and spawning car string model_name = "fbi"; Vehicle car = GTA.World.CreateVehicle(model_name, spawnLoc); NumberPlate("TEXT"); Game.Player.Character.Task.WarpIntoVehicle(car, VehicleSeat.Driver); //Prints text in-game PrintText("Car Spawned!", 2500); } } } you can assign a plate to your car with it like that : car.NumberPlate = "L33T" (I assume that you understand that car is the name you've given to your vehicle object.) And i recommend you to use Visual Studio to have a look on available functions ;-)Yeah understand everything but function for set plate is giving me errors. I am using VS 2013 Link to comment Share on other sites More sharing options...
timnboys Posted May 16, 2015 Share Posted May 16, 2015 Hello @Crosire do you think you will implement the getclosestped that was in the gta iv .net scripthook? as that would be great and help me out with getting the closestped to the player instead of basically having no easy way of doing it. Link to comment Share on other sites More sharing options...
Andross90 Posted May 16, 2015 Share Posted May 16, 2015 I've been trying to have some functions execute as soon as the game loads but I can't seem to get it to work. The onTick event seems to begin firing before the story mode has fully loaded, and I have tried waiting for Player.CanControlCharacter to return true before calling the functions but even that seems to return true before the game loads. An event like 'onGameLoad' would be very helpful, or just something that is definitely true only when the game has fully loaded that I can check. Link to comment Share on other sites More sharing options...
XBLToothPik Posted May 17, 2015 Share Posted May 17, 2015 (edited) -NVM Edited May 17, 2015 by XBLToothPik Link to comment Share on other sites More sharing options...
GTAGeek123 Posted May 17, 2015 Share Posted May 17, 2015 (edited) I seemed to be unable to load old save games when using this mod again (just sits at the loading screen, but never loads). I thought it was fixed in version 0.8, but it looks to be happening in 0.8 and 0.9. It seemed to be working earlier, but I had to do a repair install of the game today for unrelated reasons and then had to re-apply my mods. Everything is working perfectly, except I can't load old save games using this mod again. I have even downloaded and reinstalled version 0.8 and then version 0.9, but have had no luck. Any thoughts? Edit: This save game issue does not appear to be coming from this mod, but rather it seems the number of asi mods I have enabled is causing the issue. When I have over 16 or 17 mods enabled I can no longer load old save games. I disable one (doesn't seem to matter which one) and the issue goes away. Does anyone know if there is a limit on the number of asi mods that can be used at one time? Edited May 17, 2015 by GTAGeek123 Link to comment Share on other sites More sharing options...
ech3lon Posted May 17, 2015 Share Posted May 17, 2015 (edited) Hello @Crosire do you think you will implement the getclosestped that was in the gta iv .net scripthook? as that would be great and help me out with getting the closestped to the player instead of basically having no easy way of doing it. You can do that yourself quite easily. This code is untested and from the top of my head but should do the job. You simply obtain all the Peds within a certain radius and determine which one is the closest. Set distance to something small if you are looking only for very close peds. E.g. 2.5F would be very close, 10.0F is still reasonable. Depends on what you are trying to do. public static Ped getClosestPed(float distance) { Ped[] peds = World.GetNearbyPeds(Game.Player.Character, distance); if (peds != null && peds.Length > 0) { int closestPedIndex = 0; float closestPedDistance = distance; for (int i = 0; i < peds.Length; i++) { if (Entity.Exists(peds[i]) && Function.Call<bool>(Hash.IS_ENTITY_A_PED, peds[i])) { Vector3 playerPosition = Game.Player.Character.Position; Vector3 pedPosition = peds[i].Position; if (Function.Call<float>(Hash.GET_DISTANCE_BETWEEN_COORDS, playerPosition.X, playerPosition.Y, playerPosition.Z, pedPosition.X, pedPosition.Y, pedPosition.Z, 1) < closestPedDistance) { closestPedIndex = i; } } } return peds[closestPedIndex]; } return null; } Edited May 17, 2015 by ech3lon Link to comment Share on other sites More sharing options...
Mcfloy Posted May 17, 2015 Share Posted May 17, 2015 Yeah understand everything but function for set plate is giving me errors.I am using VS 2013 NumberPlate() contains 2 variables that wasn't initialized before (i mean there's no value on them, so your function shouldn't work well like that) Add in your parameters those 2 variables and it should works. Link to comment Share on other sites More sharing options...
Prof_Farnsworth Posted May 17, 2015 Share Posted May 17, 2015 Hello @Crosire do you think you will implement the getclosestped that was in the gta iv .net scripthook? as that would be great and help me out with getting the closestped to the player instead of basically having no easy way of doing it. As far as I can tell using GeNearbyVehicles, these are done radially outward from the player. If you use GetNearbyPeds(Ped, Radius, MaxAmount) and set "MaxAmount" to 1, it should return the closest ped only. Haven't tested yet but worth a try. Link to comment Share on other sites More sharing options...
thismuchvolume Posted May 17, 2015 Share Posted May 17, 2015 I'm trying to use the example off the wiki for spawning vehicles, but I'm getting a compile error: [02:13:19] [ERROR] Failed to compile 'invisibleragdoll.cs' with 3 error(s): at line 24: The name 'VehicleHash' does not exist in the current context at line 26: The name 'Color' does not exist in the current context at line 27: The name 'Color' does not exist in the current context Here's the complete code I'm using. I tried the indicator example and it worked fine, so I know my basic setup is good. I just must be missing something simple here. using System;using System.Windows.Forms;using GTA;class CreateVehicle : Script{ public CreateVehicle() { Tick += onTick; KeyUp += onKeyUp; KeyDown += onKeyDown; } private void onKeyDown(object sender, KeyEventArgs e) { } private void onKeyUp(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.NumPad0) { Vehicle vehicle = World.CreateVehicle(VehicleHash.Adder, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 3.0f, Game.Player.Character.Heading + 90); vehicle.CanTiresBurst = false; vehicle.CustomPrimaryColor = Color.FromArgb(38, 38, 38); vehicle.CustomSecondaryColor = Color.DarkOrange; vehicle.PlaceOnGround(); vehicle.NumberPlate = "SHVDN"; } } private void onTick(object sender, EventArgs e) { }} Any ideas? Link to comment Share on other sites More sharing options...
thismuchvolume Posted May 17, 2015 Share Posted May 17, 2015 So, of course, as soon as you ask for help you figure out the problem yourself. I noticed there was a nested name space in the header file for Vehicle, so I realized I needed using GTA.Native; Then I realized shortly after that the Color referenced was actually a part of C# standard library and not a special Color class as part of GTA. For that, I added using System.Drawing; Presto! It works. The wiki probably should be updated with the following to work with the latest version of the .net loader. using System;using System.Drawing;using System.Windows.Forms;using GTA;using GTA.Native;class CreateVehicle : Script{ public CreateVehicle() { Tick += onTick; KeyUp += onKeyUp; KeyDown += onKeyDown; } private void onKeyDown(object sender, KeyEventArgs e) { } private void onKeyUp(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.NumPad0) { Vehicle vehicle = World.CreateVehicle(VehicleHash.Adder, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 3.0f, Game.Player.Character.Heading + 90); vehicle.CanTiresBurst = false; vehicle.CustomPrimaryColor = Color.FromArgb(38, 38, 38); vehicle.CustomSecondaryColor = Color.DarkOrange; vehicle.PlaceOnGround(); vehicle.NumberPlate = "URMOM"; } } private void onTick(object sender, EventArgs e) { }} 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