Page 1 of 1

Modding - Deleting Artifact from Anomaly

Posted: 07 Feb 2018, 17:26
by Arszi
I would like to delete an artifact from an anomaly.
I found this callback function:

Code: Select all

function anomaly_zone_binder:on_artefact_take(obj)
   local id
   if(type(obj.id)=="number") then
      id = obj.id
   else
      id = obj:id()
   end

    parent_zones_by_artefact_id[id] = nil
   artefact_ways_by_id[id] = nil
   artefact_points_by_id[id] = nil
   self.artefact_ways_by_id[id] = nil
   self.artefact_points_by_id[id] = nil
   self.spawned_count = self.spawned_count - 1
   if (self.spawned_count < 0) then
      self.spawned_count = 0
   end
end


My question is:

I won't pick up the artifact, it should be removed from the game for good. Will running the code above with the current artifact object do the trick, or should I call

Code: Select all

safe_release_manager.release(obj)
too, to avoid potential memory leaks?

Re: Modding - Deleting Artifact from Anomaly

Posted: 08 Feb 2018, 06:13
by luppolo
just remove the artifacts from the anomaly config files without messing with the code

Re: Modding - Deleting Artifact from Anomaly

Posted: 08 Feb 2018, 06:28
by Balathruin
luppolo wrote:just remove the artifacts from the anomaly config files without messing with the code

I don't think you understand what he wants.

Re: Modding - Deleting Artifact from Anomaly

Posted: 08 Feb 2018, 06:41
by luppolo
Balathruin wrote:
luppolo wrote:just remove the artifacts from the anomaly config files without messing with the code

I don't think you understand what he wants.

if the artifact doesnt spawn to begin with then nobody (player or npc) can pick it up

Re: Modding - Deleting Artifact from Anomaly

Posted: 08 Feb 2018, 07:32
by Arszi
I am working on a mod, which spawns artefacts by dynamic percentage in anomalies (For example, anomalies in Cordon will have 10% chance to spawn artefacts during blowout), then at the next blowout, it will remove/delete every artefacts from the anomalies, and spawnsnew ones with a certain percentage randomly.
I just used the "pick up" code, to reset the anomalies.

My original question was, that resetting an anomaly like this is enough, or I should release the artefacts? I want them to cease to exists, a safe way, which won't cause any long term issues with saved games, etc.

Re: Modding - Deleting Artifact from Anomaly

Posted: 08 Feb 2018, 13:58
by luppolo
i think that when an artifact is spawned in an anomaly it exists as regular item, it's just a guess since when i load a game i often see the log message saying af_whatever is spawned, if that's true then just iterating all objects and calling

Code: Select all

alife():release(obj,true)

before an emission should do, of course you'll need to do some finer checks to not delete also all artifacts in stashes, on npc etc

Re: Modding - Deleting Artifact from Anomaly

Posted: 08 Feb 2018, 20:13
by Arszi
Thank you,

Code: Select all

alife():release(obj,true)
does the trick.
I store the artefact id-s in a dictionary, and get the object back by alife():object(id) to release. This way I can not do any harm to artefacts in NPC inventory, stash, etc.