I'm at abit of a loss for how to get a player's EquipmentGrid.
I've looked at Player, Controller, Game, Force, nowhere is there anything about EquipmentGrid. I was hoping to just call something like player.equipment_grid but as it stands now, I'll have to watch everyone's cursor for a new EquipmentGrid and add it to a table but that seems quite hacky and... stupid...
I hope I'm just overlooking something but at the moment, I don't think I am...
Get EquipmentGrid?
Get EquipmentGrid?
Will code for Food. I also have 11+ mods!
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Get EquipmentGrid?
It belongs to the item, which belongs to the player inventory, which belongs to the character, which belongs to the player, which belongs to the game.
This is a stripped down version of the gameloop I used to manipulate the equipment in my modular armor mod.
This is a stripped down version of the gameloop I used to manipulate the equipment in my modular armor mod.
Code: Select all
local thisPlayer = nil
local players = game.players
for i=1, #players do
thisPlayer = players[i]
if (thisPlayer.character) then
local armor = thisPlayer.get_inventory(defines.inventory.player_armor)[1] -- Check for armour presence.
if (armor.valid_for_read) then
if (armor.has_grid) then -- Check for grid existence.
local grid = armor.grid
local energy = 0 -- Total energy and energy capacity
local energyCap = 0
local shieldHealth = 0 -- Total shield and shield capacity for auto-balancing.
local shieldCap = 0
for i,equipment in ipairs(grid.equipment) do -- Loop through all equipment.
if (equipment.max_energy ~= 0) then
energy = energy + equipment.energy -- If it has energy, add values to total value.
energyCap = energyCap + equipment.max_energy
else
end
if equipment.max_shield ~= 0 then
shieldHealth = shieldHealth + equipment.shield -- Same with shield.
shieldCap = shieldCap + equipment.max_shield
else
end
end
else
end
else
end
else
-- No player
end
end
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: Get EquipmentGrid?
Just wondering - why do you increment over player indexes instead of simply iterating the players directly?
Code: Select all
for i,player in pairs(game.players) do
if player.character then
-- stuff here
end
end
If you want to get ahold of me I'm almost always on Discord.
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Get EquipmentGrid?
Mainly because I am not very good at LUA, and copied existing examples.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: Get EquipmentGrid?
Thanks for the help... it kinda feels weak that there isn't a direct access to the armour slot since there is only one but I guess I'll have to run with this... I'm hoping to be able to get some code made tomorrow but... things might not happen >.>
Will code for Food. I also have 11+ mods!