I’m really new to all of this. Lots of programming experience, but first time with Lua, and first time hacking at GTA. I’m setting up a server for my friends and I, and just want a crazy “riot mode” server. I’ve been all over these forums, looking at the various examples, and managed to slap together this, based on a few examples I’ve seen.
I’m seeing some strange behavior. I’ve got it setup to everyone hates everyone. But, a player needs to be pretty close, within 5 meters, or a player needs to discharge a weapon, before the Peds will react or do anything. Some times I can get them started, and they keep themselves going around a busy intersection. Other times, nothing happens until a player instigates it.
I have two things I’m trying to do now.
1 - Have the peds behave aggressively all the time, without a player instigating it.
2 - Spawn more peds near players. Basically like the Script Hook based riot mode from several of the trainers.
Because I’ve seen some code shared here, here is what I’ve mangled together for my client scripting.
Config = {}
-- 0, just attack the player. 1, total chaos
Config.HostilePeds = 1
Config.RandomWeapons = {
"WEAPON_KNIFE",
"WEAPON_NIGHTSTICK",
"WEAPON_KNIFE",
"WEAPON_NIGHTSTICK",
"WEAPON_PISTOL",
"WEAPON_COMBATPISTOL",
"WEAPON_PISTOL",
"WEAPON_COMBATPISTOL",
"WEAPON_PISTOL50",
"WEAPON_MICROSMG",
"WEAPON_SMG",
"WEAPON_ASSAULTSMG",
"WEAPON_MICROSMG",
"WEAPON_SMG",
"WEAPON_ASSAULTSMG",
"WEAPON_ASSAULTRIFLE",
"WEAPON_CARBINERIFLE",
"WEAPON_ADVANCEDRIFLE",
"WEAPON_PUMPSHOTGUN",
"WEAPON_SAWNOFFSHOTGUN",
"WEAPON_SAWNOFFSHOTGUN",
"WEAPON_SAWNOFFSHOTGUN",
"WEAPON_BULLPUPSHOTGUN",
"WEAPON_SPECIALCARBINE",
"WEAPON_HEAVYPISTOL",
}
-- Experiement with Ped density. No impact.
--[[
Config.PedDensity = 1
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
SetPedDensityMultiplierThisFrame(Config.PedDensity)
SetScenarioPedDensityMultiplierThisFrame(Config.PedDensity,Config.PedDensity)
end
end)
]]--
local relationshipTypes = {
"PLAYER",
"CIVMALE",
"CIVFEMALE",
"COP",
"SECURITY_GUARD",
"PRIVATE_SECURITY",
"FIREMAN",
"GANG_1",
"GANG_2",
"GANG_9",
"GANG_10",
"AMBIENT_GANG_LOST",
"AMBIENT_GANG_MEXICAN",
"AMBIENT_GANG_FAMILY",
"AMBIENT_GANG_BALLAS",
"AMBIENT_GANG_MARABUNTE",
"AMBIENT_GANG_CULT",
"AMBIENT_GANG_SALVA",
"AMBIENT_GANG_WEICHENG",
"AMBIENT_GANG_HILLBILLY",
"DEALER",
"HATES_PLAYER",
"HEN",
"WILD_ANIMAL",
"SHARK",
"COUGAR",
"NO_RELATIONSHIP",
"SPECIAL",
"MISSION2",
"MISSION3",
"MISSION4",
"MISSION5",
"MISSION6",
"MISSION7",
"MISSION8",
"ARMY",
"GUARD_DOG",
"AGGRESSIVE_INVESTIGATE",
"MEDIC",
"CAT",
}
local RELATIONSHIP_HATE = 5
local RELATIONSHIP_COMPANION = 0
Citizen.CreateThread(function()
print('Starting Ped Loop')
while true do
Citizen.Wait(10)
for _, group in ipairs(relationshipTypes) do
SetRelationshipBetweenGroups(RELATIONSHIP_HATE, GetHashKey(group), GetHashKey('PLAYER'))
if Config.HostilePeds > 0 then
for _, group2 in ipairs(relationshipTypes) do
SetRelationshipBetweenGroups(RELATIONSHIP_HATE, GetHashKey(group), GetHashKey(group2))
SetRelationshipBetweenGroups(RELATIONSHIP_HATE, GetHashKey(group2), GetHashKey(group))
end
end
end
for Ped in EnumeratePeds() do
equipPed(Ped)
end
end
end)
function equipPed(Ped)
-- Not a human, or the player? Ignore it.
if (not IsPedHuman(Ped)) or (GetPedRelationshipGroupDefaultHash(Ped)==GetHashKey('PLAYER') or GetPedRelationshipGroupHash(Ped)==GetHashKey('PLAYER')) or (GetBestPedWeapon(Ped,0)~=GetHashKey("WEAPON_UNARMED")) then
return
end
local randomPedWeapon = Config.RandomWeapons[ math.random( #Config.RandomWeapons ) ]
SetPedCombatAttributes(Ped, 5, true)
SetPedCombatAttributes(Ped, 16, true)
SetPedCombatAttributes(Ped, 46, true)
SetPedCombatAttributes(Ped, 26, true)
SetPedCombatAttributes(Ped, 2, true)
SetPedCombatAttributes(Ped, 1, true)
SetPedDiesWhenInjured(Ped, true)
GiveWeaponToPed(Ped, GetHashKey(randomPedWeapon), 2800, false, true)
SetPedInfiniteAmmo(Ped, true, randomPedWeapon)
SetPedFleeAttributes(Ped, 0, 0)
SetPedPathAvoidFire(Ped,1)
SetPedPathCanUseLadders(Ped,1)
SetPedPathCanDropFromHeight(Ped,1)
SetPedPathCanUseClimbovers(Ped,1)
SetPedAlertness(Ped,3)
SetPedCombatRange(Ped,2)
SetPedAllowedToDuck(Ped,1)
if(randomPedWeapon == 0x42BF8A85) then
SetPedFiringPattern(Ped, 0x914E786F) --FIRING_PATTERN_BURST_FIRE_HELI
end
ResetAiWeaponDamageModifier()
SetAiWeaponDamageModifier(0.2) -- 1.0 == Normal Damage.
AddArmourToPed(Ped, 50) --<**is 100 max for npc???**
SetPedArmour(Ped, 50)
end
local entityEnumerator = {
__gc = function(enum)
if enum.destructor and enum.handle then
enum.destructor(enum.handle)
end
enum.destructor = nil
enum.handle = nil
end
}
local function EnumerateEntities(initFunc, moveFunc, disposeFunc)
return coroutine.wrap(function()
local iter, id = initFunc()
if not id or id == 0 then
disposeFunc(iter)
return
end
local enum = {handle = iter, destructor = disposeFunc}
setmetatable(enum, entityEnumerator)
local next = true
repeat
coroutine.yield(id)
next, id = moveFunc(iter)
until not next
enum.destructor, enum.handle = nil, nil
disposeFunc(iter)
end)
end
function EnumeratePeds()
return EnumerateEntities(FindFirstPed, FindNextPed, EndFindPed)
end