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

minhkhoi0975

[C#] The followers don't attack the enemies.

Recommended Posts

minhkhoi0975

Hi, I have a problem with my C# script. I wrote a script for GTA IV that makes peds on the street become my followers. However, when I am in combat with the cops or other enemies, the followers try to run away instead of helping me fight against them. Are there any ways to make my followers attack the enemies ?

Here is my source code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GTA;

namespace HoboHelper
{
public class HoboHelperScript:Script
{
Group PlayerGroup;

public HoboHelperScript()
{
PlayerGroup = Player.Group;
this.BindKey(Keys.G, new KeyPressDelegate(GetHobo));
this.Tick += new EventHandler(HoboHelper_Ticks);
}

public void HoboHelper_Ticks(object sender, EventArgs e)
{
Ped[] Pedgroup = World.GetPeds(Player.Character.Position, 3.0F);
if (Pedgroup == null) return;

foreach (Ped p in Pedgroup)
{
if (!Exists(p) || p == null) return;
if (p.RelationshipGroup == RelationshipGroup.Player) continue;

//Help a hobo.
if (PedHasModelInGroup(p, HoboModel) == true)
{
if (Player.Money < 100) return;
GiveMessage("Press G to help the tramp ($100).", 2000);
}

//Hire a criminal.
else if (PedHasModelInGroup(p, CriminalModel) == true)
{
if (Player.Money < 500) return;
GiveMessage("Press G to hire the criminal ($500).", 2000);
}
}
}

private void GetHobo()
{
Ped[] Pedgroup = World.GetPeds(Player.Character.Position, 3.0F);
if (Pedgroup == null) return;

foreach (Ped p in Pedgroup)
{
if (!Exists(p) || p == null) return;
if (p.RelationshipGroup == RelationshipGroup.Player) continue;

//Help a hobo.
if (PedHasModelInGroup(p, HoboModel) == true || p.PedType == PedType.Bum)
{
if (Player.Money < 100) return;

p.WillDoDrivebys = true;
p.AlwaysDiesOnLowHealth = true;
p.PriorityTargetForEnemies = true;
p.DuckWhenAimedAtByGroupMember = true;
p.SetPathfinding(true, true, true);

GetRandomWeapon1(p);

p.RelationshipGroup = RelationshipGroup.Player;
p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);
PlayerGroup.AddMember(p);

Player.Money -= 100;
GiveMessage("Thank you for giving me money. Let me do something for you.", 5000);
}

//Hire a criminal.
else if (PedHasModelInGroup(p, CriminalModel) == true || p.PedType == PedType.Criminal || p.PedType == PedType.Dealer)
{
if (Player.Money < 500) return;

p.WillDoDrivebys = true;
p.AlwaysDiesOnLowHealth = true;
p.PriorityTargetForEnemies = true;
p.DuckWhenAimedAtByGroupMember = true;
p.SetPathfinding(true, true, true);

GetRandomWeapon2(p);

p.RelationshipGroup = RelationshipGroup.Player;
p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);
PlayerGroup.AddMember(p);

Player.Money -= 500;
GiveMessage("Let's have some fun.", 5000);
}
}
}


private void GetRandomWeapon1(Ped p)
{

Random rd = new Random();
int WeaponChoice = rd.Next(11);

switch (WeaponChoice)
{
case 0: //The weapon the player is carrying.
Weapon weap = Player.Character.Weapons.CurrentType;
if (weap == Weapon.Unarmed) //In case the player is unarmed.
{
p.Weapons.Select(Weapon.Melee_Knife);
}
else
{
p.Weapons.FromType(weap).Ammo = 9999;
p.Weapons.Select(weap);
}
break;

case 1:
case 2: //Glock pistol.
p.Weapons.Glock.Ammo = 9999;
p.Weapons.Select(Weapon.Handgun_Glock);
break;

case 3:
case 4:
case 5:
case 6: //Baseball bat.
p.Weapons.Select(Weapon.Melee_BaseballBat);
break;

case 7:
case 8:
case 9:
case 10: //Knife.
p.Weapons.Select(Weapon.Melee_Knife);
break;
}
}
private void GetRandomWeapon2(Ped p)
{
Random rd = new Random();
int WeaponChoice = rd.Next(6);

switch (WeaponChoice)
{
case 0: //Glock
p.Weapons.Glock.Ammo = 9999;
p.Weapons.Select(Weapon.Handgun_Glock);
break;

case 1: //Desert Eagle
p.Weapons.DesertEagle.Ammo = 9999;
p.Weapons.Select(Weapon.Handgun_DesertEagle);
break;

case 2: //Uzi
p.Weapons.Uzi.Ammo = 9999;
p.Weapons.Select(Weapon.SMG_Uzi);
break;

case 3: //MP5
p.Weapons.MP5.Ammo = 9999;
p.Weapons.Select(Weapon.SMG_MP5);
break;

case 4: //AK47
p.Weapons.AssaultRifle_AK47.Ammo = 9999;
p.Weapons.Select(Weapon.Rifle_AK47);
break;

case 5: //The weapon the player is carrying
Weapon weap = Player.Character.Weapons.CurrentType;
if (weap == Weapon.Unarmed) //In case the player is unarmed.
{
p.Weapons.Select(Weapon.Melee_Knife);
}
else
{
p.Weapons.FromType(weap).Ammo = 9999;
p.Weapons.Select(weap);
}
break;
}
}

private void GiveMessage(string text, int time)
{
GTA.Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", text, time, 1);
}

private bool PedHasModelInGroup(Ped p, Model[] modelgroup)
{
for (int i=0;i<=modelgroup.Length-1;i++)
{
if (p.Model == modelgroup) return true;
}
return false;
}

Model[] HoboModel = { "M_M_CRACKHEAD", "M_M_GENBUM_01", "M_M_TRAMPBLACK" };
Model[] CriminalModel = { "M_Y_BRONX_01", "M_Y_DEALER", "M_Y_DRUG_01", "M_Y_RUNNER", "M_Y_SHADY_02" };
}
}

 

Edited by minhkhoi0975

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.


  • 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.