Ability to set Combat Robot speed using LuaEntity.speed

raspberrypuppies
Inserter
Inserter
Posts: 48
Joined: Tue Mar 26, 2019 4:43 am
Contact:

Ability to set Combat Robot speed using LuaEntity.speed

Post by raspberrypuppies »

TLDR: Add 'combat-robot' to LuaEntity.speed's whitelist

When combat robots spawn they slowly drift towards their Entity.orientation until they hit their leash radius. Normally, this means they slowly drift towards the right until the player moves around. The player's random motion + leash behavior causes them to orbit chaotically. But combat robots created for static entities like turrets will always drift and never act alive like they do for players. You can change the drift direction using Entity.orientation but there's no way to give them a nudge to start orbiting around. Trying to set the speed with LuaEntity.speed causes an error.


Minimum example to reproduce

data.lua

Code: Select all

local turret = data.raw['ammo-turret']['gun-turret']
turret.created_effect = {
    type = 'direct',
    action_delivery = {
        type = "instant",
        target_effects = { {
            type = "create-entity",
            entity_name = 'defender',
            show_in_tooltip = true,
            offset_deviation = { { -4, -4 }, { 4, 4 } },
            trigger_created_entity = true,
            offsets = {{0,0}}
        } },
    }
};
control.lua

Code: Select all

script.on_event(defines.events.on_script_trigger_effect,
    function(event)
        if event.entity.name == 'defender' then
            event.entity.orientation = math.random()
            --event.entity.speed = 1 -- causes an error
        end
    end)
Bilka
Factorio Staff
Factorio Staff
Posts: 3617
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Ability to set Combat Robot speed using LuaEntity.speed

Post by Bilka »

Okay, I added LuaEntity::get_movement() and set_movement() for 2.0.67.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Post Reply

Return to “Implemented mod requests”