technology effects

Place to get help with not working mods / modding interface.
etn
Burner Inserter
Burner Inserter
Posts: 7
Joined: Mon Aug 18, 2014 2:21 am
Contact:

technology effects

Post by etn »

what are all of the technology effects :?:
I was going to make a player upgrade mod, so you could research a technology that gives you +1% max health and health regen, then found that the effects seem to be hardcoded and I don't know if its even possible :(
my first post
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: technology effects

Post by FreeER »

Yes the effects are hardcoded, I answered a post fairly similar to this here, so check that post and feel free to ask any questions you still have afterwards :)
etn
Burner Inserter
Burner Inserter
Posts: 7
Joined: Mon Aug 18, 2014 2:21 am
Contact:

Re: technology effects

Post by etn »

well that's sad... :cry:
but at least I can change the players character to a better one
etn
Burner Inserter
Burner Inserter
Posts: 7
Joined: Mon Aug 18, 2014 2:21 am
Contact:

Re: technology effects

Post by etn »

actually, how do you switch the character to a new one? when I try, it crashes :?
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: technology effects

Post by FreeER »

etn wrote:actually, how do you switch the character to a new one? when I try, it crashes :?

Code: Select all

oldchar = game.player.character
newCharacter = game.createentity{name = "player", position = oldchar.position, force = oldchar.force}
game.player.character = newCharacter
-- swap inventories here
oldchar.destroy()
should work :)
Devcod
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Aug 08, 2014 8:14 pm
Contact:

Re: technology effects

Post by Devcod »

Actually you can do regeneration bonuses with some hacking around.
You can check if technology is researched, you can run function every tick, you can have some global variables. So what is a problem? Of course you don't have real values for regeneration (how much per how many ticks) but you can guess them. And it will be really slowing the game down.

So there is some code with base regeneration rate of 1 health every 60 ticks (1 second):

Code: Select all

glob.yourmod = {}
glob.yourmod.bonuses = {
  ["regen"] = {0, 0}, -- solid/static health regenerated | % of baseRegen regenerated
}
glob.yourmod.regenTime = 60 -- how often health is regenerated in ticks
glob.yourmod.baseRegen = 1 -- how much health is regenerated in regenTime by default

function healthBonus()
  local technologies = {
    [1] = {
      ["name"] = "your-tech-1", -- tech name
      ["regen"] = {10, 0} -- adds 10 health every time when game.tick % glob.yourmod.regenTime == 0
    },
    [2] = {
      ["name"] = "your-tech-2", -- tech name
      ["regen"] = {0, 500} -- adds 500% * glob.yourmod.baseRegen (=5) health every time when game.tick % glob.yourmod.regenTime == 0
    },
  }

  for index, technology in pairs(technologies) do
    if game.player.force.technologies[ technology["name"] ].researched == true then
      glob.yourmod.bunuses["regen"][1] = glob.yourmod.bunuses["regen"][1] + technology["regen"][1]
      glob.yourmod.bunuses["regen"][2] = glob.yourmod.bunuses["regen"][2] + technology["regen"][2]
    end
  end
end

game.onevent(defines.events.ontick, function(event)
  healthBonus()
  if glob.yourmod.bonuses["regen"][1] > 0 then
    if game.tick % glob.yourmod.regenTime == 0 then
      game.player.character.health = game.player.character.health + glob.yourmod.bonuses["regen"][1]
    end
  end
  if glob.yourmod.bonuses["regen"][2] > 0 then
    if game.tick % glob.yourmod.regenTime == 0 then
      game.player.character.health = game.player.character.health + ( glob.yourmod.baseRegen * ( glob.yourmod.bonuses["regen"][2] / 100 ) )
    end
  end
end)
This is not real code - I don't have access to Factorio right now, so there most probably are errors in this script. If it does work then it should regenerate 10 health if you have your-tech-1 and another 5 health if you have your-tech-2. At first I also wanted to add max health but it is not exposed anywhere so it is impossible right now.

In almost same way I have written Paralyse and Bleeding effects (I don't have access to them right now). It is sort of "proof of concept" and not real deal. Paralyse isn't even working as indented (lack of exposed API, blocks player movement with teleportation every tick), but bleeding is nice - do X damage every Y tick/second/minute/hour for Z ticks/seconds/minutes/hours (like 10 damage every 10 tick for 60 ticks resulting in total 60 damage done).
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: technology effects

Post by FreeER »

Devcod wrote:Actually you can do regeneration bonuses with some hacking around.
Yep, it's possible, I didn't mention it mostly because I didn't think to, which is probably because I personally prefer to let the C++ code do as much work as it can (since it's presumably been 'optimized' for doing that work already), and only write the code necessary to make the C++ code realize that I want it to do something, and so I sometimes don't think about mentioning that the same could be done more manually (also, the post that I pointed to was asking about inventory and that would be difficult, if not impossible, to do without character swapping; at least in such a way that the player can just as easily access all of the items, well unless it was just based on stack compression...eh you see the point I was trying to make, hopefully).
Devcod wrote:blocks player movement with teleportation every tick)
how about using game.player.character.active = false? Not sure if that affects crafting however, and it might also affect being able to operate entities so..depends on specific use.
Devcod wrote:bleeding is nice
I don't suppose you're using the poison effect for that? Hm, just checked into how that might be used and it looks like the poison cloud would actually have to be teleported on top of the player to continually damage them (which kind of makes sense lol), so maybe not any better than a simple set of lua vars (especially if you needed to change the amount of damage dynamically).

Not to say that either way is 'the' best of course, just my preference and thus the cloud through which I think. Thanks for mentioning it Devcod, always useful to learn new things (or to be reminded of them, as the case may be).
Post Reply

Return to “Modding help”