Question about programming a mod
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Question about programming a mod
I was toying around a bit with an idea (image below), Medium and Long Range Artillery using tank shells, terribly bad aim and long cooldowns but somewhat useful to "resize" some big nests over time, also artillary firing sound is always nice to hear.
Now, I am not a programmer and never touched Lua, so my question is...for someone who's not a programmer, how difficult would it be to make those things works on the programming side (moderately difficult, difficult, straight impossible)? With "makes those things works" I mean ability to designate groups of artillery, open a custom minimap to click and designate an area where to fire for a specific group, rotate every artillery in the group toward the target direction, and then have them firing in that zone. Can you guys explain me what actually doing that would imply code wise?
Now, I am not a programmer and never touched Lua, so my question is...for someone who's not a programmer, how difficult would it be to make those things works on the programming side (moderately difficult, difficult, straight impossible)? With "makes those things works" I mean ability to designate groups of artillery, open a custom minimap to click and designate an area where to fire for a specific group, rotate every artillery in the group toward the target direction, and then have them firing in that zone. Can you guys explain me what actually doing that would imply code wise?
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
Noone?
Well my only guess is that my question is just too vague for anyone to answer or too long to answer, so I'll try asking something more specific and split it up.
1) I've read another topic/tutorial here on the forum and if I got it correctly, my artillery item would have to fall under a prototype. If current prototype would prove not suitable for it, it is possible to add prototypes to the game trough mods? Also, if it is, do I have access to the code of current vanilla prototype so that I can see how it is and what it does?
2)I just started watching some Lua tutorials, apparently a Table is a collection of variables, and one of each artillery will eventually be just a variable in the game, right? If so, if I want to group them together it means I need to have some kind of "manager" that can keep adding and removing N tables of N artillery variables in it?
3)About opening a minimap and designating the tager area, can this be easily achieved? Meaning the code that currently convert all the entities in the game into a map can just be copy-pasted to have the same functionality in my minimap? Do I have access to that code? What about clicking on said minimap to translate that in coordinates in the world relative from artillery group? There is any obvious obstacles to such feature? Or even opening a tab for the minimap to go in and to manage the groups, does that present some obvious obstacle?
In the meantime I'm following lua tutorials and trying to flash out the idea little by little as a way to practice the language, but I would really appreciate to know beforehand what can and cannot be done.
This is what I got so far, don't laugh
Well my only guess is that my question is just too vague for anyone to answer or too long to answer, so I'll try asking something more specific and split it up.
1) I've read another topic/tutorial here on the forum and if I got it correctly, my artillery item would have to fall under a prototype. If current prototype would prove not suitable for it, it is possible to add prototypes to the game trough mods? Also, if it is, do I have access to the code of current vanilla prototype so that I can see how it is and what it does?
2)I just started watching some Lua tutorials, apparently a Table is a collection of variables, and one of each artillery will eventually be just a variable in the game, right? If so, if I want to group them together it means I need to have some kind of "manager" that can keep adding and removing N tables of N artillery variables in it?
3)About opening a minimap and designating the tager area, can this be easily achieved? Meaning the code that currently convert all the entities in the game into a map can just be copy-pasted to have the same functionality in my minimap? Do I have access to that code? What about clicking on said minimap to translate that in coordinates in the world relative from artillery group? There is any obvious obstacles to such feature? Or even opening a tab for the minimap to go in and to manage the groups, does that present some obvious obstacle?
In the meantime I'm following lua tutorials and trying to flash out the idea little by little as a way to practice the language, but I would really appreciate to know beforehand what can and cannot be done.
This is what I got so far, don't laugh
Code: Select all
function Reload(Ammo, Type)
Ammo[Type] = Ammo[Type] - 1
end
function Fire(Ammo, Type)
print("BOOM!!!", Ammo[Type], Type, " left.")
end
----------------------------------------------
inRange = true
isFiring = true
activeAmmo = "ExpShells"
ammoTbl = {ExpShells = 12, IncShells = 4}
while isFiring do
if inRange then
if ammoTbl[activeAmmo] > 0 then
Reload(ammoTbl, activeAmmo)
Fire(ammoTbl, activeAmmo)
else
print("Out of Ammo")
isFiring = false
end
else
print ("Out of Range")
isFiring = false
end
end
- DedlySpyder
- Filter Inserter
- Posts: 253
- Joined: Fri Jun 20, 2014 11:42 am
- Contact:
Re: Question about programming a mod
If you want the player to designate an attack area, then you don't necessarily want turrets (or not turrets with a big range). IIRC, having a large range will lag the game because it will need to constantly check every tile in that range.
I'm not entirely sure if rotating a turret is possible runtime, but check the API here: http://lua-api.factorio.com/latest/
As for making it fire check out the ion cannon mod (drawing a blank on its name), basically the player places an entity down and the mod does damage to that area, you could determine random spots after a bit of time and cause explosions, or fire projectiles manually from the artillery (which would be in the API under surface.create_entity).
Look in the base game for prototypes, and there is a modding tutorial around this area in the forums for the basics of adding stuff to the game.
(on my phone or else I would have given links)
I'm not entirely sure if rotating a turret is possible runtime, but check the API here: http://lua-api.factorio.com/latest/
As for making it fire check out the ion cannon mod (drawing a blank on its name), basically the player places an entity down and the mod does damage to that area, you could determine random spots after a bit of time and cause explosions, or fire projectiles manually from the artillery (which would be in the API under surface.create_entity).
Look in the base game for prototypes, and there is a modding tutorial around this area in the forums for the basics of adding stuff to the game.
(on my phone or else I would have given links)
Re: Question about programming a mod
There are already a couple of mods with artillery, if they don't satisfy your own vision, you can peek into them to learn, how is it done.
https://mods.factorio.com/mods/Buhamut/Artillery
https://mods.factorio.com/mods/sore68/Additional-Turret
Also, this thread viewtopic.php?f=25&t=42627 might be of some relevance.
As well as parts of my signature.
https://mods.factorio.com/mods/Buhamut/Artillery
https://mods.factorio.com/mods/sore68/Additional-Turret
Also, this thread viewtopic.php?f=25&t=42627 might be of some relevance.
As well as parts of my signature.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
If that's true, then it's truly unfortunate. I played a bit few months ago with C++ out of curiosity (and forgot most now =_=) so I'll use pointers & array teminology in my example since I don't know how to call it in Lua or if is there at all, but, instead of checking every single tile in the area for every time you fire and for every projectile, wouldn't be possible to save a list of pointers to only the nests and entities (aliens) associated with them only once at the time you designate the target area(so let's say you end up with around 30 things to track for a group of artillery), organize each pointer at a given index in a multidimensional array to kind of represent the position of this entity on a checkboard and only update the position of the moving units in it (not nests) once every 3 seconds or so? Then the index in that "checkboard" at where the shell hits is random, and it only check to apply damage to entities in indexes in a range of that index.DedlySpyder wrote:IIRC, having a large range will lag the game because it will need to constantly check every tile in that range.
Is this a good or viable way in Lua to do it, and should this reduce or prevent lag?
Anyway I won't probably benefit much from reading game or mod code just right now, so I'm starting with "Programming in Lua" book so I'll check the stuff you guys suggested me later, especcially the bomber mod which could potentially be the most relevant one by the name of it, thanks
Re: Question about programming a mod
I think I can answer your questions one by one, but not very detail to avoid making the answers complicated. Tell us if you want to know more.
But it is great that you can break your question into smaller ones.
Yes, it sucks, but it is mainly due to the heavy optimization in Factorio. These limitations allow the game to run fast.
Each mod has its own global table, you can do anything to it without affecting other mods.
However, things may change in the coming v0.15, as there will be some new APIs.
By the way, besides the two mods mentioned by Adil, I think you will also be interested at these two:
https://mods.factorio.com/mods/Superche ... %20Station
https://mods.factorio.com/mods/Superche ... n%20Cannon
Orbital Ion Cannon lets you fire an area on the map. You mark the target area on the map (not minimap) using a special item. So the range is limited by your reach distance.
You can eliminate the range limit with Satellite Uplink Station. By entering the station, just like entering a vehicle, you will be turned into god mode, which is like playing the sandbox scenario.
C++ is hard to learn, so I don't think lua will be a problem for you. My advice is, don't waste your time on reading generic books about lua. Just pick a small mod and learn from it. You are free to look at the contents of any mod and change its scripts to see the effect (as long as you don't publish it as your own mod of course ).
If you have something not sure about lua, just ask Google. It is what I did when I made Creative Mode, which was my first time to program in lua. And I am still doing it now.
Oh, and we don't say "pointer" in lua, because it cannot be used in lua (and many other languages). We say "reference". E.g. the reference to a turret.
Because this board isn't that famous. Most modders are busy on their mods. May need some time before someone actually read your post.Marcus Aseth wrote:Noone?
Well my only guess is that my question is just too vague for anyone to answer or too long to answer, so I'll try asking something more specific and split it up.
But it is great that you can break your question into smaller ones.
Unfortunately, no. You have to use the prototypes provided by the game. You can use scripts to do something special on top of the existing prototypes, but you can't change their default behaviours, and it is also limited by the APIs. For example, you can teleport a player to another location, but you can't do this to walls, because LuaControl::teleport doesn't allow it.Marcus Aseth wrote:1) I've read another topic/tutorial here on the forum and if I got it correctly, my artillery item would have to fall under a prototype. If current prototype would prove not suitable for it, it is possible to add prototypes to the game trough mods? Also, if it is, do I have access to the code of current vanilla prototype so that I can see how it is and what it does?
Yes, it sucks, but it is mainly due to the heavy optimization in Factorio. These limitations allow the game to run fast.
Yes, you can do it. The "manager" you are looking for is the global table, which is persistent for the save.Marcus Aseth wrote:2)I just started watching some Lua tutorials, apparently a Table is a collection of variables, and one of each artillery will eventually be just a variable in the game, right? If so, if I want to group them together it means I need to have some kind of "manager" that can keep adding and removing N tables of N artillery variables in it?
Each mod has its own global table, you can do anything to it without affecting other mods.
Theoretically, you can make your own minimap by using the find_entities APIs in LuaSurface, and then represent the minimap using a matrix of tiny buttons. But I wonder the performance will be good. If the search area is large, the process will be sloooooow. And making so many GUI elements at a time will definitely make the game lag. That's why you don't see any existing mod with these features.Marcus Aseth wrote:3)About opening a minimap and designating the tager area, can this be easily achieved? Meaning the code that currently convert all the entities in the game into a map can just be copy-pasted to have the same functionality in my minimap? Do I have access to that code? What about clicking on said minimap to translate that in coordinates in the world relative from artillery group? There is any obvious obstacles to such feature? Or even opening a tab for the minimap to go in and to manage the groups, does that present some obvious obstacle?
However, things may change in the coming v0.15, as there will be some new APIs.
By the way, besides the two mods mentioned by Adil, I think you will also be interested at these two:
https://mods.factorio.com/mods/Superche ... %20Station
https://mods.factorio.com/mods/Superche ... n%20Cannon
Orbital Ion Cannon lets you fire an area on the map. You mark the target area on the map (not minimap) using a special item. So the range is limited by your reach distance.
You can eliminate the range limit with Satellite Uplink Station. By entering the station, just like entering a vehicle, you will be turned into god mode, which is like playing the sandbox scenario.
You said you are not a programmer, but you have learnt C++. hm......Marcus Aseth wrote:I played a bit few months ago with C++ out of curiosity
C++ is hard to learn, so I don't think lua will be a problem for you. My advice is, don't waste your time on reading generic books about lua. Just pick a small mod and learn from it. You are free to look at the contents of any mod and change its scripts to see the effect (as long as you don't publish it as your own mod of course ).
If you have something not sure about lua, just ask Google. It is what I did when I made Creative Mode, which was my first time to program in lua. And I am still doing it now.
Oh, and we don't say "pointer" in lua, because it cannot be used in lua (and many other languages). We say "reference". E.g. the reference to a turret.
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
Thank you for the long answer Mooncat, I'll definetely check out those mods linked too once I'm done with the book, even though I'm sure as you suggest one can learn directly from studying mods, I would have never have guessed for example I could have multiple returns from my functions, so in the long run I think is better for me to learn the basics of the language in a more "formal way" before trying to understand what the code does (also the book is from one of the creators of Lua, and I'm around page 65/360 so I'll be done with it soon )
I opened the graphics from the laser turret the other day and saw the spritesheet for when the turret activate and for when it rotates. Let's say my artillery would also need an extra spritesheet for when it fires because the barrel need to go back because of the recoil, my question is, does a particular prototype also imply a fixed number of spritesheets for the graphic or I could just easily add this extra spritesheet for the firing event?
Edit: Also, my true weakness is math and algorithms, I simply suck at it or worst ( the same reason I hadn't had much "room" to apply my c++ syntax knowledge to anything). But if my idea of artillery is that it hits a given range on a multidimensional array and maybe can be increased trough tech research, then I guess I would need to know an algorithm to draw a rasterized circle to mark the "in range" squares on that checkboard, and I do not know it (this is only an example, I simply do not know too much stuff when it comes to math and algorithms). So my question is, there is something that you guys can recomend me, a book maybe or some online material that helped you in the past to become good at this?
I hope this won't be a problem, but I can't know for sure just yet :\Unfortunately, no. You have to use the prototypes provided by the game. You can use scripts to do something special on top of the existing prototypes, but you can't change their default behaviours, and it is also limited by the APIs.
I opened the graphics from the laser turret the other day and saw the spritesheet for when the turret activate and for when it rotates. Let's say my artillery would also need an extra spritesheet for when it fires because the barrel need to go back because of the recoil, my question is, does a particular prototype also imply a fixed number of spritesheets for the graphic or I could just easily add this extra spritesheet for the firing event?
Do I need all those buttons though? Is it possible to track the position of my minimap inside the screen and the mouse coordinates when clicking?Theoretically, you can make your own minimap by using the find_entities APIs in LuaSurface, and then represent the minimap using a matrix of tiny buttons.
Well, knowing some syntax doesn't make me a programmer though if I can't do anything with it xDYou said you are not a programmer, but you have learnt C++. hm......
Edit: Also, my true weakness is math and algorithms, I simply suck at it or worst ( the same reason I hadn't had much "room" to apply my c++ syntax knowledge to anything). But if my idea of artillery is that it hits a given range on a multidimensional array and maybe can be increased trough tech research, then I guess I would need to know an algorithm to draw a rasterized circle to mark the "in range" squares on that checkboard, and I do not know it (this is only an example, I simply do not know too much stuff when it comes to math and algorithms). So my question is, there is something that you guys can recomend me, a book maybe or some online material that helped you in the past to become good at this?
Re: Question about programming a mod
The "algorithm" for making a rasterized circle is following:
There's no just a single book to get good, that circle part is just general knowledge of math and calculus, the drawing part is knowledge of the material you're working with.
I don't think it might be directly applicable here, but the following course does bring some knowledge: https://www.coursera.org/learn/algorith ... de-conquer
Have a look around there, there might be some more basic ones as well.
- choose radius (r) value
x,y,r are connected by the following equation x^2+y^2=r^2
loop through possible x values, calculate the corresponding y
do something you want to do with those coordinates
Lua example of code
The "draw" part really depends on what do you mean. There are commands in api that can be used to spawn entities at these coordinates, as Mooncat said, you can implement your own canvas on which to draw.There's no just a single book to get good, that circle part is just general knowledge of math and calculus, the drawing part is knowledge of the material you're working with.
I don't think it might be directly applicable here, but the following course does bring some knowledge: https://www.coursera.org/learn/algorith ... de-conquer
Have a look around there, there might be some more basic ones as well.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
Thanks Adil, this is quite useful , I was actually curious to see what's going on with the numbers (just print them out since I don't know yet how to draw stuff using lua) so I added one function to do so (code below) but it seems I'm getting only nil values? Probably I'm doing something wrong, any idea?Adil wrote:The "algorithm" for making a rasterized circle is following:
- choose radius (r) value
x,y,r are connected by the following equation x^2+y^2=r^2
loop through possible x values, calculate the corresponding y
do something you want to do with those coordinatesLua example of codeThe "draw" part really depends on what do you mean. There are commands in api that can be used to spawn entities at these coordinates, as Mooncat said, you can implement your own canvas on which to draw.
There's no just a single book to get good, that circle part is just general knowledge of math and calculus, the drawing part is knowledge of the material you're working with.
I don't think it might be directly applicable here, but the following course does bring some knowledge: https://www.coursera.org/learn/algorith ... de-conquer
Have a look around there, there might be some more basic ones as well.
Code: Select all
function printCoord(tbl)
local i = 1
for k,v in pairs(tbl) do
local x, y = table.unpack(v)
point = "Point " .. i .. ") " .. tostring(x) .. " | " .. tostring(y)
print(point)
i = i + 1
end
end
--generate table of circle coordinates
local radius=20
local circle_squares={}
table.insert(circle_squares,{x=radius,y=0})
for x=1,radius-1 do
local y=math.sqrt(radius^2-x^2)
table.insert(circle_squares,{x=x,y=y})
table.insert(circle_squares,{x=x,y=-y})
table.insert(circle_squares,{x=-x,y=y})
table.insert(circle_squares,{x=-x,y=-y})
end
table.insert(circle_squares,{x=0,y=radius})
printCoord(circle_squares)
Code: Select all
function printCoord(tbl)
local i = 1
for k,v in pairs(tbl) do
local x, y = v.x, v.y
point = "Point " .. i .. ") " .. tostring(x) .. " | " .. tostring(y)
print(point)
i = i + 1
end
end
Re: Question about programming a mod
In my code I've missed
and
Code: Select all
table.insert(circle_squares,{x=-radius,y=0})
Code: Select all
table.insert(circle_squares,{x=0,y=-radius})
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
Thanks again Adil, I was actually in the process to learn some Love2d API in order to better visualize what your code is doing (number on a console don't cut it for me), img below. Though it bothers me I lack the knowledge to modify shapes like this at my will trough math, for instance if I wanted something as basic as for the circles to be uniformely distributed along the radius, I would already be having problemsAdil wrote:In my code I've missedandCode: Select all
table.insert(circle_squares,{x=-radius,y=0})
Code: Select all
table.insert(circle_squares,{x=0,y=-radius})
So I will be out for a "online math course" hunt
image
Edit: I've actually kind of get them to distributed almost properly by doing half of a quadrant of the circle based on the x and half based on the y but still, I'm sure there is some fancy math easier to write that yelds a perfect resoult, so I'm looking forward to learn it
image2
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
Ok, so, let's say I have a piece of artillery which is fuel powered and not electric, the sentence "You can use scripts to do something special on top of the existing prototypes" would include using the turret prototype and then extend it in a way that it now has the car/tank/train fuel Gui inventory and burns fuel over time? (this would be the choice I would prefer if possible, since if I have a more advanced artillery that require electricity, they could both be branches of the same turret prototype instead of having one under car and one under turret)Mooncat wrote:Unfortunately, no. You have to use the prototypes provided by the game. You can use scripts to do something special on top of the existing prototypes, but you can't change their default behaviours, and it is also limited by the APIs.Marcus Aseth wrote:1) I've read another topic/tutorial here on the forum and if I got it correctly, my artillery item would have to fall under a prototype. If current prototype would prove not suitable for it, it is possible to add prototypes to the game trough mods?
Or the only way to achieve that would be to base my artillery class on the car prototype and have it be a car in disguise that doesn't move?
And if this where the case, would it be the smart choice or there would be a better one yet? Also would be possible to prevent the player from boarding it or the car prototype implies it is always possible to board it?
Re: Question about programming a mod
Factorio is done in such a way that it is impossible to "extend" prototypes.
Usually you spawn several different entities together, each being of different type and covering some part of your envisioned mechanic.
Canonic example would be Klonan's "ks power" mod in which there are burner generators provided as a composition of a burner, offshore pump and a steam generator. Usually most of such entities are made invisible.
Depending on how much do you want to imitate the vanilla mechanics, you may have to use something like furnace and some dummy recipe. Quick and dirty way would be just a chest from which the fuel would be pulled. Vehicle is a good way too. You will have to either use scripts to kick players out of it though, or to put a dummy player character in it so it is always full.
Usually you spawn several different entities together, each being of different type and covering some part of your envisioned mechanic.
Canonic example would be Klonan's "ks power" mod in which there are burner generators provided as a composition of a burner, offshore pump and a steam generator. Usually most of such entities are made invisible.
Depending on how much do you want to imitate the vanilla mechanics, you may have to use something like furnace and some dummy recipe. Quick and dirty way would be just a chest from which the fuel would be pulled. Vehicle is a good way too. You will have to either use scripts to kick players out of it though, or to put a dummy player character in it so it is always full.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
I see. (I'll number the following questions in case someone has the answer to only some of them)Adil wrote:Factorio is done in such a way that it is impossible to "extend" prototypes.
Usually you spawn several different entities together, each being of different type and covering some part of your envisioned mechanic.
Canonic example would be Klonan's "ks power" mod in which there are burner generators provided as a composition of a burner, offshore pump and a steam generator. Usually most of such entities are made invisible.
Depending on how much do you want to imitate the vanilla mechanics, you may have to use something like furnace and some dummy recipe. Quick and dirty way would be just a chest from which the fuel would be pulled. Vehicle is a good way too. You will have to either use scripts to kick players out of it though, or to put a dummy player character in it so it is always full.
1) Fournace actually seems to me the more logic choice layout wise cause there is exactly 1 slot for the fuel and 1 for the cannon shells, though... I still have not a clear picture how the whole sprite system works. Can I just make an artillery turret out of a fournace and then have the whole rotation/shooting spritesheets associated with it? Or the way a spritesheet gets interpreted and how many of them are expected is dependent on the prototype I choose to use?
Also I'm trying to making sense of the Api document page, but I'm confused...I'm trying to compare what I found in the game code but I have few questions about it:
2)the easy one is, what the punctuation used in the doc stands for? I guess the double colon "::" shows a key::value pair, a "→" shows a return value, but what is "[R]"?
3)the more tricky one is, I'm comparing the base/prototypes/entity/entities.lua "car" prototype with what I see in the LuaEntityPrototype page, but for instance the car prototype has a "burner = ...." table entry, and in the doc page I don't find any reference or explanation for that entry, and the same applies to "flags =" table and other stuff, so...I'm clearly doing something wrong, what am I missing here?
Re: Question about programming a mod
from LuaEntityMarcus Aseth wrote: 2)the easy one is, what the punctuation used in the doc stands for? I guess the double colon "::" shows a key::value pair, a "→" shows a return value, but what is "[R]"?
grid :: LuaEquipmentGrid [R]
LuaEntity would be the "entity" object you are working with.
grid returns the "equipmentgrid" object
[R] means read only, [RW] means read-write
What this means is you can't directly write to the .grid field but it returns a "grid" object which has fields you can access to read/modify stuff
myentity.grid = nil --> not allowed, grid is read-only
myentity.grid.clear() --> remove all items inside the grid belonging to myentity
myentity.grid.equipment --> return a table of LUAequipment found inside the grid of myentity
There is a lot of undocumented stuff like this. This may or may not be expanded on with .15.3)the more tricky one is, I'm comparing the base/prototypes/entity/entities.lua "car" prototype with what I see in the LuaEntityPrototype page, but for instance the car prototype has a "burner = ...." table entry, and in the doc page I don't find any reference or explanation for that entry, and the same applies to "flags =" table and other stuff, so...I'm clearly doing something wrong, what am I missing here?
The burner = ... is a table which tells the car that it is fueled by a burner and sets the amount of fuel etc for the car
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
Thanks for the answer Nexela, I really have no problem reading documentation with a lot of pages, but if I can't get the clear picture by it cause stuff is missing, knowing that alone puts me off quite a bit from even trying...(especially the whole sprite matter where I don't know if I'm limited by the number of spritesheets in the prototype I use, risking of putting the effort in it just to possibly end up with a piece of artillery that can't even have cannon recoil animation, that's a waste of time imo), so I guess I will be waiting for the game to be finished before cheching again and trying modding anything, because by then hopefully there will be full documentation and less restrictions.
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
By the way this is the rough blockout I had so far for my artillery, the part of the cannon that is supposed to recoil during fire is clearly visible, so if you guys have any knowledge about the sprite working that could help me (especially the question 1) two replies above) I'm still interested in the answer and would totally help : )
Re: Question about programming a mod
No you can't, furnace doesn't support 360 rotation for sure. What I've suggested above, is to spawn whatever entity you want to use for the main logic of the cannon and then add a furnace atop of that. I've suggested furnace because it supports fuel eating mechanic, you could put some dummy recipe into it, which would cause the fuel consumption to happen like it does in vanilla entities. It is by no means capable of providing all the functionality you want to implement. More than 4 directions for sprites are only available in `player`, `vehicle`, `unit` and `turret` prototypes.Marcus Aseth wrote:1) Fournace actually seems to me the more logic choice layout wise cause there is exactly 1 slot for the fuel and 1 for the cannon shells, though... I still have not a clear picture how the whole sprite system works. Can I just make an artillery turret out of a fournace and then have the whole rotation/shooting spritesheets associated with it? Or the way a spritesheet gets interpreted and how many of them are expected is dependent on the prototype I choose to use?
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
-
- Inserter
- Posts: 37
- Joined: Tue Dec 13, 2016 9:34 am
- Contact:
Re: Question about programming a mod
Adil wrote:No you can't, furnace doesn't support 360 rotation for sure. What I've suggested above, is to spawn whatever entity you want to use for the main logic of the cannon and then add a furnace atop of that. I've suggested furnace because it supports fuel eating mechanic, you could put some dummy recipe into it, which would cause the fuel consumption to happen like it does in vanilla entities. It is by no means capable of providing all the functionality you want to implement. More than 4 directions for sprites are only available in `player`, `vehicle`, `unit` and `turret` prototypes.Marcus Aseth wrote:1) Fournace actually seems to me the more logic choice layout wise cause there is exactly 1 slot for the fuel and 1 for the cannon shells, though... I still have not a clear picture how the whole sprite system works. Can I just make an artillery turret out of a fournace and then have the whole rotation/shooting spritesheets associated with it? Or the way a spritesheet gets interpreted and how many of them are expected is dependent on the prototype I choose to use?
My bad, I should have edited my previous question instead of copy pasting, I was actually looking for a way to fit the recoil spritesheet into it, not to specifically use it in the furnace prototype, though good to know it can't be done that way.
So you suggested using multiple prototypes, so furnace would be the invisible clicable entity that allows for the fuel consumption, and overlapped with it (with its collision box and click box) there would be a turret prototype entity that provides for the spritesheet.
1)During the targetting phase a function I provide would set the turret current frame in order to have each turret pointing in the right direction, and would keep them pointing that direction until you remove the shooting order (is this doable?)
2)Is the spritesheet size fixed or size limited in any way? If not, I could have a single spritesheet containing both static turret rotation animation and shooting animation for each direction (right?)
3)Now the really important question. If all I've said above is doable, is it possible for me to control when a given frame for a given turret has to be shown trough an external function? I will have another function that takes care of checking every N seconds which group or single artillery piece is ready to fire, at that point the function will tell that turret to cycle trough the animation frames containing the fire animation, the function would play a shooting sound, and then leave the turret current frame set to the one before the shooting animation. Is all I've said doable? I have this kind of control over the displayed frame from a turret at any given time? (this is really the thing I need to know the most)