So I ended up writing a lot more code than I wanted but this is what I came up with as an example of a simple mission generator.
__resource.lua
--[[
Scripted By: Xander1998 (X. Cross)
--]]
resource_manifest_version '05cfa83c-a124-4cfa-a768-c24a5811d8f9'
client_script "client.lua"
client.lua
local activeMissions = {}
local missions = {
-- Mission One [Example Mission]
{
spawns = {
{
x = 1994.93,
y = 3052.98,
z = 47.21,
models = {
"U_M_Y_Zombie_01"
}
},
{
x = 1989.5758056641,
y = 3055.4487304688,
z = 47.215156555176,
models = {
"U_M_Y_Zombie_01"
}
}
}
},
-- Mission Two [Example Extra Mission | No different than mission one]
{
spawns = {
{
x = 1994.93,
y = 3052.98,
z = 47.21,
models = {
"U_M_Y_Zombie_01"
}
},
{
x = 1989.5758056641,
y = 3055.4487304688,
z = 47.215156555176,
models = {
"U_M_Y_Zombie_01"
}
}
}
}
}
RegisterCommand("goto", function(source, args, raw)
local missionId = tonumber(args[1])
if missionId == nil then return end
if missions[missionId] == nil then return end
local mission = missions[missionId]
SetEntityCoords(GetPlayerPed(-1), mission.spawns[1].x, mission.spawns[1].y, mission.spawns[1].z, 0.0, 0.0, 0.0, false)
end, false)
RegisterCommand("mission", function(source, args, raw)
local missionId = tonumber(args[1])
if missionId == nil then return end
if missions[missionId] == nil then return end
local activationId = #activeMissions + 1
local method = CreateMission(missionId, activationId)
table.insert(activeMissions, activationId)
Citizen.CreateThread(method)
end, false)
function CreateMission(mission_id, activationId)
local selectedMission = missions[mission_id]
local trackedPeds = {}
-- Get Alive Zombies
local function getZombiesAlive()
local alive = 0
for a = 1, #trackedPeds do
if not IsEntityDead(trackedPeds[a]) then
alive = alive + 1
end
end
return alive
end
-- Cleanup Zombies
local function cleanupZombies()
for a = 1, #trackedPeds do
DeleteEntity(trackedPeds[a])
end
end
-- if mission doesn't exist... Don't run...
if selectedMission == nil then print("Mission Invalid.. Canceling...") return end
-- Spawn Zombies
for a = 1, #selectedMission.spawns do
local spawn = selectedMission.spawns[a]
math.randomseed(GetGameTimer())
local pedModel = spawn.models[math.random(1, #spawn.models)]
-- Load Model
RequestModel(pedModel)
while not HasModelLoaded(pedModel) do
Citizen.Wait(0)
end
local createdZombie = CreatePed(5, GetHashKey(pedModel), spawn.x, spawn.y, spawn.z, math.random(0, 359), true, false)
SetZombieAttributes(createdZombie)
table.insert(trackedPeds, createdZombie)
end
while true do
local aliveLeft = getZombiesAlive()
-- Mission Success Ended
if aliveLeft == 0 then
print("Mission Success!")
cleanupZombies()
Citizen.RemoveThread(activeMissions[activationId])
end
-- Mission Failed Ended
if IsEntityDead(GetPlayerPed(-1)) then
print("Mission Failed!")
cleanupZombies()
Citizen.RemoveThread(activeMissions[activationId])
end
Citizen.Wait(0)
end
end
function SetZombieAttributes(zombie)
SetPedRelationshipGroupHash(zombie, GetHashKey("zombeez"))
SetPedArmour(zombie, 100)
SetPedAccuracy(zombie, 25)
SetPedSeeingRange(zombie, 100.0)
SetPedHearingRange(zombie, 100.0)
SetPedFleeAttributes(zombie, 0, 0)
SetPedCombatAttributes(zombie, 16, 1)
SetPedCombatAttributes(zombie, 17, 0)
SetPedCombatAttributes(zombie, 46, 1)
SetPedCombatAttributes(zombie, 1424, 0)
SetPedCombatAttributes(zombie, 5, 1)
SetPedCombatRange(zombie,2)
SetAmbientVoiceName(zombie, "ALIENS")
SetPedEnableWeaponBlocking(zombie, true)
DisablePedPainAudio(zombie, true)
SetPedDiesInWater(zombie, false)
SetPedDiesWhenInjured(zombie, false)
RequestAnimSet("move_m@drunk@verydrunk")
while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
Wait(1)
end
SetPedMovementClipset(zombie, "move_m@drunk@verydrunk", 1.0)
ApplyPedDamagePack(zombie,"BigHitByVehicle", 0.0, 9.0)
ApplyPedDamagePack(zombie,"SCR_Dumpster", 0.0, 9.0)
ApplyPedDamagePack(zombie,"SCR_Torture", 0.0, 9.0)
StopPedSpeaking(zombie, true)
SetAiMeleeWeaponDamageModifier(10000)
end