Hello. First of all I’m a big beginner in scripting and even bigger one in code optimizing. Is there any way I could make a table for bunch of peds so I don’t need to run seperate line for each of them?

SetPedRelationshipGroupHash(SantosGuard1, GetHashKey(“armymen”))
SetPedRelationshipGroupHash(SantosGuard2, GetHashKey(“armymen”))
SetPedRelationshipGroupHash(SantosGuard3, GetHashKey(“armymen”))
SetPedRandomComponentVariation(SantosGuard1, false)
SetPedRandomComponentVariation(SantosGuard2, false)
SetPedRandomComponentVariation(SantosGuard3, false)
GiveWeaponToPed(SantosGuard1, GetHashKey(“WEAPON_ASSAULTRIFLE”), 999, 1, 1)
GiveWeaponToPed(SantosGuard2, GetHashKey(“WEAPON_PISTOL50”), 999, 1, 1)
GiveWeaponToPed(SantosGuard3, GetHashKey(“WEAPON_PUMPSHOTGUN”), 999, 1, 1)
SetPedInfiniteAmmo(SantosGuard1, true, GetHashKey(“WEAPON_ASSAULTRIFLE”))
SetPedInfiniteAmmo(SantosGuard2, true, GetHashKey(“WEAPON_PISTOL50”))
SetPedInfiniteAmmo(SantosGuard3, true, GetHashKey(“WEAPON_PUMPSHOTGUN”))
SetPedAccuracy(SantosGuard1, 90)
SetPedAccuracy(SantosGuard2, 90)
SetPedAccuracy(SantosGuard3, 90)
SetPedArmour(SantosGuard1, 100)
SetPedArmour(SantosGuard2, 100)
SetPedArmour(SantosGuard3, 100)

I want to do something like that:

local GuardList = {
SandyZoneGuard1,
SandyZoneGuard2,
SandyZoneGuard3,
SandyZoneGuard4,
SandyZoneGuard5,
SandyZoneGuard6,
SandyZoneGuard7,
SandyZoneGuard8,
SandyZoneGuard9,
SandyZoneGuard10,
SandyZoneGuard11
}
SetPedRelationshipGroupHash(GuardList, GetHashKey(“armymen”))

You can declare a simple function to reference each time you need it, example:

function setGuardRelations(GuardList )
for key, guard in ipairs(GuardList) do -- we iterate the GuardList i forget the correct way to iterate a list with Lua, this will should be ok, note the ipairs(GuardList) edit
    SetPedRelationshipGroupHash(guard, GetHashKey(“armymen”)) -- for each Guard we set the ped relation
end
end

Then, when you want to use it, just do

setGuardRelations(GuardList)

1 Like

Hmm, something is wrong.

Upper code:

SandyZoneGuard1 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1863.8369140625, 3660.6931152344, 36.666610717773, 210.0, true, false)
SandyZoneGuard2 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1866.4075927734, 3662.1362304688, 36.666610717773, 210.0, true, false)
SandyZoneGuard3 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1869.6414794922, 3664.2055664063, 36.666610717773, 210.0, true, false)
SandyZoneGuard4 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1876.2316894531, 3668.3173828125, 36.277591705322, -60.0, true, false) – HEAVY BOI
SandyZoneGuard5 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1870.8305664063, 3680.8078613281, 36.530979156494, -80.0, true, false)
SandyZoneGuard6 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1870.5925292969, 3689.3947753906, 36.530979156494, -80.0, true, false)
SandyZoneGuard7 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1848.3670654297, 3668.7766113281, 36.50354385376, 180.0, true, false)
SandyZoneGuard8 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1843.4039306641, 3669.7106933594, 36.503551483154, 180.0, true, false)
SandyZoneGuard9 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1856.5505371094, 3657.0041503906, 36.587120056152, 120.0, true, false) – HEAVY BOI
SandyZoneGuard10 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1858.8133544922, 3687.3088378906, 34.267082214355, 120.0, true, false) – INSIDE DUDE
SandyZoneGuard11 = CreatePed(7, GetHashKey(“s_m_m_marine_01”), 1851.2963867188, 3683.5339355469, 34.267082214355, -60.0, true, false) – INSIDE DUDE
local GuardList = {
SandyZoneGuard1,
SandyZoneGuard2,
SandyZoneGuard3,
SandyZoneGuard4,
SandyZoneGuard5,
SandyZoneGuard6,
SandyZoneGuard7,
SandyZoneGuard8,
SandyZoneGuard9,
SandyZoneGuard10,
SandyZoneGuard11
}
setGuardSettings(GuardList)

Function:

function setGuardSettings(GuardList)
for key, guard in GuardList do – we iterate the GuardList
SetPedRelationshipGroupHash(guard, GetHashKey(“armymen”)) – for each Guard we set the ped relation
SetPedRandomComponentVariation(guard, false)
SetPedAccuracy(guard, 100)
SetPedSeeingRange(guard, 80.0)
SetPedHearingRange(guard, 80.0)
SetPedCombatMovement(guard, 0)
SetPedInfiniteAmmo(guard, true, GetHashKey(“WEAPON_CARBINETRIFLE”))
SetPedInfiniteAmmo(guard, true, GetHashKey(“WEAPON_SMG”))
SetPedInfiniteAmmo(guard, true, GetHashKey(“WEAPON_PISTOL50”))
SetPedInfiniteAmmo(guard, true, GetHashKey(“WEAPON_PUMPSHOTGUN”))
SetPedInfiniteAmmo(guard, true, GetHashKey(“WEAPON_HEAVYSNIPER”))
SetPedArmour(guard, 100)
SetPedSuffersCriticalHits(guard, false)
end
end

And it can’t load the settings:

Sorry i mistake, edited function:

function setGuardRelations(GuardList )
for key, guard in ipairs(GuardList) do -- we iterate the GuardList i forget the correct way to iterate a list with Lua, this will should be ok, note the ipairs(GuardList) edit
    SetPedRelationshipGroupHash(guard, GetHashKey(“armymen”)) -- for each Guard we set the ped relation
end
end

1 Like

Works like a charm. Thank you very much :blush:

1 Like