Here is a simple passenger script that does not autoteleport you if function times out and gives a chance for male passengers to fight instead of flee (also compatible with bodyguards):
using GTA;
using GTA.Math;
using GTA.Native;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PassengerScript2
{
public class PassengerScript2 : Script
{
public PassengerScript2()
{
this.Tick += new EventHandler(this.OnTick);
}
private int GetClosestVehicleSeat(Vehicle v)
{
string[] strArray = new string[6]
{
"seat_dside_f",
"seat_pside_f",
"seat_dside_r",
"seat_pside_r",
"seat_dside_r1",
"seat_pside_r1"
};
string str1 = "";
float num1 = 100f;
foreach (string str2 in strArray)
{
int num2 = Function.Call<int>(Hash._0xFB71170B7E76ACBA, (InputArgument)v, (InputArgument)str2);
if (num2 != -1)
{
float num3 = Vector3.Distance(Function.Call<Vector3>(Hash._0x44A8FCB8ED227738, (InputArgument)v, (InputArgument)num2), Game.Player.Character.Position);
if ((double)num3 < (double)num1)
{
num1 = num3;
str1 = str2;
}
}
}
if ((double)num1 <= 10.0)
{
if (str1 == "seat_dside_f")
return -1;
if (str1 == "seat_pside_f")
return 0;
if (str1 == "seat_pside_r")
return 2;
if (str1 == "seat_dside_r")
return 1;
if (str1 == "seat_dside_r1")
return 3;
if (str1 == "seat_pside_r1")
return 4;
}
return -3;
}
private Vehicle GetClosestVehicle(float dist)
{
Vehicle[] allVehicles = World.GetAllVehicles();
float num1 = dist + 100f;
Vehicle vehicle1 = (Vehicle)null;
foreach (Vehicle vehicle2 in allVehicles)
{
float num2 = Vector3.Distance(Game.Player.Character.Position, vehicle2.Position);
if ((double)num2 < (double)num1)
{
vehicle1 = vehicle2;
num1 = num2;
}
}
if ((double)num1 <= (double)dist)
return vehicle1;
return (Vehicle)null;
}
private void PedReaction()
{
if (Helper.GET_MISSION_FLAG())
return;
if (Game.Player.IsPlaying && Game.Player.Character.IsInVehicle() && (!Helper.PED_IS_POLICE_FORCE(Game.Player.Character)) && !Helper.IS_PED_IN_ANY_TAXI(Game.Player.Character))
foreach (Ped ped in ((IEnumerable<Ped>)World.GetNearbyPeds(Game.Player.Character, 1)).ToList<Ped>().ToArray())
{
if (!Helper.PED_IS_POLICE_FORCE(ped))
{
int BodyGuardCheck = Helper.GET_PLAYER_GROUP(Game.Player);
if (ped.IsAlive && ped.IsHuman && ped.IsInVehicle() && (!Helper.IS_PED_IN_ANY_TAXI(ped)) && (!Helper.IS_PED_FLEEING(ped) && !ped.IsShooting) && (!ped.IsReloading && !ped.IsRagdoll && (!ped.IsGettingIntoAVehicle && !ped.IsGettingUp)) && (!ped.IsInCombat && ped.IsVisible) && !ped.IsInMeleeCombat)
{
if (!Helper.IS_PED_IN_GROUP(ped, BodyGuardCheck))
switch (ped.GetRelationshipWithPed(Game.Player.Character))
{
case Relationship.Pedestrians:
if (ped.Model == new Model(PedHash.Bouncer01SMM) && ped.IsAlive)
return;
Vehicle JackedVehicle = Game.Player.LastVehicle;
Random random = new Random();
Ped driver = ped.CurrentVehicle.Driver;
Ped targetedEntity = Game.Player.GetTargetedEntity() as Ped;
ped.Task.ClearAll();
if (ped.Gender == Gender.Male)
{
int num1 = random.Next(1, 8);
if (num1 >= 2)
{
ped.Task.FightAgainst(Game.Player.Character);
}
else
ped.Task.FleeFrom(Game.Player.Character);
}
else
{
ped.Task.FleeFrom(Game.Player.Character);
}
/* if ((Helper.IS_PLAYER_FREE_AIMING_AT_ENTITY(Game.Player, driver)) && (Function.Call<bool>(Hash._0x5E346D934122613F)) && JackedVehicle.Driver.Exists())
{
Function.Call(Hash._0x90D2156198831D69, (InputArgument)JackedVehicle.Driver, (InputArgument)true);
driver.BlockPermanentEvents = true;
driver.Task.DriveTo(driver.CurrentVehicle, World.GetWaypointPosition(), 10f, 45, 1074528293);
UI.ShowSubtitle("Driving to waypoint", 2000);
} */
break;
}
}
}
}
}
private void OnTick(object sender, EventArgs e)
{
PedReaction();
if (!Game.IsControlJustPressed(0, GTA.Control.Enter))
return;
if (!Function.Call<bool>(Hash._0x997ABD671D25CA0B, (InputArgument)Game.Player.Character, (InputArgument)false))
{
if (Function.Call<bool>(Hash._0xBB062B2B5722478E, (InputArgument)Game.Player.Character))
{
Function.Call(Hash._0xE1EF3C1216AFF2CD, (InputArgument)Game.Player.Character);
}
else
{
Vehicle closestVehicle = this.GetClosestVehicle(10f);
if ((Entity)closestVehicle != (Entity)null)
{
bool flag = Function.Call<bool>(Hash._0xC5286FFC176F28A2, (InputArgument)Game.Player.Character);
int closestVehicleSeat = this.GetClosestVehicleSeat(closestVehicle);
if (closestVehicleSeat == -3 || closestVehicleSeat == -1)
return;
if (flag)
{
Function.Call(Hash._0xC20E50AA46D09CA8, (InputArgument)Game.Player.Character, (InputArgument)closestVehicle, (InputArgument)9000, (InputArgument)closestVehicleSeat, (InputArgument)2f, (InputArgument)1, (InputArgument)0);
Wait(4000);
if (!Function.Call<bool>(Hash._0xA3EE4A07279BB9DB, (InputArgument)Game.Player.Character, (InputArgument)closestVehicle, false))
{
Function.Call(Hash._0xE1EF3C1216AFF2CD, (InputArgument)Game.Player.Character);
}
}
else
{
Function.Call(Hash._0xC20E50AA46D09CA8, (InputArgument)Game.Player.Character, (InputArgument)closestVehicle, (InputArgument)9000, (InputArgument)closestVehicleSeat, (InputArgument)1f, (InputArgument)1, (InputArgument)0);
Wait(4000);
if (!Function.Call<bool>(Hash._0xA3EE4A07279BB9DB, (InputArgument)Game.Player.Character, (InputArgument)closestVehicle, false))
{
Function.Call(Hash._0xE1EF3C1216AFF2CD, (InputArgument)Game.Player.Character);
}
}
}
}
}
}
public static class Helper
{
public static void PRINT_MODEL_NEAREST_PED()
{
Ped[] nearbyPeds = World.GetNearbyPeds(Game.Player.Character, 5f);
string str;
if (nearbyPeds != null)
{
str = "";
foreach (Ped ped in nearbyPeds)
{
if ((double)ped.Position.DistanceTo(Game.Player.Character.Position) < 1.5)
str = ped.Model.Hash.ToString();
}
}
else
str = "Unavailable";
bool flag = false;
Function.Call(Hash._0x66E0276CC5F6B9DA, (InputArgument)0);
Function.Call(Hash._0x07C837F9A01C34C9, (InputArgument)0.55f, (InputArgument)0.55f);
Function.Call(Hash._0xBE6B23FFA53FB442, (InputArgument)((int)byte.MaxValue), (InputArgument)((int)byte.MaxValue), (InputArgument)((int)byte.MaxValue), (InputArgument)((int)byte.MaxValue));
Function.Call(Hash._0x63145D9C883A1A70, (InputArgument)0.0f, (InputArgument)1f);
Function.Call(Hash._0xC02F4DBFB51D988B, (InputArgument)0);
Function.Call(Hash._0x465C84BC39F1C351, (InputArgument)0, (InputArgument)0, (InputArgument)0, (InputArgument)0, (InputArgument)0);
Function.Call(Hash._0x441603240D202FA6, (InputArgument)1, (InputArgument)0, (InputArgument)0, (InputArgument)0, (InputArgument)205);
if (flag)
{
Function.Call(Hash._0x25FBB336DF1804CB, (InputArgument)str);
}
else
{
Function.Call(Hash._0x25FBB336DF1804CB, (InputArgument)"STRING");
Function.Call(Hash._0x6C188BE134E074AA, (InputArgument)str);
}
Function.Call(Hash._0xCD015E5BB0D96A57, (InputArgument)0.5f, (InputArgument)0.5f);
}
public static List<long> GET_FIREARM()
{
return new List<long>()
{
2937143193L,
584646201L,
3220176749L,
3800352039L,
4024951519L,
2132975508L,
2640438543L,
2210333304L,
2144741730L,
171789620L,
1593441988L,
2726580491L,
1305664598L,
1627465347L,
3523564046L,
984333226L,
205991906L,
1672152130L,
3342088282L,
2634544996L,
324215364L,
1119849093L,
2828843422L,
453432689L,
2578377531L,
487013001L,
1834241177L,
2982836145L,
2017895192L,
736523883L,
100416529L,
3218215474L,
3231910285L,
911657153L,
137902532L
};
}
public static List<long> GET_NON_FIREARM()
{
return new List<long>()
{
2508868239L,
2694266206L,
2227010557L,
2460120199L,
101631238L,
2138347493L,
1141786504L,
1317494643L,
4191993645L,
2578778090L,
1737195953L,
883325847L,
126349499L,
2725352035L
};
}
public static List<long> GET_POLICE_PED_MODELS()
{
return new List<long>()
{
368603149L,
1581098148L,
2595446627L,
4074414829L,
1702441027L,
4028996995L,
1490458366L,
1925237458L,
2374966032L
};
}
public static List<long> GET_SUPPORT_PED_MODELS()
{
return new List<long>() { 3008586398L, 3613962792L };
}
public static List<long> GET_POLICE_VEHICLE_MODELS()
{
return new List<long>()
{
2046537925L,
2667966721L,
1912215274L,
2321795001L,
4260343491L,
2758042359L,
2515846680L,
456714581L
};
}
public static bool PED_IS_POLICE_FORCE(Ped ped)
{
return Helper.GET_POLICE_PED_MODELS().Contains((long)ped.Model.Hash);
}
public static bool PED_IS_SUPPORT_FORCE(Ped ped)
{
return Helper.GET_SUPPORT_PED_MODELS().Contains((long)ped.Model.Hash);
}
public static bool VEHICLE_IS_POLICE_FORCE(Vehicle vehicle)
{
return Helper.GET_POLICE_VEHICLE_MODELS().Contains((long)vehicle.Model.Hash);
}
public static bool PED_IS_ARMED(Ped ped)
{
return ped.Weapons.Current.IsPresent && ped.Weapons.Current.Hash != WeaponHash.Unarmed;
}
public static bool WEAPON_IS_FIREARM(WeaponHash weaponHash)
{
return Helper.GET_FIREARM().Contains((long)weaponHash);
}
public static bool GET_MISSION_FLAG()
{
return Function.Call<bool>(Hash._0xA33CDCCDA663159E, new InputArgument[0]);
}
public static Hash GET_HASH_KEY(string name)
{
return Function.Call<Hash>(Hash._0xD24D37CC275948CC, (InputArgument)name);
}
public static void SET_ENTITY_MAX_SPEED(Entity entity, float maxSpeed = 1f)
{
Function.Call(Hash._0x0E46A3FCBDE2A1B1, (InputArgument)entity, (InputArgument)maxSpeed);
}
public static bool IS_PED_FACING_PED(Ped ped1, Ped ped2, float angle)
{
return Function.Call<bool>(Hash._0xD71649DB0A545AA3, (InputArgument)ped1, (InputArgument)ped2, (InputArgument)angle);
}
public static bool IS_PED_IN_ANY_TAXI(Ped ped)
{
return Function.Call<bool>(Hash._0x6E575D6A898AB852, (InputArgument)ped);
}
public static void CLEAR_PED_TASKS(Ped ped)
{
Function.Call(Hash._0xE1EF3C1216AFF2CD);
}
public static bool IS_PED_IN_VEHICLE(Ped ped, Vehicle vehicle)
{
return Function.Call<bool>(Hash._0xA3EE4A07279BB9DB);
}
public static bool IS_PED_FLEEING(Ped ped)
{
return Function.Call<bool>(Hash._0xBBCCE00B381F8482, new InputArgument(ped));
}
public static bool HAS_ENTITY_CLEAR_LOS_TO_ENTITY(Entity entity1, Entity entity2)
{
return Function.Call<bool>(Hash._0xFCDFF7B72D23A1AC, (InputArgument)entity1, (InputArgument)entity2, (InputArgument)17);
}
public static bool HAS_ENTITY_CLEAR_LOS_TO_ENTITY_IN_FRONT(Entity entity1, Entity entity2)
{
return Function.Call<bool>(Hash._0x0267D00AF114F17A, (InputArgument)entity1, (InputArgument)entity2);
}
public static bool IS_PLAYER_FREE_AIMING_AT_ENTITY(Player player, Entity driver)
{
return Function.Call<bool>(Hash._0x3C06B5C839B38F7B, (InputArgument)Game.Player.Character, (InputArgument)driver);
}
public static bool IS_VEHICLE_A_CONVERTIBLE(Vehicle closestVehicle)
{
return Function.Call<bool>(Hash._0x52F357A30698BCCE, (InputArgument)closestVehicle);
}
public static int GET_PLAYER_GROUP(Player player)
{
return Function.Call<int>(Hash._0x0D127585F77030AF, (InputArgument)Game.Player);
}
public static bool IS_PED_IN_GROUP(Ped ped, int groupId)
{
return Function.Call<bool>(Hash._0x5891CAC5D4ACFF74, (InputArgument)ped, (InputArgument)groupId);
}
}
}
}