Joe91 / fun-bots

A highly customizable and configurable bot mod for your Venice Unleashed Battlefield 3 server.
https://discord.gg/zNk3qCzk6x
231 stars 45 forks source link

Bots react to grenades #328

Open FlashHit opened 4 months ago

FlashHit commented 4 months ago

Currently bots will ignore all nades. Would be a good optional feature when they could try to run away from grenades

Joe91 commented 4 months ago

for later:

local s_GrenadeEntities = {} 
local s_GrenadeTimers = {} 

Hooks:Install('EntityFactory:Create', 1, function(hook, data, transform)
    if data:Is('GrenadeEntityData') then
        local entity = hook:Call()
        s_GrenadeEntities[entity.instanceId] = entity
        s_GrenadeTimers[entity.instanceId] = 2
    end
end)

Events:Subscribe('Engine:Update', function(dt)
    for instanceId,timer in pairs(s_GrenadeTimers) do
        s_GrenadeTimers[instanceId] = s_GrenadeTimers[instanceId] - dt
            print(timer)
        if timer <= 0 then
            print(SpatialEntity(s_GrenadeEntities[instanceId]).transform.trans)
            s_GrenadeTimers[instanceId] = nil
            s_GrenadeEntities[instanceId] = nil
        end
    end
end)