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()
Thanks
Code: Select all
local weapon = p.get_inventory(defines.inventory.character_guns).get_contents()
Code: Select all
}
65.917 Script @__code__/control.lua:19: {
["combat-shotgun"] = 1,
["pistol"] = 1,
shotgun = 1
}
Ahh - this makes perfect sense, thank you.Silari wrote: ↑Sun Sep 11, 2022 10:42 pmIt's part of the character entity: https://lua-api.factorio.com/latest/Lua ... _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, or mods. If the player doesn't have a character they won't have any guns.
Search is here:
There is a search bar for most objects, methods and attributes on the left, in the sidebar.KoRaLLL wrote: ↑Mon Sep 12, 2022 8:20 amDo you have any guidance on navigating the docs? I spent hours googling things like 'factorio player active weapon modding' 'player active item factorio' and nothing came up.
I'm struggling to find the right pointers within the docs, and as far as I'm aware there's no search functionality
You are a life saver. Thank you so much!
Yeah, CTRL + F'ing is what I've been doing, but obviously it meant that I glanced over things like in my original request.Bilka wrote: ↑Mon Sep 12, 2022 8:38 amThere is a search bar for most objects, methods and attributes on the left, in the sidebar.KoRaLLL wrote: ↑Mon Sep 12, 2022 8:20 amDo you have any guidance on navigating the docs? I spent hours googling things like 'factorio player active weapon modding' 'player active item factorio' and nothing came up.
I'm struggling to find the right pointers within the docs, and as far as I'm aware there's no search functionality
You can also open https://lua-api.factorio.com/latest/Classes.html and use your browser's search function (usually under ctrl +f) to search through all objects, methods, attributes and their short descriptions. Since the short descriptions are on the page, it tends to be more useful than the sidebar search. E.g. for the question here you could search for "weapon" on the Classes page and find it right away.
Screenshot_20220912_103550.png