here’s the mission’s cs file:
using CitizenFX.Core;
using CitizenFX.Core.Native;
using CitizenFX.Core.UI;
using Freeroam.Utils;
using System;
using System.Threading.Tasks;
namespace Freeroam.Missions
{
internal class Gang46
{
public Ped targetPed;
public Ped[] bodyguards;
public Gang46(Ped targetPed, Ped[] bodyguards)
{
this.targetPed = targetPed;
this.bodyguards = bodyguards;
}
}
class GangFight46 : IMission
{
private static Vector3[] targetSpawns = new Vector3[]
{
new Vector3(3800.76f, 4475.42f, 5.99f),
new Vector3(3817.35f, 4482.64f, 6.17f),
new Vector3(3822.63f, 4467.38f, 3.16f),
new Vector3(3865.33f, 4463.55f, 2.72f),
new Vector3(3818.56f, 4441.96f, 2.81f),
new Vector3(3811.93f, 4447.48f, 3.56f),
new Vector3(3800.64f, 4441.82f, 4.25f),
new Vector3(3824.62f, 4474.13f, 5.16f),
new Vector3(3812.00f, 4490.71f, 5.99f)
};
private Gang46[] targets = new Gang46[9];
private bool enableTick = false;
public async void Start()
{
Random random = new Random();
for (int i = 0; i < targets.Length; i++)
{
Ped targetPed = await Util.CreatePed(PedHash.Gaffer01SMM, targetSpawns[i]);
targetPed.Weapons.Give(WeaponHash.CarbineRifle, int.MaxValue, true, true);
targetPed.Task.StartScenario("WORLD_HUMAN_AA_SMOKE", targetPed.Position);
Ped[] bodyguards = await SpawnBodyguards(targetPed, random.Next(0, 0));
Function.Call(Hash.FLASH_MINIMAP_DISPLAY);
Blip blip = targetPed.AttachBlip();
blip.Sprite = BlipSprite.Enemy;
blip.Color = BlipColor.TrevorOrange;
blip.Name = Strings.MISSIONS_GANGFIGHT46_BLIP;
blip.Scale = 0.8f;
targets[i] = new Gang46(targetPed, bodyguards);
}
Util.DisplayHelpText(Strings.MISSIONS_GANGFIGHT46_INFO);
Screen.ShowSubtitle(Strings.MISSIONS_GANGFIGHT46_START, 15000);
enableTick = true;
}
public void Stop(bool success)
{
if (!success)
{
foreach (Gang46 target in targets)
{
if (target != null)
{
DespawnTargetSquad(target);
}
}
}
else
{
Screen.ShowNotification(Strings.MISSIONS_GANGFIGHT46_ALLTARGETSKILLED);
//BaseScript.TriggerEvent(Events.MONEY_ADD, 5000);
//BaseScript.TriggerEvent(xPlayer.addMoney(5000));
BaseScript.TriggerServerEvent("makepmnt", 5000);
//xPlayer.addMoney(5000);
BaseScript.TriggerEvent(Events.XP_ADD, 30);
}
}
public async Task Tick()
{
if (enableTick)
{
Ped playerPed = Game.PlayerPed;
if (Game.Player.WantedLevel > 0) Game.Player.WantedLevel = 0;
if (playerPed.IsDead)
{
BaseScript.TriggerEvent(Events.MISSION_STOP, false);
enableTick = false;
}
else
{
int livingTargets = 0;
for (int i = targets.Length - 1; i > -1; i--)
{
if (targets[i] != null)
{
if (!targets[i].targetPed.IsDead) livingTargets++;
else
{
Entity killer = targets[i].targetPed.GetKiller();
if (killer == playerPed)
{
//if (Game.Player.WantedLevel < 3) Game.Player.WantedLevel = 3;
}
DespawnTargetSquad(targets[i]);
targets[i] = null;
}
}
}
if (livingTargets == 0) BaseScript.TriggerEvent(Events.MISSION_STOP, true);
}
}
await Task.FromResult(0);
}
private async Task<Ped[]> SpawnBodyguards(Ped targetPed, int amount)
{
PedGroup group = new PedGroup();
group.Add(targetPed, true);
group.FormationType = FormationType.Default;
group.SeparationRange = 1f;
RelationshipGroup relationship = World.AddRelationshipGroup("_ASSASSIN_TARGETS");
relationship.SetRelationshipBetweenGroups(new RelationshipGroup(Util.GetHashKey("COP")), Relationship.Respect, true);
relationship.SetRelationshipBetweenGroups(new RelationshipGroup(Util.GetHashKey("SECURITY_GUARD")), Relationship.Respect, true);
targetPed.RelationshipGroup = relationship;
Random random = new Random();
Ped[] bodyguards = new Ped[amount];
for (int i = 0; i < amount; i++)
{
float x = Util.GetRandomFloat(random, -2, 2);
float y = Util.GetRandomFloat(random, -2, 2);
Vector3 spawnPos = targetPed.GetOffsetPosition(new Vector3(x, y, 0f));
Ped bodyguard = await Util.CreatePed(PedHash.FibOffice01SMM, spawnPos);
bodyguard.Armor = 300;
bodyguard.Weapons.Give(WeaponHash.CarbineRifle, int.MaxValue, true, true);
bodyguard.RelationshipGroup = new RelationshipGroup(Util.GetHashKey("SECURITY_GUARD"));
group.Add(bodyguard, false);
bodyguards[i] = bodyguard;
}
return bodyguards;
}
private void DespawnTargetSquad(Gang46 target)
{
target.targetPed.AttachedBlip.Delete();
target.targetPed.MarkAsNoLongerNeeded();
foreach (Ped bodyguard in target.bodyguards) bodyguard.MarkAsNoLongerNeeded();
}
}
}
In that file, starting at line 81, you can see where I start trying different things:
Screen.ShowNotification(Strings.MISSIONS_GANGFIGHT46_ALLTARGETSKILLED);
//BaseScript.TriggerEvent(Events.MONEY_ADD, 5000);
//BaseScript.TriggerEvent(xPlayer.addMoney(5000));
BaseScript.TriggerServerEvent("makepmnt", 5000);
//xPlayer.addMoney(5000);
BaseScript.TriggerEvent(Events.XP_ADD, 30);
During my searches and forum topics, I was directed toward calling a lua function, so my alteration to the .cs file is this:
Comment his line:
BaseScript.TriggerEvent(Events.MONEY_ADD, 5000);
And add my line:
BaseScript.TriggerServerEvent("makepmnt", 5000);
and in server/main.lua, I’ve got this:
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent("makepmnt")
AddEventHandler("makepmnt", function(amnt)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.addMoney(amnt)
end)
and just in case it’s important, my _resource.lua:
resource_manifest_version 'f15e72ec-3972-4fe4-9c7d-afc5394ae207'
client_scripts {
"client/main.lua",
"nativeui.net.dll",
"Freeroam.net.dll",
}
server_scripts {
"server/main.lua",
"server/missions.lua",
"server/notifications.lua"
}
So, all I’ve done so far is to comment his payment line out and add mine in the .cs file and to register the server event in my server LUA script.