Mod almost done, but really need help with lua programming

Place to get help with not working mods / modding interface.
Nasabot
Fast Inserter
Fast Inserter
Posts: 102
Joined: Fri Oct 30, 2015 11:16 am
Contact:

Mod almost done, but really need help with lua programming

Post by Nasabot »

EDIT2: YEEEEA. I DID IT!!! I CANT BELIEV IT. Even on my own! :))
(ofc the code I needed was ridonkulous easy...)

EDIT.: This is un updated post because I wanted to avoid double posts.

In the last few days I created a mod which is meant to extend vanila content in a decent way. The mod keeps the flavour of the original game, but improves it by balancing and reorganizing content, so it becomes more meaningful and less redundant. Unfortunatly it requires a single lua-functionality I am not capable to create... and without it, the mod makes no sense(at least to me^^) as a lot of balancing is based on this single functionality. I spent several hours created a proper working "control.lua" but till now I am not able to make it work, so I hope somebody can help me.

The functionality I need is simple:
A building should lose HP over time, until it finally gets destroyed, and can get rebuild automatically by robots.
Maybe you know a simpler way to solve this, but the code I worked on was from this forum thread: viewtopic.php?f=32&t=12840
It is possible to change "wall regeneration" in a way to make the building(entity) lose health, but when it reaches 0, it wont get destroyed.
I tried to solve this with adding a script which looks like this:

Code: Select all

script.on_event(defines.events.on_entity_died, function(event)
   if event.entity.name == "entity-name" then
   entity.die()
   end
end)
My guess is, that the game makes a difference in "entity gets destroyed" and "entity.HP = 0". Also I am pretty sure that there needs to be more in the If-brackets.

Also I get keeping error messages, while trying different codes. Fact is, I am a total noob in .lua and currently I am not sure if I will make it on my own in the next 20 hours of trying different lines for a single functionality...




Outdated and irrelevant post:
I am thinking about creating a mod and I try to think ahead. Currently I try to improve my modding skills by analyzing BOBs Mods structure(which is very tidy :)), but to really start Id like to have those 2 questions answered:

1,
Is it possible to create different types of fuels?
For instance:
-You have Fuel X, Y and Z
-Burner A uses fuel Z
-Burner B uses Fuel X, Y
Or does the game limit burner to just "Yes or No"?
What I want to do is to exclude certain fuels for certain burner. If this is not possible, I have to rethink the doctrine of my whole thought concept.

2,
What is to exspect from the Patch 0.13? Does anybody know where I can inform myself about the content(so I can take it into account) and when it is about to come? (the next patch this week isnt 0.13.00 but 0.12.23 and for steam?)
Do you have any experience with mod-patch incompatibility? Is it wise to wait and start modding after a big patch arrives? I dont want to start a mod and 1 week later a new patch makes all my work useless, so I rather do planning and learning in the meantime.
Last edited by Nasabot on Thu Feb 25, 2016 7:39 pm, edited 4 times in total.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5410
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by Klonan »

1. burner is yes or no, you create 'fuel' by defining a "fuel-value" in the item definition
2. 0.13 wont break anything you're going to be working on, so i wouldn't worry about waiting, get stuck in now :D
Nasabot
Fast Inserter
Fast Inserter
Posts: 102
Joined: Fri Oct 30, 2015 11:16 am
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by Nasabot »

Thanks, good to know!

Well, if 1, does not work as I hoped do you know if its possible to make buildings >degenerate<. I know that there is a "healing per tick" value which works in its obvious way, but if you put in a negative value, the player nor a building would degenerate on its own(the player would start degenerating, after he is damaged by a monster. On a building it seems to not have an effect)
So it seams the game checks if an entity is in combat/damaged or not until regeneration (positive or negative) starts to kick in.

Maybe somebody knows how to implement permanent degeneration of entities?
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5410
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by Klonan »

Nasabot wrote:Thanks, good to know!

Well, if 1, does not work as I hoped do you know if its possible to make buildings >degenerate<. I know that there is a "healing per tick" value which works in its obvious way, but if you put in a negative value, the player nor a building would degenerate on its own(the player would start degenerating, after he is damaged by a monster. On a building it seems to not have an effect)
So it seams the game checks if an entity is in combat/damaged or not until regeneration (positive or negative) starts to kick in.

Maybe somebody knows how to implement permanent degeneration of entities?
Healing per tick is only for some entities...

You can implement 'damage' but it will involve a lot of scripting,
I reccomend looking at the control lua in https://forums.factorio.com/forum/vie ... 32&t=12840
Nasabot
Fast Inserter
Fast Inserter
Posts: 102
Joined: Fri Oct 30, 2015 11:16 am
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by Nasabot »

I looked at the code and tried a little bit around and YES, it will work for me! Thank you :)
Nasabot
Fast Inserter
Fast Inserter
Posts: 102
Joined: Fri Oct 30, 2015 11:16 am
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by Nasabot »

Yesterday I created a lot of stuff and I am really enjoying modding, designing content and rebalancing, but I am a total noob in programming.
Healing per tick is only for some entities...

You can implement 'damage' but it will involve a lot of scripting,
I reccomend looking at the control lua in viewtopic.php?f=32&t=12840
This link helped me a lot and I am able to understand how the code works, but there is one thing I need:

When a building loses HP it will stay at 0 HP and wont get destroyed. How can I implement a function so that the building gets destroyed at 0 HP and ideally leaves a "ghost" (so it can be rebuilt by robots automatically)? I think that cant be so difficult and eventually I would find out after hours of studying lua, but I rather embarrass myself a last single time and ask for it directly ;)

If I get this functunallity done I wont need any more help.
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by orzelek »

Entity has a destroy function that you should call at 0 hp.
I'm not 100% sure if it will leave ghost.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5410
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by Klonan »

Nasabot wrote:Yesterday I created a lot of stuff and I am really enjoying modding, designing content and rebalancing, but I am a total noob in programming.

When a building loses HP it will stay at 0 HP and wont get destroyed. How can I implement a function so that the building gets destroyed at 0 HP and ideally leaves a "ghost" (so it can be rebuilt by robots automatically)? I think that cant be so difficult and eventually I would find out after hours of studying lua, but I rather embarrass myself a last single time and ask for it directly ;)

If I get this functunallity done I wont need any more help.
you can use entity.die() and it will act like it's been killed by something
Nasabot
Fast Inserter
Fast Inserter
Posts: 102
Joined: Fri Oct 30, 2015 11:16 am
Contact:

Re: Interested in creating a mod but have 2 specific questions

Post by Nasabot »

Hmm, I spent several hours trying to understand lua, but though I learned a lot, I am not able to get any reasonable code working.

I hope somebody can help me create a proper working "control.lua", so I can release my mod soon. Actually I spent a lot of time creating my mod the last 3 days, but now I am at the point where I am close to finish it, but I miss this single lua function which is essential for my mod.

What I want to do is to create a building(entity) which loses health points over time and destroys the entity if HP reach 0 and ideally leaves back a ghost, so that it can be rebuild by robots.
The code I am working on and trying to expand is
I reccomend looking at the control lua in viewtopic.php?f=32&t=12840
(The code in the quote allows HP-degeneration, but entity stays at 0 HP and this is the problem)

I looked through all the documentation and some lua tutorials but I am too bad at programming :(

Maybe somebody, who is a lua-pro, can help me add those few important lines to make the function working :)
Post Reply

Return to “Modding help”