![Question :?:](./images/smilies/icon_question.gif)
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
![Sad :(](./images/smilies/icon_e_sad.gif)
my first post
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()
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)
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:Actually you can do regeneration bonuses with some hacking around.
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:blocks player movement with teleportation every tick)
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).Devcod wrote:bleeding is nice