Jump to content

How to determine the presence of electricity in a cell?


Nebula

Recommended Posts

 function SearchGenerator(player)
	local player = getSpecificPlayer(0);
	local shutdown
	local generator
	
	if SandboxVars.ElecShutModifier >= -1 and GameTime:getInstance():getNightsSurvived() > SandboxVars.ElecShutModifier then
		shutdown = true;
		elseif GameTime:getInstance():getNightsSurvived() <= SandboxVars.ElecShutModifier then
		shutdown = false;
	end
	
	local zoneSize = 2;
	for z = 0, 3 do
		for x = player:getSquare():getX() - zoneSize, player:getSquare():getX() + zoneSize do
			for y = player:getSquare():getY() - zoneSize, player:getSquare():getY() + zoneSize do
				local Square = player:getCell():getGridSquare(x, y, z);
				if Square and Square:getGenerator() and Square:getGenerator():isActivated() then
					generator = true;
				end
			end
		end
	end
end

 

There were no problems with finding an included generator. But how to determine the presence of electricity in a cell?

Link to comment
Share on other sites

I figured it out ... need to use  - getSquare():haveElectricity()

But now I have the next question.
Why, before the global power outage, is there a lack of electricity in the cells, although the lights are on and the refrigerators are working?

Link to comment
Share on other sites

I think it's because there is a special state about that general electricity.

getSandboxOptions():getElecShutModifier()

then you can compare with getGameTime():getWorldAgeHours()

You also could check in the Sewing Machine mod, there are some code that checks for power if I remember well.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...