[MOD 0.16.x] Alien walls [0.7.0]

Topics and discussion about specific mods
vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

[MOD 0.16.x] Alien walls [0.7.0]

Post by vedrit » Tue Jun 09, 2015 9:49 pm

Type: Mod
Name: Alien Walls
Description: Originating as an add-on to darkshadow's Evolution, this mod is now a stand-alone mod that adds regenerating walls and gates.
License: CC BY-NC-SA
Dependency: Base Factorio
Version: 0.7.0
Release: 07/05/2018
Tested-With-Factorio-Version: 0.16
Category: Other
Tags: Free
Download-Url: https://mods.factorio.com/mods/vedrit/AlienWall
Website: https://forums.factorio.com/forum/vie ... 32&t=12840
License
Long description

Versions History
0.7.0
0.6.1
0.6.0
0.5.0
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.2.1
0.1.5
0.1.4
0.1.2
0.1.0
To do
I'll officially release this mod when I'm no longer using placeholders for the entities/icons
Last edited by vedrit on Tue May 08, 2018 12:53 am, edited 42 times in total.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 3459
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [WIP] Alien walls

Post by Klonan » Tue Jun 09, 2015 11:15 pm

Hey, what sort of stuff do you have done already?

I can help out with the research scripting if you need the help.

I might try my hand at making some wall graphics, I will see what i can do.

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Tue Jun 09, 2015 11:53 pm

I've literally just started, so I have nothing done. My girlfriend does graphic design, so I've asked her to handle graphics. I'm kind of just going through files and figuring out what I need and where to put things.

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 4:19 am

I've hit a snag in that Factorio always "Error in assignID, 'hybrid-wall' was not recognized id of item" sometimes it'll say recipe instead of item
I've checked all my files, and the name is consistent across them all, "hybrid-wall"

User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 509
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: [WIP] Alien walls

Post by L0771 » Wed Jun 10, 2015 4:53 am

vedrit wrote:I've hit a snag in that Factorio always "Error in assignID, 'hybrid-wall' was not recognized id of item" sometimes it'll say recipe instead of item
I've checked all my files, and the name is consistent across them all, "hybrid-wall"
I recomends make a copy of existing item and modify how you want.
Check this code from version > 0.4.0 (prototypes), is better start with that code from the beginning.

That error must be in the item, or the item doesn't exists.

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 5:08 am

L0771 wrote:
vedrit wrote:I've hit a snag in that Factorio always "Error in assignID, 'hybrid-wall' was not recognized id of item" sometimes it'll say recipe instead of item
I've checked all my files, and the name is consistent across them all, "hybrid-wall"
I recomends make a copy of existing item and modify how you want.
Check this code from version > 0.4.0 (prototypes), is better start with that code from the beginning.

That error must be in the item, or the item doesn't exists.
That's essentially what I've done, using Evolution, Dytech, and the Factorio base (for the gate, since I don't know of any mod that has a gate)
Entity
Item
Interesting way to structure things, L0771, but I'm not quite sure I understand it

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 7:06 am

Resolved the issue. I wasn't calling recipe or item in data. It now loads up without a hitch! MOVING ON!

Tested it out, and the wall isn't healing. A bit of a problem, as one might understand
Last edited by vedrit on Wed Jun 10, 2015 7:13 am, edited 1 time in total.

FishSandwich
Smart Inserter
Smart Inserter
Posts: 1846
Joined: Sun Feb 23, 2014 3:37 pm
Contact:

Re: [WIP] Alien walls

Post by FishSandwich » Wed Jun 10, 2015 7:12 am

This is relevant to my interests. :D

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 7:30 am

So, according to the wiki, healing_per_tick only works on active entities, but I don't see anywhere I can set an entity to be active. There's mention of an [entity].active = true but it doesn't seem to be working, or else I don't know how to use it.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 3459
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [WIP] Alien walls

Post by Klonan » Wed Jun 10, 2015 1:07 pm

vedrit wrote:So, according to the wiki, healing_per_tick only works on active entities, but I don't see anywhere I can set an entity to be active. There's mention of an [entity].active = true but it doesn't seem to be working, or else I don't know how to use it.
Thats not a problem, i can set up a script in the control.lua to emulate the regeneration if you'd like.

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 4:28 pm

That would be appreciated. I don't currently have a control file, and I'm curious how it would work.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 3459
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [WIP] Alien walls

Post by Klonan » Wed Jun 10, 2015 5:24 pm

This is just a draft, once more work is done and its reasonably packaged i can work on it more. If this doesnt work let me know.

Just save it as control.lua

Code: Select all

require "defines"
require "util"


game.onevent(defines.events.ontick, function(event)

		if glob.ticking == nil then
			glob.ticking = 59
		end
		
		if glob.ticking == 0 then
			glob.ticking = 59
			heal_wall()
		else
			glob.ticking = glob.ticking - 1
		end
end)


game.onevent(defines.events.onrobotbuiltentity , function(event)

	if event.createdentity.name == "hybrid-wall" then
	
			if glob.monsterwall == nil then
				glob.monsterwall = {}
			end
			
		local monsterwall = event.createdentity
			table.insert(glob.monsterwall, monsterwall)
	end
end)

game.onevent(defines.events.onbuiltentity, function(event)

	if event.createdentity.name == "hybrid-wall" then
	
			if glob.monsterwall == nil then
				glob.monsterwall = {}
			end
			
		local monsterwall = event.createdentity
			table.insert(glob.monsterwall, monsterwall)
	end
end)




function heal_wall()

	if glob.monsterwall ~= nil then 
		for k,monsterwall in pairs(glob.monsterwall) do
			local HP = monsterwall.health
				if HP < 1750 --max health
					then HP = HP + 10 --Hp per second
					monsterwall.health = HP
				end
			else
		end
	else
		table.remove(glob.monsterwall, k)
	end
end

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 5:57 pm

Klonan wrote:This is just a draft, once more work is done and its reasonably packaged i can work on it more. If this doesnt work let me know.

Just save it as control.lua

Code: Select all

require "defines"
require "util"


game.onevent(defines.events.ontick, function(event)

		if glob.ticking == nil then
			glob.ticking = 59
		end
		
		if glob.ticking == 0 then
			glob.ticking = 59
			heal_wall()
		else
			glob.ticking = glob.ticking - 1
		end
end)


game.onevent(defines.events.onrobotbuiltentity , function(event)

	if event.createdentity.name == "hybrid-wall" then
	
			if glob.monsterwall == nil then
				glob.monsterwall = {}
			end
			
		local monsterwall = event.createdentity
			table.insert(glob.monsterwall, monsterwall)
	end
end)

game.onevent(defines.events.onbuiltentity, function(event)

	if event.createdentity.name == "hybrid-wall" then
	
			if glob.monsterwall == nil then
				glob.monsterwall = {}
			end
			
		local monsterwall = event.createdentity
			table.insert(glob.monsterwall, monsterwall)
	end
end)




function heal_wall()

	if glob.monsterwall ~= nil then 
		for k,monsterwall in pairs(glob.monsterwall) do
			local HP = monsterwall.health
				if HP < 1750 --max health
					then HP = HP + 10 --Hp per second
					monsterwall.health = HP
				end
			else
		end
	else
		table.remove(glob.monsterwall, k)
	end
end

It keeps saying there are missing 'end's in the heal_wall function when I try to initiate a game, whether saved or new, which I don't understand since it looks like it has end's in the correct places. When I put in end's where the game says they are expected, this is what we end up with

Code: Select all

function heal_wall()
   if glob.alienwall ~= nil then 
      for k,alienwall in pairs(glob.alienwall) do
         local HP = alienwall.health
            if HP < 500 --max health
               then HP = HP + 5 --Hp per second
               alienwall.health = HP
            end
         end
		 else
      end
   end
   else
      table.remove(glob.alienwall, k)
   end
end

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 926
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: [WIP] Alien walls

Post by ratchetfreak » Wed Jun 10, 2015 6:31 pm

there's an additional else in there:

Code: Select all


    function heal_wall()

       if glob.monsterwall ~= nil then
          for k,monsterwall in pairs(glob.monsterwall) do
             local HP = monsterwall.health
             if HP < 1750 --max healththen 
                HP = HP + 10 --Hp per second
                monsterwall.health = HP
             end
           --  else <--right here
          end
       else
          table.remove(glob.monsterwall, k)
       end
    end
I also reindented that part

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 6:47 pm

ratchetfreak wrote:there's an additional else in there:

Code: Select all


    function heal_wall()

       if glob.monsterwall ~= nil then
          for k,monsterwall in pairs(glob.monsterwall) do
             local HP = monsterwall.health
             if HP < 1750 --max healththen 
                HP = HP + 10 --Hp per second
                monsterwall.health = HP
             end
           --  else <--right here
          end
       else
          table.remove(glob.monsterwall, k)
       end
    end
I also reindented that part

Thanks. Now the game is saying that a table was expected, but got nil at table.remove(glob.alienwall, k)
Isn't the first if in the function supposed to prevent such a case?

User avatar
ThaPear
Fast Inserter
Fast Inserter
Posts: 208
Joined: Fri May 30, 2014 8:05 am
Contact:

Re: [WIP] Alien walls

Post by ThaPear » Wed Jun 10, 2015 7:00 pm

Simplification of the tick function:

Code: Select all

game.onevent(defines.events.ontick, function(event)
		if (game.tick % 60) == 0 then
			heal_wall()
		end
end)
Fix of the heal_wall function:

Code: Select all

function heal_wall()
	if glob.monsterwall ~= nil then
		for k,monsterwall in pairs(glob.monsterwall) do
			if monsterwall.valid then -- Is the wall still there?
				local HP = monsterwall.health
				if HP < 1750 then
					HP = HP + 10 --Hp per second
					monsterwall.health = HP
				end
			else -- It's no longer there, so remove it from our list.
				table.remove(glob.monsterwall, k)
			end
		end
	end
end

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 7:18 pm

Thanks Pear, I'm no longer getting errors and the hybrid-gate entity will heal over time, but the hybrid-wall entity won't. Is there a way to check if both entity types are being added?

Edit - Is it possible to add the entity to the table within the entity file, rather than in control?

Edit2 - I figured out the healing thing and got it so both will now heal. Sweet.

User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 509
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: [WIP] Alien walls

Post by L0771 » Wed Jun 10, 2015 8:41 pm

vedrit wrote:So, according to the wiki, healing_per_tick only works on active entities, but I don't see anywhere I can set an entity to be active. There's mention of an [entity].active = true but it doesn't seem to be working, or else I don't know how to use it.
Some entities don't accept healing_per_tick.
Check this code, i'll do something like this, i think is the best option for now, working with triggers.
vedrit wrote:Edit - Is it possible to add the entity to the table within the entity file, rather than in control?
Yep, very useful, if you creates the entity with createentity, just do
local var = createentity(...)
if you creates the entity with the character, add in the function "onrobotbuiltentity"
local var = event.createdentity

vedrit
Filter Inserter
Filter Inserter
Posts: 261
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: [WIP] Alien walls

Post by vedrit » Wed Jun 10, 2015 8:53 pm

L0771 wrote:
vedrit wrote:So, according to the wiki, healing_per_tick only works on active entities, but I don't see anywhere I can set an entity to be active. There's mention of an [entity].active = true but it doesn't seem to be working, or else I don't know how to use it.
Some entities don't accept healing_per_tick.
Check this code, i'll do something like this, i think is the best option for now, working with triggers.
That would be another interesting way of doing things, but there's so much going on, I don't really understand it with my fairly limited knowledge of Lua. I would need someone far more experienced to go through it with me and explain what each function is doing and where it's getting it's data, and where that data is going.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 3459
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [WIP] Alien walls [0.1.2]

Post by Klonan » Wed Jun 10, 2015 11:51 pm

Thanks everyone for fixing the issues with my script, I havent been able to test any of this myself.

I've written up a research control script to automatically increment a global regen rate.

Code: Select all

require "defines
require "util"

function init() --Initialises the global value
	if glob.monsterregen == nil then
		glob.monsterregen = 10  --per second
	end
end

function set_regen(n) --used for testing or debugging IDK if it works
	glob.monsteregen = n
end

game.oninit(init)
game.onload(init)




game.onevent(defines.events.onresearchfinished, function(event) --when research is finished

	if research == "monster-wall-upgrade" then
			glob.monsterregen = glob.monsterregen * 1.2 --plus 20%
			--glob.monsterregen = glob.monsterregen +5 -- increase to 15
		end	
	
	if research == "monster-wall-upgrade-1" then
			glob.monsterregen = glob.monsterregen * 1.4 --plus 40%
		end
	
	
	if research == "monster-wall-upgrade-2" then
			glob.monsterregen = glob.monsterregen * 1.6 --plus 60%
		end
	end
	
)
You can integrate this into the control.lua or just save it as research.lua and require it in the control.lua

we'd need to change the heal_wall function to

Code: Select all

function heal_wall()

   if glob.monsterwall ~= nil then
      for k,monsterwall in pairs(glob.monsterwall) do
         if monsterwall.valid then -- Is the wall still there?
            local HP = monsterwall.health
            if HP < 1750 then
               HP = HP + glob.regenrate --Hp per second determined by global value
               monsterwall.health = HP
            end
         else -- It's no longer there, so remove it from our list.
            table.remove(glob.monsterwall, k)
         end
      end
It might be better to have the global.regenrate to be checked when the wall entity is built (alongside the glob.monsterwall check)
just slip it in alongside it.

Code: Select all

	if glob.monsterregen == nil then
		glob.monsterregen = 1

Post Reply

Return to “Mods”

Who is online

Users browsing this forum: No registered users and 14 guests