[MOD 1.1] Oxygen

Topics and discussion about specific mods
User avatar
darkshadow1809
Filter Inserter
Filter Inserter
Posts: 306
Joined: Thu Jan 15, 2015 10:13 pm
Contact:

Re: [0.11.X] Oxygen

Post by darkshadow1809 »

Natha wrote:
darkshadow1809 wrote:Workin on a new modpack and erhh

Seems Dystopia + Cursed Don't like your mod :)

http://prntscr.com/6vfoxh

Seems the item grid is missing an equipment grid :D hope it helps ;) This seems to happen when cursed tries implementing its own armor then dystopia tries and forces an armor slot into it. And gets the upper hand. Then your mod returns this error. Mod works without either of these mods :P Might be wrong tho! dont judge :# i suck at lua lol :D I am only good at throwing stuff at it and make it work on some magical reason :D

Code: Select all

function hasgasmask(player)
	if player.getinventory(defines.inventory.playerarmor)[1] == nil then return false end
	local grid = player.getinventory(defines.inventory.playerarmor)[1].grid
	if grid == nil then return false end
	for _,equip in pairs(grid.equipment) do
		if equip.name == "gas-mask" then return true end
	end
	return false
end
I've added a check with the ItemStack.hasgrid() method, it should work now :D

Thanks buddy :) !
ShadowsModpackDevelopment

User avatar
darkshadow1809
Filter Inserter
Filter Inserter
Posts: 306
Joined: Thu Jan 15, 2015 10:13 pm
Contact:

Re: [0.11.X] Oxygen

Post by darkshadow1809 »

Check the mod before you release it :P

http://prntscr.com/6vlwaz
ShadowsModpackDevelopment

Natha
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: [0.11.X] Oxygen

Post by Natha »

darkshadow1809 wrote:Check the mod before you release it :P

http://prntscr.com/6vlwaz
Hmm...whenever i fix small errors and I'm sure that it must be correct, there is a new error :D
Nevertheless thanks, I'll now try to test the mod always :)

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: [0.11.X] Oxygen

Post by orzelek »

Natha wrote: Nevertheless thanks, I'll now try to test the mod always :)
Famous last words of developer ;)

Natha
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: [0.11.X] Oxygen

Post by Natha »

orzelek wrote:
Natha wrote: Nevertheless thanks, I'll now try to test the mod always :)
Famous last words of developer ;)
the thing was, that I not have tested each small change of the mod :D
its annoying that almost always the small changes cause the biggest errors ;)

User avatar
Cheata
Long Handed Inserter
Long Handed Inserter
Posts: 78
Joined: Sun Aug 17, 2014 6:46 am
Contact:

Re: [0.11.X] Oxygen

Post by Cheata »

I seem to have found a minor issue with the oxygen bottle detection

I tried out this mod for the first time today and as expected ran out of oxygen before i managed to get a working oxygen facility up and running, However i had expected this and planned ahead. while the last of the research was completing and the first oxygen bottle got filled i ran around picking up and eating fish to keep my health up.

16min after running out of oxygen i finally managed to get a full bottle back into my inventory but to my disappointment i still died from lack of oxygen


It appears you use the code below to check if the player has run out of oxygen and deal damage accordingly however you only check for oxygen bottles if the players remaining oxygen is greater than 0.
This means that once the player has started suffocating it cannot be stopped even if a fresh oxygen bottle is added to the inventory after suffocation has begun

Code: Select all

                        if v[2] > 0 and (game.tick % 800 == 0 or (not hasgasmask(v[1]) and game.tick % 400 == 0)) then
				v[2] = v[2] - 1
				checkinventory(v)
				updategui(v)
			elseif v[2] <= 0 and game.tick % 300 == 0 and v[1].character ~= nil then
				v[1].character.damage(10, v[1].force, "oxygen")
			end
unless this is intentional behavior may i suggest the following adjustment to allow for last minute rescues

Code: Select all

                        if v[2] > 0 and (game.tick % 800 == 0 or (not hasgasmask(v[1]) and game.tick % 400 == 0)) then
				v[2] = v[2] - 1
				updategui(v)
			elseif v[2] <= 0 and game.tick % 300 == 0 and v[1].character ~= nil then
				v[1].character.damage(10, v[1].force, "oxygen")
			end
			checkinventory(v)
or something similar, possibly with a separate tick check around the 200 or 300 mark

alternatively you could setup the checkinventory function to return true if an oxygen bottle was found as shown below (i have done this on my local machine and confirmed it works)

Code: Select all

function checkinventory(oxygenplayer)
	local inv = oxygenplayer[1].getinventory(defines.inventory.playermain)
	
	for i=1,2 do
		if inv.getitemcount("oxygen-bottle") >= 1 and oxygenplayer[2] <= 50 then
			inv.remove{name="oxygen-bottle", count=1}
			inv.insert{name="empty-oxygen-bottle", count=1}
			oxygenplayer[2] = oxygenplayer[2] + 50
                        return true  -- small bottle found so leave the function and tell caller about it
		elseif inv.getitemcount("big-oxygen-bottle") >= 1 and oxygenplayer[2] == 0 then
			inv.remove{name="big-oxygen-bottle", count=1}
			inv.insert{name="big-empty-oxygen-bottle", count=1}
			oxygenplayer[2] = oxygenplayer[2] + 100
                       return true -- large bottle found so leave the function and tell the caller about it
		end
		inv = oxygenplayer[1].getinventory(defines.inventory.playerquickbar)
	end
       return false --no bottles found so send caller default value
end

Code: Select all

                   function handleplayers()
	for _,v in ipairs(glob.oxygen) do
		if v[1].controllertype == defines.controllers.character then
			
			-- Sauerstoffverbrauch und Schaden bei geringem Sauerstoff
			if v[2] > 0 and (game.tick % 800 == 0 or (not hasgasmask(v[1]) and game.tick % 400 == 0)) then
				v[2] = v[2] - 1
				checkinventory(v)  -- left this here to make use of the 50% bottles sooner but not necessarily needed
				updategui(v)
			elseif v[2] <= 0 and game.tick % 300 == 0 and v[1].character ~= nil then
                            if checkinventory(v) then --check for the bottles and restore oxygen
                                updategui(v)
                            else
				v[1].character.damage(10, v[1].force, "oxygen") --cause damage if none found
                            end
			end
			
			-- Auffüllung durch Verteiler
			local pos = v[1].position
			if game.tick % 75 == 0 then
				entities = game.findentitiesfiltered{area={{pos.x - 10, pos.y - 10}, {pos.x + 10, pos.y + 10}}, name="oxygen-dispenser"}
				if #entities > 0 then
					if v[2] < 100 then
						v[2] = v[2] + 1
						updategui(v)
					end
					if game.tick % 225 == 0 then
						local inv = v[1].getinventory(defines.inventory.playermain)
						for i=1,2 do
							if inv.getitemcount("empty-oxygen-bottle") > 0 then
								inv.remove({name="empty-oxygen-bottle", count=1})
								inv.insert({name="oxygen-bottle", count=1})
							elseif inv.getitemcount("big-empty-oxygen-bottle") > 0 then
								inv.remove({name="big-empty-oxygen-bottle", count=1})
								inv.insert({name="big-oxygen-bottle", count=1})
							end
							inv = v[1].getinventory(defines.inventory.playerquickbar)
						end
					end
				end
			end
			
		end
	end
end
Let me know your thoughts :)

Natha
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: [0.11.X] Oxygen

Post by Natha »

Quote
thanks for your report, i've changed the condition checks ;)

User avatar
darkshadow1809
Filter Inserter
Filter Inserter
Posts: 306
Joined: Thu Jan 15, 2015 10:13 pm
Contact:

Re: [0.11.X] Oxygen

Post by darkshadow1809 »

Seems my modpack has a major issue. Once i threw oxygen mod out. It seems something still damages people from polution... Wut? xD

I pm'd you.
ShadowsModpackDevelopment

Virlomi
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat May 02, 2015 11:28 pm
Contact:

Re: [0.11.X] Oxygen

Post by Virlomi »

Since you're making oxygen a thing to worry about, it would be really neat to have an atmosphere dispenser that builds a dome of safe space that you don't need a mask in. Think kind of force field type thing on space carriers and the like.

Natha
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: [0.11.X] Oxygen

Post by Natha »

Virlomi wrote:Since you're making oxygen a thing to worry about, it would be really neat to have an atmosphere dispenser that builds a dome of safe space that you don't need a mask in. Think kind of force field type thing on space carriers and the like.
You dont need any gas masks while you are in the dispensing area of the dispenser ;)
Maybe I can implement a higher tier of dispenser with an area about 20 blocks :D

Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: [0.11.X] Oxygen

Post by Peter34 »

Hi

You say you've set this mod to start the game with 10 Oxygen Bottles, but that you personally feel that you'd be able to research up to the Chemical Plant tech before using more than half of that.

Well, I'm the opposite, I'm rather less hardcore, so might it be a good idea to make several versions of this mod, differing only in terms of the amount of starting Oxygen Bottles, as a way for the player to toggle the difficulty level? I propose versions with 3, 5, 7, 10, 15, 22 and 35 bottles, each figure being approxiatemly 50% greater than the previous, thereby catering to players of all levels of hardcoreness from ultra to none.

Natha
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: [0.11.X] Oxygen

Post by Natha »

Peter34 wrote:Hi

You say you've set this mod to start the game with 10 Oxygen Bottles, but that you personally feel that you'd be able to research up to the Chemical Plant tech before using more than half of that.

Well, I'm the opposite, I'm rather less hardcore, so might it be a good idea to make several versions of this mod, differing only in terms of the amount of starting Oxygen Bottles, as a way for the player to toggle the difficulty level? I propose versions with 3, 5, 7, 10, 15, 22 and 35 bottles, each figure being approxiatemly 50% greater than the previous, thereby catering to players of all levels of hardcoreness from ultra to none.
Hmm...I think the best way is to set up a config file where you can change the oxygen bottle amount.

Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: [0.11.X] Oxygen

Post by Peter34 »

Natha wrote: Hmm...I think the best way is to set up a config file where you can change the oxygen bottle amount.
That may be easier. Just make sure to explain how people can find the file and edit it.

OvermindDL1
Fast Inserter
Fast Inserter
Posts: 192
Joined: Sun Oct 05, 2014 6:12 am
Contact:

Re: [0.11.X] Oxygen

Post by OvermindDL1 »

As per prior recent posts, 10 is *not* enough when playing heavily modded, I adjusted mine to 15 and that was sufficient, though I could see most people needing more when not making a dead beeline for it like I was in my mod-set.

However, I am here to report a 'bug'?
Specifically when calling:

Code: Select all

remote.call("oxygen", "getoxygenofplayer",player.name)
Is returning `nil` for my playername. I have not debugged in to the mod yet so unsure why glob.oxygen does not seem to match my playername, but...

<edit id="0">
I changed the Oxygen mods Control.lua files any lines that were:

Code: Select all

if v[1] == game.getplayer(playername) then
And replaced them with:

Code: Select all

if v[1].name == playername then
And that seems to have resolved the issue. Is the Player object not comparable? If so then those lines were doomed to fail. if they are comparable then somehow it is not returning the same object.
</edit>

Wyrm
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Fri Jan 30, 2015 3:56 am
Contact:

Re: [0.11.X] Oxygen

Post by Wyrm »

I think it may be an aliasing issue. == is testing whether the two compare equal in some implementation-dependent way. I suspect that it's probably a bit-wise comparison. If v is a copy of game.player, it is not necessarily (and probably isn't) bit-equal with game.player. Instead it's a whole different structure with every element copied to v from game.player to a new patch of memory. This means that (given that probably game.player is represented by a C++ vector) the pointers will not compare equal, and so, the two structures will not compare equal.

I would consider this to be a bug in the underlying program. == should have special handling code for lists, and should compare equal all lists whose corresponding elements compare equal.

OvermindDL1
Fast Inserter
Fast Inserter
Posts: 192
Joined: Sun Oct 05, 2014 6:12 am
Contact:

Re: [0.11.X] Oxygen

Post by OvermindDL1 »

Wyrm wrote:I think it may be an aliasing issue. == is testing whether the two compare equal in some implementation-dependent way. I suspect that it's probably a bit-wise comparison. If v is a copy of game.player, it is not necessarily (and probably isn't) bit-equal with game.player. Instead it's a whole different structure with every element copied to v from game.player to a new patch of memory. This means that (given that probably game.player is represented by a C++ vector) the pointers will not compare equal, and so, the two structures will not compare equal.

I would consider this to be a bug in the underlying program. == should have special handling code for lists, and should compare equal all lists whose corresponding elements compare equal.
As someone who has implement LUA as a scripting language in multiple different games, hell no. Deep comparisons are costly as hell.

What you would 'think' it would do is return the same object, those would compare true, it probably returns different objects from underlying C++ code, thus yeah, they test false, and the usernames (or really GUID if Factorio had those) should be checked instead.

Wyrm
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Fri Jan 30, 2015 3:56 am
Contact:

Re: [0.11.X] Oxygen

Post by Wyrm »

OvermindDL1 wrote:As someone who has implement LUA as a scripting language in multiple different games, hell no. Deep comparisons are costly as hell.
And as a general programmer, I can tell you that such things are sometimes necessary to ensure consistent behavior. They aren't too bad as long as you don't do them too often on structures that are too large. You're right that there should be a separate function for them, though (like Scheme's equal? vs eq? predicates).

OvermindDL1
Fast Inserter
Fast Inserter
Posts: 192
Joined: Sun Oct 05, 2014 6:12 am
Contact:

Re: [0.11.X] Oxygen

Post by OvermindDL1 »

Wyrm wrote:
OvermindDL1 wrote:As someone who has implement LUA as a scripting language in multiple different games, hell no. Deep comparisons are costly as hell.
And as a general programmer, I can tell you that such things are sometimes necessary to ensure consistent behavior. They aren't too bad as long as you don't do them too often on structures that are too large. You're right that there should be a separate function for them, though (like Scheme's equal? vs eq? predicates).
Precisely, a separate function, and yes I tested, Factorio does not always return the same structure, name checking should be checked, not the structure. :-)

Neomore
Inserter
Inserter
Posts: 47
Joined: Sun Jun 21, 2015 5:42 pm
Contact:

Re: [0.11.X] Oxygen

Post by Neomore »

will this mod ever be getting updated to .12? I love this mod, and have been looking forward to it getting new stuff. I'm not very good at coding, myself. Otherwise I'd update it myself.
Author of Advanced Factorio, a set of mods that add small bits of Advanced functionality to your gameplay

Check it out here: https://mods.factorio.com/user/neomore

Neomore
Inserter
Inserter
Posts: 47
Joined: Sun Jun 21, 2015 5:42 pm
Contact:

Re: [0.11.X] Oxygen

Post by Neomore »

For anyone better at coding than me, i was able to actually get the mod to load on .12 after having to add over 50 lines of code, and lots of underscores. However, currently only placing the oxygen dispenser down works. Picking it up breaks the mod. Haven't figured out how to fix that, yet.

Also, the smoke effect and the dispenser's shadow effects are also broken, as well as oxygen being added to the main menu (i believe). It at least doesn't in test mode.

But, hey. At least Factorio is able to turn on when the mod is installed. That's at least a bit of progress.

Here's the file. I will keep trying to work on it, but would appreciate someone more qualified to do this. Hopefully the mod author him/her self, but anyone will do.
Attachments
Oxygen_1.3.7.zip
(34.61 KiB) Downloaded 294 times
Author of Advanced Factorio, a set of mods that add small bits of Advanced functionality to your gameplay

Check it out here: https://mods.factorio.com/user/neomore

Post Reply

Return to “Mods”