Questions on Prototype/Car

Place to get help with not working mods / modding interface.
Post Reply
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Questions on Prototype/Car

Post by Schallfalke »

Hello everyone,

I have several questions about Prototype/Car. Would appreciate if some devs or experts could answer (some of) my questions:
  1. Does anyone successfully get "healing_per_tick" property working on cars, or how does it work out? I tried to add that to vanilla car, tank, or my modded vehicles. But none of the vehicles have their health regenerated. I have code (in data.lua) like the following:

    Code: Select all

    data.raw.car.car.healing_per_tick = 0.5
    
  2. What does "tank_driving" property exactly do? I cannot tell any differences by setting it to "true". (Default is "false".)
  3. Is it possible to use this prototype to create a mech-like vehicle, which can move like the player character? (Move in steps in four directions, rather than car-like forward/rotate/backward.)
  4. Is it possible to apply different types of animations (with "idle", "running", "running_with_gun" like in Types/CharacterArmorAnimation) to make a mech-like vehicle? I ask this because Prototype/Car only has "animations" property that is type "RotatedAnimation", which is different from Prototype/Character that "animations" property with type "table of CharacterArmorAnimation". I tried to "borrow" the vanilla player character animations, but only one set of them can be used in Prototype/Car... "running" set looks best in movement and changing direction, but it suffers when not moving. "running_with_gun" set may look best as it is carrying a gun, but actually looks awful in changing direction though.
  5. If answer to 3 is NO, are there any alternative prototype to use, while players can still "enter" it to take control? To my findings, there are three other main prototypes that are similar, but cannot be used for creating a mech-like vehicle:
    1. Prototype/Locomotive or Prototype/*Wagon: They are bounded on rails, so I am not interested in that.
    2. Prototype/Unit: Seems they are controlled by AI, and players cannot "enter" it to take control.
    3. Prototype/Character: Animation-wise it is the best. But is it possible to use that and make it as a controllable vehicle?
Overall, any suggestions to creating a mech entity with good looks and good controls? I am actually planning a mod for controllable mech. That is why I ask the above questions trying to "exploit" the properties of Prototype/Car, or any other prototypes that can fit this purpose. Any inputs to make this closer to success are sincerely welcomed!

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Questions on Prototype/Car

Post by DaveMcW »

You can "upgrade" a player character to a mech character.

Code: Select all

function swap_character(player)
  if not player or not player.character then return end
  local old_character = player.character
  if player.character.name == "character" then
    player.character = player.surface.create_entity{name="mech", position=player.position, force=player.force}
    old_character.destroy()
  elseif player.character.name == "mech" then
    player.character = player.surface.create_entity{name="character", position=player.position, force=player.force}
    old_character.destroy()
  end
end

Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: Questions on Prototype/Car

Post by Schallfalke »

DaveMcW wrote:
Sat Dec 21, 2019 4:29 pm
You can "upgrade" a player character to a mech character.

Code: Select all

function swap_character(player)
  if not player or not player.character then return end
  local old_character = player.character
  if player.character.name == "character" then
    player.character = player.surface.create_entity{name="mech", position=player.position, force=player.force}
    old_character.destroy()
  elseif player.character.name == "mech" then
    player.character = player.surface.create_entity{name="character", position=player.position, force=player.force}
    old_character.destroy()
  end
end
Thanks for the idea and the technique, I will test it to see how the whole system would change to work.
Though I already foresee some problems, like the "mech" will not consume fuel like if declared as car/vehicle, also it would be tricky (though doable by script checking gun inventory) to set some mech-only guns (to prevent them from being equipped by normal characters).
The end result will probably more like "morphing" player into the giant/titan race. :lol:
Oh well, maybe changing the theme of the mod would fit better to this approach. So I will consider DaveMcW's approach as a separate race mod though, thanks.

PS: Still looking for ways to create mech-like vehicle, so answers to the above 5 questions would help.

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Questions on Prototype/Car

Post by Honktown »

I have a mod which removes healing from biters and adds a different kind. To apply the behavior to other entities would be adding/reassigning a single function (I do generic healing, based on max health or a flat value, so it literally doesn't matter what type of entity it is, as long as it has those). My healing is also applied to spawned entities... didn't realize at the time the enemies are of unit type and spawners are of spawner type. It works so eh, I'm leaving my behavior for now.


To change it to work for you, you'd only need to change what types of entities healing can be applied. To do it dynamically, using on_built_entity would probably work best. Scan for the specific type or property and "register" the type so it starts healing when damaged. To do it statically, just comment the registration event line and add it to whatever I called the healing name/types table. (I think it's a table of names with amount = something in a subtable)

https://mods.factorio.com/mod/DelayedRegen

backend/regenlogic.lua
Comment this line (end of file):

Code: Select all

script.on_event(defines.events.on_entity_spawned, entity_spawned)
Line 42:

Code: Select all

global.entity_prototypes = global.entity_prototypes or {}
The table is [name] = {amount = number}. This is a flat value added to health every healing interval (I implicitly convert heal per tick and percent/flat and stuff to a flat amount per healing interval, for a minor optimization).

To re-make the mod for your own use, you may want to find-and-replace the settings and such, or just remove the settings value and hand-code the values you want. Also there's log prints in the on_configuration_changed (might want to get rid of those).

My license is Public Domain and I use comments (seriously why don't people have more comments?!?!). Go crazy.

Edit: the way I have my settings may also be wrong and broken lol, because if the value doesn't exist, that implied the table doesn't exist... which would throw a field error. I did it like that because I learned it from something else.
I have mods! I guess!
Link

Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: Questions on Prototype/Car

Post by Schallfalke »

Honktown wrote:
Mon Dec 30, 2019 5:36 pm
I have a mod which removes healing from biters and adds a different kind. To apply the behavior to other entities would be adding/reassigning a single function (I do generic healing, based on max health or a flat value, so it literally doesn't matter what type of entity it is, as long as it has those). My healing is also applied to spawned entities... didn't realize at the time the enemies are of unit type and spawners are of spawner type. It works so eh, I'm leaving my behavior for now.
Thanks for the info. Your comment led me to a deeper knowledge about health regen.
The delay is currently applied only to player characters. Guess you have found this as a fact, so you made such a dedicated mod to handle this.

And I having the feeling that normal regenerations are applied only to type "unit", "unit-spawner" and "turret" which are also exclusively coded.
And I have a further feeling that "healing_per_tick" is exclusively applied only to above-mentioned entities, although it exists for all entities under Prototype/EntityWithHealth.
Guess it is related to overhead (UPS) concens, but just want someone who knows the game to confirm this bahaviour.
To change it to work for you, you'd only need to change what types of entities healing can be applied. To do it dynamically, using on_built_entity would probably work best. Scan for the specific type or property and "register" the type so it starts healing when damaged. To do it statically, just comment the registration event line and add it to whatever I called the healing name/types table. (I think it's a table of names with amount = something in a subtable)

https://mods.factorio.com/mod/DelayedRegen

...

To re-make the mod for your own use, you may want to find-and-replace the settings and such, or just remove the settings value and hand-code the values you want. Also there's log prints in the on_configuration_changed (might want to get rid of those).

My license is Public Domain and I use comments (seriously why don't people have more comments?!?!). Go crazy.

Edit: the way I have my settings may also be wrong and broken lol, because if the value doesn't exist, that implied the table doesn't exist... which would throw a field error. I did it like that because I learned it from something else.
Thanks for the offer. I would certainly cite your mod whenever I have used any part of your code.
Just do not expect me to do it soon, since my mod would not come soon... I am still finding possibilities NOT to hack use Prototype/Character, since such use can cause conflicts to those mods that are modifying character properties.

Post Reply

Return to “Modding help”