Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
jstq

How to stop ped switch their weapon to unarmed

Recommended Posts

jstq

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 by jstq

Share this post


Link to post
Share on other sites
LordOfTheBongs

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 by LordOfTheBongs

Share this post


Link to post
Share on other sites
jstq
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...

Share this post


Link to post
Share on other sites
LordOfTheBongs

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

Share this post


Link to post
Share on other sites
jstq

Now I have another problem with armed peds..

LQrilDW.jpg

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?

Share this post


Link to post
Share on other sites
Rugz007

frozen thing issue did you tried to shoot them?

Share this post


Link to post
Share on other sites
jstq

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

Share this post


Link to post
Share on other sites
jstq

Ped doesn't react if i aim at him and doesnt react at shooting (falls, stands up and stand still again)

Share this post


Link to post
Share on other sites
LordOfTheBongs

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?

Share this post


Link to post
Share on other sites
jstq

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.

Share this post


Link to post
Share on other sites
Rugz007

I did had that issue of frozen objects its because... Ithink.... Game loads too many scripts and it just had not enough video memory

Share this post


Link to post
Share on other sites
jstq

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 by jstq

Share this post


Link to post
Share on other sites
LordOfTheBongs

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 by LordOfTheBongs

Share this post


Link to post
Share on other sites
jstq

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 by jstq

Share this post


Link to post
Share on other sites
LordOfTheBongs

ok cool, i will give it a go in an hour or so ;)

 

at work now :*(

Share this post


Link to post
Share on other sites
LordOfTheBongs

uJmeCYm.png

 

mVedMMw.png

 

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 by LordOfTheBongs

Share this post


Link to post
Share on other sites
jstq

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 by jstq

Share this post


Link to post
Share on other sites
LordOfTheBongs

ah cool. No problem, well it is my lunch break, ill give your script a test soon and see if i can fix anything

Share this post


Link to post
Share on other sites
jstq

The main thing I cant fighure out is why ped looses their task to start fighting, but does other tasks fine.

Share this post


Link to post
Share on other sites
LordOfTheBongs

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 by LordOfTheBongs

Share this post


Link to post
Share on other sites
jstq
 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

Share this post


Link to post
Share on other sites
Rugz007

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 ^^

Share this post


Link to post
Share on other sites
jstq

does it loads only cs files?

Share this post


Link to post
Share on other sites
LordOfTheBongs

yeah u can load cs files, the scripthookdotnet will compile the code before loading

Share this post


Link to post
Share on other sites
jstq

Deleted everything, left only this script - nothing changed. Like wtf? Peds dont react on anyting

Share this post


Link to post
Share on other sites
Rugz007

Let ME work On It :D

Share this post


Link to post
Share on other sites
Rugz007

Nothing Happens :/ Why Dont You Contact A Guy Who Has Made A ENEMY SPAWNER thing :D

Share this post


Link to post
Share on other sites
Rugz007

hey jstq i have pm you

Share this post


Link to post
Share on other sites
jstq

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 by jstq

Share this post


Link to post
Share on other sites
Rugz007

-_- sh*t

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.