Noox Posted June 21, 2014 Share Posted June 21, 2014 Hello, this is what I have done so far public void spawnMobileAlly() { Group mobileGroup = Player.Group; if (pGroup.MemberCount == 3) Game.DisplayText("Too many group members"); else { Vector3 playerPos = Player.Character.Position.Around(50.0f); Vehicle veh = World.CreateVehicle("INTRUDER", playerPos); Ped[] mobilePeds = new Ped[3]; for (int i = 0; i < mobilePeds.Length; i++) { mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player); mobilePeds[i].WarpIntoVehicle(veh, ) //what should I put as seat? } } but I don't know how the seats are called, by using visual studio intellisense I can see there is no driver or passenger, could you help me? thanks Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 (edited) Class named VehicleSeat example of use: VehicleSeat.DriverRegards,Paul. Edited June 21, 2014 by leftas Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 Thanks! How do I let them reach Niko by not leaving the vehicle? Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 Just reach or and follow ? Regards, Paul. Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 Reach. Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 mobilePeds[i].Task.DriveTo(...); This function. Also check Doc. from hazardx http://www.hazardx.com/details.php?file=89 There is everyhing. Or you can search in source code(C++) Regards, Paul. Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 I finished it but it's not working, after 30 minutes of looking I gave up. This is the mess I made public void spawnMobileAlly() { pGroup = Player.Group; if (pGroup.MemberCount == 3) Game.DisplayText("Too many group members"); else { Vector3 playerPos = Player.Character.Position.Around(50.0f); Vehicle veh = World.CreateVehicle("INTRUDER", playerPos); Ped[] mobilePeds = new Ped[3]; for (int i = 0; i < mobilePeds.Length; i++) { mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player); if (i == 0) mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver); else mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat); } mobilePeds[1].Task.DriveTo(Player.Character, 250, false); float mobDistance = mobilePeds[1].Position.DistanceTo(Player.Character.Position); if (mobDistance < 2) { for (int i = 0; i < mobilePeds.Length; i++) { mobilePeds[i].Task.LeaveVehicle(); applyGroupProperties(mobilePeds[i]); } } } } applyGroupProperties: public void applyGroupProperties(Ped p) { p.CurrentRoom = Player.Character.CurrentRoom; p.WillDoDrivebys = true; p.Armor = 500; p.PriorityTargetForEnemies = true; p.DuckWhenAimedAtByGroupMember = true; p.AlwaysDiesOnLowHealth = true; p.SetPathfinding(true, true, true); Weapon weapon = Player.Character.Weapons.Current; p.Weapons.FromType(weapon).Ammo = 500; p.Weapons.Select(weapon); p.RelationshipGroup = RelationshipGroup.Player; p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion); p.CantBeDamagedByRelationshipGroup(RelationshipGroup.Player, true); pGroup.AddMember(p); } They spawn correctly (well, not correctly since most of the times they're not in the road ) but they don't move and if I get closer they don't leave the vehicle, what's the problem? Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 (edited) With last lines of spawn. That need's to be in loop to check. But I don't know how to do that don't need to loop(like for you) always applyGroupProperties I have workaround but it's dumb(it's i++ workaround)... Just I don't get your line mobilePeds[1].Task.DriveTo(Player.Character, 250, false); Array starts from 0 and your driver is at 0 not at 1 ? Edited June 21, 2014 by leftas Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 (edited) With last lines of spawn. That need's to be in loop to check. But I don't know how to do that don't need to loop(like for you) always applyGroupProperties I have workaround but it's dumb(it's i++ workaround)... Just I don't get your line mobilePeds[1].Task.DriveTo(Player.Character, 250, false); Array starts from 0 and your driver is at 0 not at 1 ? lol I'm stupid, I forgot that eheh. Now the driver comes to me but they don't disembark so I think that this piece of code is not working, I'll put a Game.DisplayText to see if the function is executed. float mobDistance = mobilePeds[1].Position.DistanceTo(Player.Character.Position); if (mobDistance < 2) { for (int i = 0; i < mobilePeds.Length; i++) { mobilePeds[i].Task.LeaveVehicle(); applyGroupProperties(mobilePeds[i]); } } Edited June 21, 2014 by Noox Link to comment Share on other sites More sharing options...
Rugz007 Posted June 21, 2014 Share Posted June 21, 2014 Which Mod You Making ?? Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 (edited) Also applyGroupProperties(mobilePeds[i]); this should be not in your loop but when you creating ped So you can put in loop(main tick) if (mobDistance < 2) { for (int i = 0; i < mobilePeds.Length; i++) { if (movilePeds[i].isInVehicle()) mobilePeds[i].Task.LeaveVehicle(); } } EDIT: I said to you You just executing this one time(Key press) so it's not checking if they in your range or not, you need to put ^ this code in loop(main tick) Regards, Paul. Edited June 21, 2014 by leftas Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 Thanks but it's still not working, the condition always returns false, I inserted a debug message but it doesn't pop-up in game. Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 I think 2 is too small(don't know how it's calculated in GTA 4) but I think this just too small. try to put 15 And you put that code in loop yea ? Regards, Paul. Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 (edited) Yeah it's in the loop, I tried 20 already and it didn't work. EDIT: Nevermind, I understood wrong because i didn't notice your edit, I'll see if it works now! Alright I made the changes but now the script has an error in the main thick, the console says "error during thick "blabla" and then System.NullReferenceException so I think it's trying to say that the object I'm working on doesn't exist. This is the entire code using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;using GTA;namespace Mob{ public class Mob : Script { Group pGroup; Model allyModel = "M_Y_BOUNCER_02"; Vector3 playerPos; Vehicle veh; Ped[] mobilePeds = new Ped[3]; float mobDistance; public Mob() { Interval = Settings.GetValueInteger("INTERVAL", "SETTINGS", 1000); playerPos = Player.Character.Position.Around(50.0f); veh = World.CreateVehicle("INTRUDER", playerPos); this.Tick += new EventHandler(testTick); this.KeyDown += new GTA.KeyEventHandler(this.testKeyDown); } public void testTick(object sender, EventArgs e) { if(Exists(mobilePeds[0])) mobDistance = mobilePeds[0].Position.DistanceTo(Player.Character.Position); if (mobDistance < 15) { for (int i = 0; i < mobilePeds.Length; i++) { if (mobilePeds[i].isInVehicle()) mobilePeds[i].Task.LeaveVehicle(); } } } public void testKeyDown(object sender, GTA.KeyEventArgs e) { switch (e.Key) { case Keys.N: spawnAlly(); break; case Keys.Delete: if(pGroup.MemberCount > 1) { foreach (Ped member in pGroup) { member.Weapons.RemoveAll(); member.Die(); } pGroup.RemoveAllMembers(); } break; case Keys.End: spawnMobileAlly(); break; } } public void spawnAlly() { pGroup = Player.Group; if (pGroup.MemberCount >= 3) Game.DisplayText("Max member count reached!"); else { Ped p = World.CreatePed(allyModel, Player.Character.Position.Around(5.0f), RelationshipGroup.Player); applyGroupProperties(p); } } public void spawnMobileAlly() { pGroup = Player.Group; if (pGroup.MemberCount == 3) Game.DisplayText("Too many group members"); else { for (int i = 0; i < mobilePeds.Length; i++) { mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player); if (i == 0) mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver); else mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat); applyGroupProperties(mobilePeds[i]); } mobilePeds[0].Task.DriveTo(Player.Character, 250, true); } } public void applyGroupProperties(Ped p) { p.CurrentRoom = Player.Character.CurrentRoom; p.WillDoDrivebys = true; p.Armor = 500; p.PriorityTargetForEnemies = true; p.DuckWhenAimedAtByGroupMember = true; p.AlwaysDiesOnLowHealth = true; p.SetPathfinding(true, true, true); Weapon weapon = Player.Character.Weapons.Current; p.Weapons.FromType(weapon).Ammo = 500; p.Weapons.Select(weapon); p.RelationshipGroup = RelationshipGroup.Player; p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion); p.CantBeDamagedByRelationshipGroup(RelationshipGroup.Player, true); pGroup.AddMember(p); } }} Thanks for the help. EDIT: Nevermind, fixed it, I just needed to put the other if statement under if Exists but there is a problem, when they leave the vehicle they don't follow me, it's like the AI is disabled, they do nothing EDIT2: Fixed that as well needed to apply their properties after they left the vehicle! Thanks a lot leftas! Edited June 21, 2014 by Noox Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 Which Mod You Making ?? Just to get started you press a key and some guys come to help with a vehicle Link to comment Share on other sites More sharing options...
Rugz007 Posted June 21, 2014 Share Posted June 21, 2014 Very advanced as the 1st mod Mine was a helispwaner Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 Hm I will notice that. But the problem is that you applying it x times when you are not in the vehicle. But you can fix that by if (mobilePeds[i].isInVehicle()){ mobilePeds[i].Task.LeaveVehicle(); applyGroupProperties(mobilePeds[i]);} Or even if you don't want to start loop you just check if driver in the vehicle and then check distance and start loop I don't like to start loop because for it, uses more resources and you applying the same sh*t over and over again.... Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 (edited) Thanks, that should be more optimized I noticed that I have one more problem, basically if I keep pressing del new vehicles with a new crew will keep spawning even if I use that if statement, why that? I tried doing a counter which is initialized to 0 then when the key is pressed it checks if it's 0 (could have used a boolean var but whatever) then if it is 0 it creates a new vehicle and it gets incremented but still vehicles keep spawning with new NPCs but just the first 3 are inside the car. How can I fix that? Edited June 21, 2014 by Noox Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 Hm I can't understand this sentence I noticed that I have one more problem, basically if I keep pressing del new vehicles with a new crew will keep spawning even if I use that if statement, why that? Sorry but I can't understand what you mean by that ? Can you give me an example ? Again sorry! Regards, Paul. Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 (edited) Let's say I have to press X to spawn a group of guys inside the vehicle. I press X, new vehicle spawns somewhere with 3 NPCs, the NPCs go inside the vehicle. I have a variable that counts how many vehicles there are, when I press X the first time the vehicle count goes to 1 and when I press X again the the game checks if the vehicle count is 0, since there is a vehicle already it will not spawn it again with 3 more guys. This does not happen, even if the vehicle count is 1 it still spawns a vehicle, an empty one. EDIT: Since one function spawned some guys on foot there was some kind of conflict with the group variable, I deleted that function and everything is working fine! Thanks again Edited June 21, 2014 by Noox Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 Can you show me the code, how you do that ? Regards, Paul. Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 (edited) Sure, here's the function, also, is there a way to change the blip color and remove it when the ped is dead? I see nothing in the documentation, just attachBlip(). public void spawnMobileAlly() { pGroup = Player.Group; playerPos = Player.Character.Position.Around(50.0f); if (pGroup.MemberCount < 3) //if there are less than 3 members in my group then create a vehicle { veh = World.CreateVehicle("INTRUDER", playerPos); } if (pGroup.MemberCount >= 3) //if there are more than 3 members in my group do nothing and display text Game.DisplayText("Too many group members"); else //otherwise spawn 3 NPCs { for (int i = 0; i < mobilePeds.Length; i++) { if(pGroup.MemberCount <= 3) mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player); if (i == 0) mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver); else mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat); //applyGroupProperties(mobilePeds[i]); //pGroup.AddMember(mobilePeds[i]); } mobilePeds[0].Task.DriveTo(Player.Character, 250, true); } mobilePeds[0].AttachBlip(); } Edited June 21, 2014 by Noox Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 (edited) You need to have blip like Blip yea = mobilePeds[0].AttachBlip(); // not tested yea.color = BlipColor.Red; // not tested also RGB way yea.SetColorRGB(System.Drawing.Color.Moccasin); Just after reading you comment again saw that you solved your problem Regards, Paul. Edited June 21, 2014 by leftas Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 Eheh actually not, I wasn't very careful. The game was still spawning vehicles but in places I couldn't see them, I fixed it by slightly changing the conditional statement. Thanks for all the help! public void spawnMobileAlly() { pGroup = Player.Group; playerPos = Player.Character.Position.Around(10.0f); if (pGroup.MemberCount >= 3) return; veh = World.CreateVehicle("INTRUDER", playerPos); if (pGroup.MemberCount >= 3) Game.DisplayText("Too many group members"); else { for (int i = 0; i < mobilePeds.Length; i++) { if(pGroup.MemberCount <= 3) mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player); if (i == 0) mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver); else mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat); //applyGroupProperties(mobilePeds[i]); //pGroup.AddMember(mobilePeds[i]); } mobilePeds[0].Task.DriveTo(Player.Character, 250, true); } } Link to comment Share on other sites More sharing options...
PlayPrey Posted June 21, 2014 Share Posted June 21, 2014 Hey, I can actually help To force a vehicle to spawn on the road use the ' World.GetNextPositionOnStreet ' in vector3 location, an example on its use: World.CreateVehicle(World.GetNextPositionOnStreet(Player.Character.Position.Around(10.0F))); Link to comment Share on other sites More sharing options...
Jitnaught Posted June 21, 2014 Share Posted June 21, 2014 Hey, I can actually help To force a vehicle to spawn on the road use the ' World.GetNextPositionOnStreet ' in vector3 location, an example on its use: World.CreateVehicle(World.GetNextPositionOnStreet(Player.Character.Position.Around(10.0F))); I was JUST about to post this lol PlayPrey 1 Link to comment Share on other sites More sharing options...
Noox Posted June 21, 2014 Author Share Posted June 21, 2014 Hey, I can actually help To force a vehicle to spawn on the road use the ' World.GetNextPositionOnStreet ' in vector3 location, an example on its use: World.CreateVehicle(World.GetNextPositionOnStreet(Player.Character.Position.Around(10.0F))); That was very helpful! Thanks a lot, most of the time they were spawning in the roofs Link to comment Share on other sites More sharing options...
Jitnaught Posted June 21, 2014 Share Posted June 21, 2014 Sure, here's the function, also, is there a way to change the blip color and remove it when the ped is dead? I see nothing in the documentation, just attachBlip(). public void spawnMobileAlly() { pGroup = Player.Group; playerPos = Player.Character.Position.Around(50.0f); if (pGroup.MemberCount < 3) //if there are less than 3 members in my group then create a vehicle { veh = World.CreateVehicle("INTRUDER", playerPos); } if (pGroup.MemberCount >= 3) //if there are more than 3 members in my group do nothing and display text Game.DisplayText("Too many group members"); else //otherwise spawn 3 NPCs { for (int i = 0; i < mobilePeds.Length; i++) { if(pGroup.MemberCount <= 3) mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player); if (i == 0) mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver); else mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat); //applyGroupProperties(mobilePeds[i]); //pGroup.AddMember(mobilePeds[i]); } mobilePeds[0].Task.DriveTo(Player.Character, 250, true); } mobilePeds[0].AttachBlip(); } Put this in a tick to detect if any of the peds are dead, and if so, delete the blip. foreach (Ped p in mobilePeds) { if (p.isDead) { blip.Delete(); } } Also you could add this in the tick too, if you want to detect if the vehicle is alive. if (!veh.isAlive) { blip.Delete(); } leftas 1 Link to comment Share on other sites More sharing options...
leftas Posted June 21, 2014 Share Posted June 21, 2014 Sure, here's the function, also, is there a way to change the blip color and remove it when the ped is dead? I see nothing in the documentation, just attachBlip(). public void spawnMobileAlly() { pGroup = Player.Group; playerPos = Player.Character.Position.Around(50.0f); if (pGroup.MemberCount < 3) //if there are less than 3 members in my group then create a vehicle { veh = World.CreateVehicle("INTRUDER", playerPos); } if (pGroup.MemberCount >= 3) //if there are more than 3 members in my group do nothing and display text Game.DisplayText("Too many group members"); else //otherwise spawn 3 NPCs { for (int i = 0; i < mobilePeds.Length; i++) { if(pGroup.MemberCount <= 3) mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player); if (i == 0) mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver); else mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat); //applyGroupProperties(mobilePeds[i]); //pGroup.AddMember(mobilePeds[i]); } mobilePeds[0].Task.DriveTo(Player.Character, 250, true); } mobilePeds[0].AttachBlip(); } Put this in a tick to detect if any of the peds are dead, and if so, delete the blip. foreach (Ped p in mobilePeds) { if (p.isDead) { blip.Delete(); } } Also you could add this in the tick too, if you want to detect if the vehicle is alive. if (!veh.isAlive) { blip.Delete(); } Sheit, I misread that Jitnaught 1 Link to comment Share on other sites More sharing options...
Rugz007 Posted June 21, 2014 Share Posted June 21, 2014 I also did wanted the delete thing thanks letsplayordy You making progress faster Good Now i think my tutorials will come use to you 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