jstq Posted May 28, 2014 Share Posted May 28, 2014 (edited) I want to make ped use only the weapon that I gave to them. This is my code: foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup))) currentPed.ChangeRelationship(group, Relationship.Hate); currentPed.BecomeMissionCharacter(); List<GTA.Weapon> weapons = new List<GTA.Weapon>() { GTA.Weapon.Rifle_AK47, GTA.Weapon.Rifle_M4, GTA.Weapon.Shotgun_Baretta, GTA.Weapon.Shotgun_Basic, GTA.Weapon.SMG_MP5, GTA.Weapon.SMG_Uzi, GTA.Weapon.Thrown_Grenade, GTA.Weapon.Thrown_Molotov, GTA.Weapon.Handgun_Glock }; Random rnd = new Random(); GTA.Weapon randomWeapon = weapons[rnd.Next(1, weapons.Count)]; currentPed.Weapons.Select(randomWeapon); currentPed.Weapons.Current.Ammo = 500; currentPed.Weapons.Select(randomWeapon); currentPed.CowerInsteadOfFleeing = true; currentPed.Armor = 50; currentPed.CanSwitchWeapons = false; currentPed.WantedByPolice = true; currentPed.WillUseCarsInCombat = false; currentPed.Task.ClearAllImmediately(); currentPed.Task.FightAgainstHatedTargets(500f); Blip bl = currentPed.AttachBlip(); bl.Color = BlipColor.Green; gPedBlipDict.Add(currentPed, bl); break; So when I test this, ped gets selected, does a couple of shots, then switches his weapon to unarmed and starts melee with closest ped. How do I prevent this? Setting unarmed ammo to negative or zero doesnt helps. I did weapon selection twice on debug purpouse, because maybe if I set ammo for weapon ped doesnt have it have no effect. After a minute of that melee brawling, ped just starts run away scared. And how to make ped to attack cars and not exit car if shooting is happens nearby? Edited May 28, 2014 by jstq Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/ Share on other sites More sharing options...
LordOfTheBongs Posted May 28, 2014 Share Posted May 28, 2014 (edited) Try changing his relationshipgroup to one of the gangs... i think u need to mess with the DecisionMaker stuff (i never used before) to alter how he acts but i think making them a gangmember relgroup also makes them aggressive and use weapons if armed Edited May 28, 2014 by LordOfTheBongs Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065483343 Share on other sites More sharing options...
jstq Posted May 28, 2014 Author Share Posted May 28, 2014 foreach (Ped currentPed in pedsNearBy) { if (!currentPed.Exists() || currentPed == Player.Character|| !currentPed.isAliveAndWell || currentPed.isRequiredForMission) continue; else { currentPed.CowerInsteadOfFleeing = true; currentPed.WillUseCarsInCombat = true; } if (!gPedBlipDict.ContainsKey(currentPed) && !gVehBlipDict.ContainsKey(currentPed) && !currentPed.isInCombat) { foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup))) currentPed.ChangeRelationship(group, Relationship.Hate); currentPed.ChangeRelationship(RelationshipGroup.Gang_Italian,Relationship.Companion); currentPed.BecomeMissionCharacter(); GivePedRandomWeapon(currentPed); currentPed.CowerInsteadOfFleeing = true; currentPed.Armor = 50; currentPed.CanSwitchWeapons = false; currentPed.WantedByPolice = true; currentPed.WillUseCarsInCombat = false; currentPed.Task.FightAgainstHatedTargets(500f); Blip bl = currentPed.AttachBlip(); bl.Color = BlipColor.Green; gPedBlipDict.Add(currentPed, bl); break; } } private void GivePedRandomWeapon(Ped ex_Ped) { List<GTA.Weapon> weapons = new List<GTA.Weapon>() { GTA.Weapon.Rifle_AK47, GTA.Weapon.Rifle_M4, GTA.Weapon.Shotgun_Baretta, GTA.Weapon.Shotgun_Basic, GTA.Weapon.SMG_MP5, GTA.Weapon.SMG_Uzi, GTA.Weapon.Thrown_Grenade, GTA.Weapon.Thrown_Molotov, GTA.Weapon.Handgun_Glock }; Random rnd = new Random(); GTA.Weapon randomWeapon = weapons[rnd.Next(1, weapons.Count)]; ex_Ped.Weapons.Select(randomWeapon); ex_Ped.Weapons.Current.Ammo = 500; ex_Ped.Weapons.Select(randomWeapon); } just noticed how old lady gets shotgun, does 2 shots and DROP it on the ground and starts melee... WTF? And some other peds shooting fine until they die... Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065483593 Share on other sites More sharing options...
LordOfTheBongs Posted May 28, 2014 Share Posted May 28, 2014 yeah some game script is conflicting telling em to attack unarmed, u can try creating DecisionMaker objects and applying them to your ped but i never had much luck accomplishing anything Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065483882 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 Now I have another problem with armed peds.. Whenever I try they just stand still foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup))) currentPed.ChangeRelationship(group, Relationship.Hate); currentPed.RelationshipGroup = RelationshipGroup.Gang_Italian; currentPed.BecomeMissionCharacter(); GivePedRandomWeapon(currentPed); currentPed.CowerInsteadOfFleeing = true; currentPed.Armor = 50; currentPed.CanSwitchWeapons = false; currentPed.WantedByPolice = true; currentPed.WillUseCarsInCombat = true; TaskSequence ts = new TaskSequence(); ts.AddTask.FightAgainstHatedTargets(500f); ts.AddTask.FightAgainstHatedTargets(500f); ts.AddTask.FightAgainstHatedTargets(500f); currentPed.Task.PerformSequence(ts); What is wrong there and is there a way to check if ped standing still without any task? Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065487882 Share on other sites More sharing options...
Rugz007 Posted May 29, 2014 Share Posted May 29, 2014 frozen thing issue did you tried to shoot them? Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065487905 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 Tried to push them with car, they dont move untill they die. But other part of code with tasks: currentPed.BecomeMissionCharacter(); currentPed.WillUseCarsInCombat = true; TaskSequence ts = new TaskSequence(); ts.AddTask.EnterVehicle(currVeh, VehicleSeat.Driver); ts.AddTask.CruiseWithVehicle(currVeh, 250f, false); currentPed.Task.PerformSequence(ts); works fine Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065487931 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 Ped doesn't react if i aim at him and doesnt react at shooting (falls, stands up and stand still again) Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065487986 Share on other sites More sharing options...
LordOfTheBongs Posted May 29, 2014 Share Posted May 29, 2014 I heard the TaskSequence stuff was bugged but I never tested myself, just what I heard from a more experienced coder. I'm curious what you are trying to do? Is this like a riot script where all peds should be fighting? Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065488552 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 One ped should do riot thing, other should steal cars... Trying to bring some life to streets. TaskSequence ts = new TaskSequence(); ts.AddTask.FightAgainstHatedTargets(50f); ts.AddTask.Die(); currentPed.Task.PerformSequence(ts); Ped gets selected and instantly dies. I guess there is no hated targets for him in this raduis? But I saw at least one other ped nearby. Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065488630 Share on other sites More sharing options...
Rugz007 Posted May 29, 2014 Share Posted May 29, 2014 I did had that issue of frozen objects its because... Ithink.... Game loads too many scripts and it just had not enough video memory Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065488790 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 (edited) tried this sequence TaskSequence ts = new TaskSequence(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); ts.AddTask.WanderAround(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); ts.AddTask.WanderAround(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); ts.AddTask.WanderAround(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); ts.AddTask.WanderAround(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); ts.AddTask.WanderAround(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); ts.AddTask.WanderAround(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); ts.AddTask.WanderAround(); ts.AddTask.FightAgainstHatedTargets(100f, 9999999); currentPed.Task.PerformSequence(ts); ped wanders around, stops for a moment, then starts wandering again. I've shotted at him, he is just wandering after wakes up. Edited May 29, 2014 by jstq Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065488875 Share on other sites More sharing options...
LordOfTheBongs Posted May 29, 2014 Share Posted May 29, 2014 (edited) not really sure how TaskSequences work and what triggers them to know a task is completed. I wouldn't rely on it. You can manually write a sequence of tasks too and actually control how it works. im curious, the loop you do... foreach (Ped currentPed in pedsNearBy) do u just do that once? or is that in a tick and u run that loop over and over... not really sure but if u paste your whole script maybe i can test it Edited May 29, 2014 by LordOfTheBongs Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065488903 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 (edited) just a little test code http://pastebin.com/QzTQGSJD this is the only script that's connected to the game gTMAIN - creates crazy driver, works fine gTRampage -creates mad ped, doesnt works, worked yesterday. gTStealers - creates ped that steal car from street and drives away gTCleaning - cleans sh*t. Probably the source of the problem gLockCars - locks nearby cars and checks if player steals car and gives warning level gScheduledWantedLevel - adds wanted level if player doesnt get away far Edited May 29, 2014 by jstq Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489059 Share on other sites More sharing options...
LordOfTheBongs Posted May 29, 2014 Share Posted May 29, 2014 ok cool, i will give it a go in an hour or so at work now Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489140 Share on other sites More sharing options...
LordOfTheBongs Posted May 29, 2014 Share Posted May 29, 2014 (edited) i started cleaning up a little code, i do things a certain way, maybe you might like the style... also notice how i create the Random object on load... you need to do this because if u create a new Random everytime u need then it will 99.9% of the time choose the same weapon... google how the random object works... doing something like new Random.Next() will always give u same result. So create the object on load and then it will properly randomize everytime u call Also I notice u start the random at 1 instead of 0... so it will never choose the AK... you should just remove the AK from the array and start the Next() at 0 or maybe u meant to include the AK and it is just a typo... but change to... GTA.Weapon randomWeapon = weapons[rnd.Next(0, weapons.Count)]; Edited May 29, 2014 by LordOfTheBongs Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489380 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 (edited) I'm creating it once per tick, so its different. Not passing it into random weapon function is my mistake though, ty. Also, I'm always trying to minimize global variables count, which is very hard in this gta coding with those timers-oriented code style. So the weapon func should look like this private void GivePedRandomWeapon(Ped ex_Ped, Random ex_rand) { List<GTA.Weapon> weapons = new List<GTA.Weapon>() { GTA.Weapon.Rifle_AK47, GTA.Weapon.Rifle_M4, GTA.Weapon.Shotgun_Baretta, GTA.Weapon.Shotgun_Basic, GTA.Weapon.SMG_MP5, GTA.Weapon.SMG_Uzi, GTA.Weapon.Thrown_Grenade, GTA.Weapon.Thrown_Molotov, GTA.Weapon.Handgun_Glock }; GTA.Weapon randomWeapon = weapons[ex_rand.Next(1, weapons.Count)]; ex_Ped.Weapons.Current.Ammo = 500; ex_Ped.Weapons.Select(randomWeapon); }I've also saw rare unhandled exception that is probably was thrown in the only place without try block - cleaning tick Edited May 29, 2014 by jstq Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489507 Share on other sites More sharing options...
LordOfTheBongs Posted May 29, 2014 Share Posted May 29, 2014 ah cool. No problem, well it is my lunch break, ill give your script a test soon and see if i can fix anything Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489519 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 The main thing I cant fighure out is why ped looses their task to start fighting, but does other tasks fine. Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489543 Share on other sites More sharing options...
LordOfTheBongs Posted May 29, 2014 Share Posted May 29, 2014 (edited) u know what, i came to the realization i have helped u before with this... i just tried this and everyone is going crazy, u can use some ideas maybe... i wrote this a long time ago so it might need work... namespace Riot{ using System; using System.Windows.Forms; using System.Collections.Generic; using GTA; public class Main : Script { List<Ped> armedPeds; Random random; RelationshipGroup[] groups; bool toggle; public Main() { armedPeds = new List<Ped>(); groups = new RelationshipGroup[] { RelationshipGroup.Civillian_Female, RelationshipGroup.Civillian_Male, RelationshipGroup.Cop, RelationshipGroup.Fireman, RelationshipGroup.Gang_AfricanAmerican, RelationshipGroup.Gang_Albanian, RelationshipGroup.Gang_Biker1, RelationshipGroup.Gang_Biker2, RelationshipGroup.Gang_ChineseJapanese, RelationshipGroup.Gang_Irish, RelationshipGroup.Gang_Italian, RelationshipGroup.Gang_Jamaican, RelationshipGroup.Gang_Korean, RelationshipGroup.Gang_PuertoRican, RelationshipGroup.Gang_Russian1, RelationshipGroup.Gang_Russian2, RelationshipGroup.Medic, RelationshipGroup.Player }; random = new Random(); BindKey(Keys.Insert, Toggle); } private void Toggle() { toggle = !toggle; if (toggle) { Tick += Main_Tick; Game.WantedMultiplier = 0f; } else { Tick -= Main_Tick; Game.WantedMultiplier = 1f; } Game.DisplayText("Riot " + (toggle ? "En" : "Dis") + "abled"); } private void Main_Tick(object sender, EventArgs e) { CleanList(); foreach (Ped ped in World.GetPeds(Game.LocalPlayer.Character.Position, 100f)) { if (!Game.Exists(ped)) continue; if (Game.LocalPlayer.Character == ped) continue; if (!ped.isAliveAndWell) continue; if (armedPeds.Contains(ped)) continue; HateEveryone(ped); ped.BlockGestures = true; ped.BlockPermanentEvents = true; ped.Task.AlwaysKeepTask = true; ped.CanSwitchWeapons = true; ped.BecomeMissionCharacter(); if (ped.isInVehicle()) { ped.WillDoDrivebys = true; if (random.Next(0, 2) == 0) { ped.Weapons.Uzi.Ammo = 500; } else { ped.Weapons.MP5.Ammo = 500; } if (ped.CurrentVehicle.GetPedOnSeat(VehicleSeat.Driver) == ped) { ped.Task.CruiseWithVehicle(ped.CurrentVehicle, 100f, false); } else ped.Task.FightAgainstHatedTargets(100f); } else { ArmPed(ped); ped.Task.FightAgainstHatedTargets(100f); } armedPeds.Add(ped); } } private void HateEveryone(Ped ped) { foreach (RelationshipGroup group in groups) { if (ped.RelationshipGroup == RelationshipGroup.Cop && group == RelationshipGroup.Cop) continue; ped.ChangeRelationship(group, Relationship.Hate); } } private void ArmPed(Ped ped) { int selection = random.Next(0, 5); switch (selection) { case 0: if (random.Next(0, 2) == 0) { ped.Weapons.Glock.Ammo = 500; ped.Weapons.Glock.Select(); } else { ped.Weapons.DesertEagle.Ammo = 500; ped.Weapons.DesertEagle.Select(); } break; case 1: if (random.Next(0, 2) == 0) { ped.Weapons.Uzi.Ammo = 500; ped.Weapons.Uzi.Select(); } else { ped.Weapons.MP5.Ammo = 500; ped.Weapons.MP5.Select(); } break; case 2: if (random.Next(0, 2) == 0) { ped.Weapons.BasicShotgun.Ammo = 500; ped.Weapons.BasicShotgun.Select(); } else { ped.Weapons.BarettaShotgun.Ammo = 500; ped.Weapons.BarettaShotgun.Select(); } break; case 3: if (random.Next(0, 2) == 0) { ped.Weapons.AssaultRifle_AK47.Ammo = 500; ped.Weapons.AssaultRifle_AK47.Select(); } else { ped.Weapons.AssaultRifle_M4.Ammo = 500; ped.Weapons.AssaultRifle_M4.Select(); } break; case 4: if (random.Next(0, 2) == 0) { ped.Weapons.MolotovCocktails.Ammo = 500; ped.Weapons.MolotovCocktails.Select(); } else { ped.Weapons.Grenades.Ammo = 500; ped.Weapons.Grenades.Select(); } break; } } private void CleanList() { for (int i = armedPeds.Count - 1; i > -1; i--) { if (!Game.Exists(armedPeds[i])) { armedPeds.RemoveAt(i); continue; } if (!armedPeds[i].isAliveAndWell || armedPeds[i].Position.DistanceTo(Game.LocalPlayer.Character.Position) > 100f) { armedPeds[i].NoLongerNeeded(); armedPeds.RemoveAt(i); } } } }} The main thing I cant fighure out is why ped looses their task to start fighting, but does other tasks fine. i dont think u should use task sequences Edited May 29, 2014 by LordOfTheBongs Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489755 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup))) currentPed.ChangeRelationship(group, Relationship.Hate); currentPed.RelationshipGroup = RelationshipGroup.Gang_Italian; currentPed.ChangeRelationship(RelationshipGroup.Gang_Italian, Relationship.Companion); currentPed.BecomeMissionCharacter(); GivePedRandomWeapon(currentPed, rnd); currentPed.BlockGestures = true; currentPed.BlockPermanentEvents = true; currentPed.Task.AlwaysKeepTask = true; currentPed.Armor = 50; currentPed.CanSwitchWeapons = false; currentPed.WantedByPolice = true; currentPed.Task.ClearSecondary(); currentPed.Task.FightAgainstHatedTargets(100f); Blip bl = currentPed.AttachBlip(); bl.Color = BlipColor.Green; gPedBlipDict.Add(currentPed, bl); nothing changed, ped stands still. I think its something really messed up in my code because I remember that thing was worked, meh Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489871 Share on other sites More sharing options...
Rugz007 Posted May 29, 2014 Share Posted May 29, 2014 Did it worked anytime? do 1 thong remove all scripts from scripts folder and place your script only ..... I do it while testing my mods ^^ Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489891 Share on other sites More sharing options...
jstq Posted May 29, 2014 Author Share Posted May 29, 2014 does it loads only cs files? Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489918 Share on other sites More sharing options...
LordOfTheBongs Posted May 29, 2014 Share Posted May 29, 2014 yeah u can load cs files, the scripthookdotnet will compile the code before loading Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065489948 Share on other sites More sharing options...
jstq Posted May 30, 2014 Author Share Posted May 30, 2014 Deleted everything, left only this script - nothing changed. Like wtf? Peds dont react on anyting Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065494103 Share on other sites More sharing options...
Rugz007 Posted May 30, 2014 Share Posted May 30, 2014 Let ME work On It Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065494183 Share on other sites More sharing options...
Rugz007 Posted May 30, 2014 Share Posted May 30, 2014 Nothing Happens Why Dont You Contact A Guy Who Has Made A ENEMY SPAWNER thing Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065494277 Share on other sites More sharing options...
Rugz007 Posted May 30, 2014 Share Posted May 30, 2014 hey jstq i have pm you Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065494548 Share on other sites More sharing options...
jstq Posted May 30, 2014 Author Share Posted May 30, 2014 (edited) currentPed.BlockPermanentEvents = true; this sh*t was the problem now fighuring out why ped sometimes starts run away scared or stays still until pushed and then shots once, drops his weapon and starts melee Edited May 30, 2014 by jstq Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065495140 Share on other sites More sharing options...
Rugz007 Posted May 30, 2014 Share Posted May 30, 2014 -_- sh*t Link to comment https://gtaforums.com/topic/712123-how-to-stop-ped-switch-their-weapon-to-unarmed/#findComment-1065495552 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