Stranded: Alien Dawn

Stranded: Alien Dawn

Stranded: Alien Dawn Workshop
Explore other users workshop creations, upload, download and subscribe to new content
Battering_Ram 7 2023 年 7 月 20 日 上午 9:55
Regeneration
Hi I have a mod that incorporates things from Rimworld, and I am trying to create luciferium. I will modify the infected eye condition to make it. I am trying to create an item that removes a health condition with timer, where can I find the library of commands and or how can I make the item remove a permanent injury?
< >
正在显示第 1 - 12 条,共 12 条留言
Mnementh 21 2023 年 7 月 20 日 下午 11:33 
Hi, Battering_Ram!

There are several ways you can modify a permanent health condition to make it no longer permanent that I can think of.

1. Making the condition treatable:
  • Create a duplicate of the health condition and assign it the same ID. Alternatively, you can use a Lua script to modify the vanilla properties in the HealthConditions table.
  • Set "Status" to "requires treatment" and include "Medicine resource" and "Medicine amount," where the resource refers to the ID of your new item.
  • Now, whenever survivors acquire this condition, they will be able to heal it using the designated medicine.

2. Making the resource consumable (similar to smokeleaf pipes and stimulants):
  • Mark the resource as "Consumable" and "Vegetarian" in its definition.
  • Define a new "Consumption type," which allows the player to instruct the survivor to consume the item.
  • Modify the permanent Health condition to react to the consumption of the item. In "Msg Reactions," add a reaction to the Event "UnitConsumedRes" with the following code:
    if unit:HasHealthConditionById(self.id) and res == "add_your_resource_id_here" then unit:RemoveHealthConditions(self.id) end
  • Now, whenever the player instructs the survivor to consume the resource, all instances of this health condition will be removed.

Below is a list of commonly used health condition-related functions:
  • AddHealthCondition(id): This function adds a new instance of the health condition with the specified ID to the unit.
  • HasHealthConditionById(id): It checks if the unit has a health condition with the given ID and returns a boolean value.
  • RemoveHealthConditions(id): This function removes all instances of the health condition associated with the provided ID from the unit.
  • RemoveHealthCondition(condition): Use this function to remove the specific instance of the given health condition from the unit.
最后由 Mnementh 编辑于; 2023 年 7 月 20 日 下午 11:52
Battering_Ram 7 2023 年 7 月 27 日 下午 1:18 
引用自 Mnementh
sorry to attempt to get you to do my work but I am not really a programmer, I get how to remove a specific health condition but how would I go about removing a random health condition that is treatable? Or what is the function that heal action calls to turn a untreated wound into a treated one? Chat GPT does make suggestions but it is stabbing in the darkness...
Mnementh 21 2023 年 7 月 28 日 上午 2:52 
引用自 Battering_Ram
sorry to attempt to get you to do my work but I am not really a programmer, I get how to remove a specific health condition but how would I go about removing a random health condition that is treatable? Or what is the function that heal action calls to turn a untreated wound into a treated one? Chat GPT does make suggestions but it is stabbing in the darkness...
Let's assume you have created a new resource that can be consumed and heals 1 health condition upon consumption. The code needed for this resource to work might look something like the following:

function UnitHealth:HealRandomHealthConditions(count) local count = count or 1 local healed = 0 local status_effects = self.status_effects for item = #(status_effects or ""), 1, -1 do local effect = status_effects[item] if IsKindOf(effect, "HealthCondition") and effect.TreatmentStatus == "requires treatment" then self:TreatHealthCondition(effect, 10, self) healed = healed + 1 end if healed >= count then break end end end OnMsg.UnitConsumedRes = function(unit, res, amount, consumption_type, shelf_life_percent, res_info, variety) if res == "add_your_resource_id_here" then unit:HealRandomHealthConditions(1) end end

  • self.status_effects stores all health conditions and happiness factors that the human has acquired, sorted in the order of acquisition. So, this implementation will heal the oldest acquired injury or illness.
  • self:TreatHealthCondition(condition, healers_healing_level, healer): This function replaces the specified instance of a health condition with its treated version, or removes it entirely if there's no treated version available.
最后由 Mnementh 编辑于; 2023 年 7 月 28 日 上午 8:33
Battering_Ram 7 2023 年 7 月 29 日 下午 1:01 
thank you for the feedback @Mnementh ! i will try it out soon as I can
Battering_Ram 7 2023 年 7 月 29 日 下午 3:11 
So one last question I managed that to get that to fire then I wanted to make a genetic version of this, as a trait. On ObjUpdate I am running the following script.

function UnitHealth:HealRandomHealthConditions()
local status_effects = self.status_effects
for item = #(status_effects or ""), 1, -1 do
local effect = status_effects[item]
if IsKindOf(effect, "HealthCondition") and effect.TreatmentStatus == "requires treatment" then
self:TreatHealthCondition(effect, 10, self.id)
end
end
end

local interval = const.HourDuration*5
if time / interval == (time + update_interval) / interval then

unit:HealRandomHealthConditions(1)
return
end

But it is failing to heal.

just to test I added : target:AddHealthCondition("Migraine", self.id)
above unit:HealRandomHealthConditions(1) and the migraine fired correctly...

My suspicion is I have a syntax error, I think this will be my last question regarding the healing system...
Mnementh 21 2023 年 7 月 29 日 下午 10:25 
Do not place the function UnitHealth:HealRandomHealthConditions() in ObjUpdate. Doing so will cause the function to be declared repeatedly, which is pointless. Instead, place it in a Code asset. Once it's loaded, it will be available for all humans and animals.

Next, in your Trait, add the following code to the AddTrait(self, unit) function property:
unit.regeneration_delay = 5 * const.HourDuration unit.next_regeneration = GameTime() + unit.regeneration_delay
Also, add a "Unit reaction" for the "OnObjUpdate" event with the following code:
if not target.next_regeneration then self:OnAddTrait(self, target) end if time > target.next_regeneration then target:HealRandomHealthConditions(1) target.next_regeneration = time + target.regeneration_delay end

  • OnAddUpdate happens when the character is spawned and gets the trait.
  • To protect old savegames, the OnObjUpdate code checks if the character that has this trait has the OnAddUpdate properties set, and if not, calls the function to be executed again.
  • Then, the code checks if we have reached the time for the next regeneration, clears a single health condition, and sets a new interval.
最后由 Mnementh 编辑于; 2023 年 7 月 29 日 下午 11:29
Battering_Ram 7 2023 年 7 月 29 日 下午 11:52 
Ah I see yeah that makes more sense :steamthis:
Battering_Ram 7 2023 年 7 月 30 日 上午 4:26 
I updated it here and unfortunately it is still not working, I took 5 hours down to one just to test. The script is separate and the trait has all the qualities you have suggested. I am making a tiny mistake somewhere. I am so close I can almost taste it, I wish I understand programming but I am coming from zero. Still very impressed with what I was able to do so far :D
Battering_Ram 7 2023 年 7 月 30 日 上午 4:26 
Mod name is RimRims
Mnementh 21 2023 年 7 月 30 日 上午 5:33 
引用自 Battering_Ram
I updated it here and unfortunately it is still not working, I took 5 hours down to one just to test. The script is separate and the trait has all the qualities you have suggested. I am making a tiny mistake somewhere. I am so close I can almost taste it, I wish I understand programming but I am coming from zero. Still very impressed with what I was able to do so far :D
self:TreatHealthCondition(effect, 10, self.id)
should be:
self:TreatHealthCondition(effect, 10, self)
The function requires reference to the unit, not its ID.
Battering_Ram 7 2023 年 7 月 30 日 上午 5:59 
finaly! Thank YOu so much!
injto4ka 30 2023 年 7 月 30 日 上午 10:05 
@Battering_Ram when coding in mods it is very useful to monitor the game logs for errors. I recommend you to read the pinned post "Advanced modding tips" in the workshop discussion section.
< >
正在显示第 1 - 12 条,共 12 条留言
每页显示数: 1530 50

发帖日期: 2023 年 7 月 20 日 上午 9:55
回复数: 12