Search found 15 matches

by KoRaLLL
Thu Jan 19, 2023 8:37 am
Forum: Modding help
Topic: Check whether an entity has power?
Replies: 4
Views: 1256

Re: Check whether an entity has power?



You say to listen to the build/destroy events..but what about in cases where a boiler runs out of fuel? Nothing has been built/destroyed, but power has been lost, and in this event I'd like to trigger my function, but as far as I'm aware there's no events related to the loss of power.


That's ...
by KoRaLLL
Thu Jan 19, 2023 7:37 am
Forum: Modding help
Topic: Check whether an entity has power?
Replies: 4
Views: 1256

Re: Check whether an entity has power?


There two main ways you can optimise this loop:

- Most important, don't find_entities every time. Rather listen to build/destroy events and with that keep a list in global of all the entities you want to check. Then loop through that list. This is typically called caching.
- You can limit the ...
by KoRaLLL
Wed Jan 18, 2023 2:20 pm
Forum: Modding help
Topic: Check whether an entity has power?
Replies: 4
Views: 1256

Check whether an entity has power?

Hey all!

Just a quick question, I have the below function for checking whether or not an entity that resides in a specific type has power or not.

The function of this is that, if this entity doesn't have power, it explodes.

function check_power(event)

-- Check every second --
if event.tick ...
by KoRaLLL
Sun Jan 08, 2023 3:31 pm
Forum: Modding help
Topic: Any way to programatically generate localised names?
Replies: 5
Views: 1737

Any way to programatically generate localised names?

Hi all, I hope everyone is having a great start to the year!

I'm currently working on a project that takes both default and modded entities and manipulates them in various ways, turning some of them into other entities.

I'm running into the issue of trying to localise names programatically. Adding ...
by KoRaLLL
Wed Jan 04, 2023 1:37 pm
Forum: Modding help
Topic: Is there a trigger or variable for the 'highlighting' of certain entities?
Replies: 10
Views: 2486

Re: Is there a trigger or variable for the 'highlighting' of certain entities?



But with a custom entity I've created, for storage boxes. So that when I'm holding a storage box, it will highlight the radius of my custom entity (which has a type of 'beacon'), and then highlight the beacon when it's within the beacon's supply area.

Is this do-able? Or is this hard-coded to ...
by KoRaLLL
Wed Jan 04, 2023 1:05 pm
Forum: Modding help
Topic: Is there a trigger or variable for the 'highlighting' of certain entities?
Replies: 10
Views: 2486

Re: Is there a trigger or variable for the 'highlighting' of certain entities?

Haha wow I didn't expect so much support and traction so quickly :shock: , thank you so much everyone :D
by KoRaLLL
Wed Jan 04, 2023 12:33 pm
Forum: Modding help
Topic: Is there a trigger or variable for the 'highlighting' of certain entities?
Replies: 10
Views: 2486

Re: Is there a trigger or variable for the 'highlighting' of certain entities?

I've had success with the above & got the code doing what I need it to do, I'm just on the final hiccup.

I want to replicate this:

https://i.imgur.com/knvajKL.png

But with a custom entity I've created, for storage boxes. So that when I'm holding a storage box, it will highlight the radius of my ...
by KoRaLLL
Sun Jan 01, 2023 5:26 pm
Forum: Modding help
Topic: Is there a trigger or variable for the 'highlighting' of certain entities?
Replies: 10
Views: 2486

Re: Is there a trigger or variable for the 'highlighting' of certain entities?


The on_selected_entity_changed event fires when an entity is "selected" (in Factorio API jargon this means highlighting the entity with a mouse-over):

https://lua-api.factorio.com/latest/events.html#on_selected_entity_changed

You can use this event to detect when something is high-lit by the ...
by KoRaLLL
Sun Jan 01, 2023 12:59 pm
Forum: Modding help
Topic: Is there a trigger or variable for the 'highlighting' of certain entities?
Replies: 10
Views: 2486

Is there a trigger or variable for the 'highlighting' of certain entities?

Hi all, I was just wondering if there was any set variable or entity value for this 'on-hover' state.

I'm talking about the effect that appears when you hover over an entity (for example, an assembly machine) that is part of something else's radius (e.g, a beacon), so that when you hover on the ...
by KoRaLLL
Wed Sep 14, 2022 6:19 pm
Forum: Modding help
Topic: Getting the specific bullet-count in a players' active weapon's magazine
Replies: 2
Views: 1153

Re: Getting the specific bullet-count in a players' active weapon's magazine


The character_ammo inventory is an array of LuaItemStacks, apparently left to right as you look at it in the GUI, with 3 slots in vanilla (I'm not sure if this inventory can have its size changed by mods). You can get the currently selected gun and ammo slot with character.selected_gun_index . Use ...
by KoRaLLL
Tue Sep 13, 2022 6:06 pm
Forum: Modding help
Topic: Getting the specific bullet-count in a players' active weapon's magazine
Replies: 2
Views: 1153

Getting the specific bullet-count in a players' active weapon's magazine

Hey guys, I'm trying to get the bullet count in order to determine whether or not a player is shooting.

I was originally running:

if p.shooting_state.state ~= defines.shooting.not_shooting then

But this triggers even if the player is just holding down SPACE or C - so my logic was to capture ...
by KoRaLLL
Mon Sep 12, 2022 10:15 am
Forum: Modding help
Topic: Trying to get the active weapon that a player is using?
Replies: 6
Views: 1979

Re: Trying to get the active weapon that a player is using?



I'm struggling to find the right pointers within the docs, and as far as I'm aware there's no search functionality


Search is here:


You are a life saver. Thank you so much!



Do you have any guidance on navigating the docs? I spent hours googling things like 'factorio player active ...
by KoRaLLL
Mon Sep 12, 2022 8:20 am
Forum: Modding help
Topic: Trying to get the active weapon that a player is using?
Replies: 6
Views: 1979

Re: Trying to get the active weapon that a player is using?


It's part of the character entity: https://lua-api.factorio.com/latest/LuaEntity.html#LuaEntity.selected_gun_index . You can get the player's character, if any, using the LUAPlayer.character attribute.

Be sure to check if the player has a character first - they may not if they are using sandbox ...
by KoRaLLL
Sun Sep 11, 2022 7:39 pm
Forum: Modding help
Topic: Trying to get the active weapon that a player is using?
Replies: 6
Views: 1979

Re: Trying to get the active weapon that a player is using?

I realised that I was using print() instead of serpent.block to output this.

So I'm one step closer, however, the real output is something like:

}
65.917 Script @__code__/control.lua:19: {
["combat-shotgun"] = 1,
["pistol"] = 1,
shotgun = 1
}

How would I be able to get which of these is the ...
by KoRaLLL
Sun Sep 11, 2022 7:24 pm
Forum: Modding help
Topic: Trying to get the active weapon that a player is using?
Replies: 6
Views: 1979

Trying to get the active weapon that a player is using?

Hey all,

I was just wondering how you'd go about 'detecting' the current weapon that a player is using?

I figured it would be something like:

Code: Select all

local weapon = p.get_inventory(defines.inventory.character_guns).get_contents()
Where p = player - but this returns 'Unknown key: "1"'

Thanks

Go to advanced search