Hello,
I am trying to make all ambient/scenario pedestrians that spawn have certain attributes. I have spent quite a few days on this task and have come up with nothing. It is entirely possible I am overlooking something or just have not strung the right words together in my searches. I should mention that I am a novice when it comes to development so please bear with me.
So, the gist is to have a function that contains the attributes that I would like to assign to the ped. So, say I wanted to make the hillbillies spawn with extra health and unable to be headshot.
First, I would create the model list, much like you would for a model blacklist script:
crazyhillbilly = {
" a_m_m_hillbilly_01"
"a_m_m_hillbilly_02"
}
Then create the function containing the ped attributes changes:
local function makecrazy(ped)
SetEntityHealth(ped, 200)
SetPedSuffersCriticalHits(ped, false)
end
Here is the part that I can’t figure out, to apply these changes to the ambient/scenario spawns as well as scripted spawns. Basically tying the attributes to the model itself.
I have messed with ‘entityCreating’ and ‘populationPedCreating’ events, but have seem to come up empty, so there is obviously something I am doing wrong.
As I mentioned before I am a complete noob to this so any help and explanations are greatly appreciated!
Bumping so it gains some traction!
Did you ever make any progress on this?
Try iterating over all the spawned peds using IllidanS4 entity iterator and then checking if they are a certain ped model. Also, make sure to keep track of which peds you have already supped up.
I didnt try this code out, just wrote it here so I dont know how or if it will work but it should push you in the right direction!
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 EnumerateObjects()
return EnumerateEntities(FindFirstObject, FindNextObject, EndFindObject)
end
local superPedModels = [
" a_m_m_hillbilly_01"
]
iterateSpawnedPeds = function()
for ped in EnumeratePeds() do
-- check if the ped is not a player
if not IsPedAPlayer(ped) then
for i=1, #superPedModels do
if superPedModels[i] == GetEntityModel(ped) then
-- make sure to keep track of peds you supped up so you dont do it twice
SetEntityHealth(ped, 200)
SetPedSuffersCriticalHits(ped, false)
end
end
end
end
end