ight so idk how to code but I had an idea of a script so I asked chatgpt to write a c# gta 5 mod hitman script that when you press the key F2 it spawns a random gang member (not a families member) with a combat pistol and with a player blip at a random location not too far away prompting the player to kill the gang member. also, show a notification saying what gang member it is. once the gang member has been killed the player will be rewarded a random payment from $500 to $1500 but ofc it doesnt work.
could anyone help me fix he following code?
using GTA;
using GTA.Native;
using GTA.Math;
using System;
public class HitmanScript : Script
{
private bool isMissionRunning;
private Ped targetPed;
private Blip targetBlip;
private int rewardAmount;
private readonly Random rand = new Random();
public HitmanScript()
{
// Register the key F2 to start the mission
KeyDown += OnKeyDown;
// Set the update interval to 1000 milliseconds (1 second)
Tick += OnTick;
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
// Check if the mission is not running and the F2 key was pressed
if (!isMissionRunning && e.KeyCode == Keys.F2)
{
// Spawn a random gang member with a combat pistol
targetPed = World.CreateRandomPed(new Model(GangMember()), GetRandomLocation());
targetPed.Weapons.Give(WeaponHash.CombatPistol, 100, true, true);
// Create a blip for the target ped
targetBlip = targetPed.AddBlip();
targetBlip.Color = BlipColor.Red;
targetBlip.Scale = 0.8f;
// Show a notification with the gang member's name
UI.Notify($"Your target is a {GangMember()}. Eliminate them!");
// Set the mission as running
isMissionRunning = true;
}
}
private void OnTick(object sender, EventArgs e)
{
// Check if the mission is running and the target ped is alive
if (isMissionRunning && targetPed != null && targetPed.IsAlive)
{
// Check if the player is near the target ped
if (Game.Player.Character.Position.DistanceTo(targetPed.Position) < 15f)
{
// Show a notification to prompt the player to kill the target
UI.ShowSubtitle($"Press E to eliminate the {GangMember()}");
// Check if the player pressed the E key
if (Game.IsControlJustPressed(0, Control.Context))
{
// Eliminate the target ped
targetPed.Kill();
// Remove the blip from the map
targetBlip.Remove();
// Calculate the reward amount (random value between $500 and $1500)
rewardAmount = rand.Next(500, 1501);
// Show a notification with the reward amount
UI.Notify($"You eliminated a {GangMember()} and earned ${rewardAmount}!");
// Set the mission as not running
isMissionRunning = false;
}
}
}
}
private string GangMember()
{
// Define an array of gang members (not including families)
string[] gangMembers = { "Ballas", "Vagos", "Aztecas", "Triads", "Mafia" };
// Get a random index from the array
int randomIndex = rand.Next(gangMembers.Length);
// Return the gang member at the random index
return gangMembers[randomIndex];
}
private Vector3 GetRandomLocation()
{
// Get a random location within a 300 meter radius from the player's position
Vector3 randomLocation = Game.Player.Character.Position.Around(300f);
// Get the ground
randomLocation = World.GetGroundHeight(randomLocation);
// Return the random location
return randomLocation;
}
}