On_Kill question using code that worked for cloning self.

Have a really dumb question? Ask it here to get help from the experts (or those with too much time on their hands)

Moderator: Moderator

Post Reply
Message
Author
xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

On_Kill question using code that worked for cloning self.

#1 Post by xnd »

[changed subject title of thread from "Mess" thread. new question down below.]


Trying to pull errors out of the following mess which used to be "Inner Demons" talent ... while not knowing what I am doing :oops: at all.

newTalent{
name = "Must Kill Another",
--code altered from Inner Demons
type = {"race/Chrono_Xorn", 1},
points = 1,
mode = "passive",
require = racial_req1,
cooldown = 0,
paradox = 0,
range = 1000000,
direct_hit = true,
requires_target = true,
getChance = function(self, t)
return 50
end,
on_kill = function(self, t, target)
summon_inner_demons = function(self, target, t)
-- Find space
local x, y = util.findFreeGrid(target.x, target.y, 1, true, {[Map.ACTOR]=true})
if not x then
return
end
--if target:attr("summon_time") then return end

local m = target:cloneFull{
shader = "shadow_simulacrum",
shader_args = { color = {0.6, 0.0, 0.3}, base = 0.6, time_factor = 1500 },
no_drops = false, keep_inven_on_death = false,
faction = "enemies",
summoner = self, summoner_gain_exp=false,
summon_time = 1000000,
ai_target = {actor=target},
ai = "summoned", ai_real = "tactical",
name = ""..target.name.."'s more dangerous self from another timeline",
desc = [[A temporal clone that resembles the creature it came from but seems more dangerous.]],
}
m:removeAllMOs()
m.make_escort = nil
m.on_added_to_level = nil
m.on_added = nil

mod.class.NPC.castAs(m)
engine.interface.ActorAI.init(m, m)

m.exp_worth = 1
m.energy.value = 1
m.player = nil
m.max_life = m.max_life / 4 / m.rank
m.life = util.bound(m.life, 0, m.max_life)
m.inc_damage.all = (m.inc_damage.all or 0) - 50
m.forceLevelup = function() end
m.on_die = nil
m.die = nil
m.puuid = nil
m.on_acquire_target = nil
m.no_inventory_access = true
m.on_takehit = nil
m.seen_by = nil
m.can_talk = nil
m.clone_on_hit = nil
m.self_resurrect = nil
--if m.talents.T_SUMMON then m.talents.T_SUMMON = nil end
--if m.talents.T_MULTIPLY then m.talents.T_MULTIPLY = nil end

-- Inner Demon's never flee
m.ai_tactic = m.ai_tactic or {}
m.ai_tactic.escape = 0

-- Remove some talents
local tids = {}
for tid, _ in pairs(m.talents) do
local t = m:getTalentFromId(tid)
if t.no_npc_use then tids[#tids+1] = t end
end
for i, t in ipairs(tids) do
if t.mode == "sustained" and m:isTalentActive(t.id) then m:forceUseTalent(t.id, {ignore_energy=true}) end
m.talents[t.id] = nil
end

-- remove detrimental timed effects
local effs = {}
for eff_id, p in pairs(m.tmp) do
local e = m.tempeffect_def[eff_id]
if e.status == "detrimental" then
effs[#effs+1] = {"effect", eff_id}
end
end

while #effs > 0 do
local eff = rng.tableRemove(effs)
if eff[1] == "effect" then
m:removeEffect(eff[2])
end
end

-- make more dangerous
-- inc_stats = { str=20, mag=20, wil=20, cun=20, dex=20, con=20, lck=20 },

game.zone:addEntity(game.level, m, "actor", x, y)
game.level.map:particleEmitter(x, y, 1, "generic_teleport", {rm=60, rM=130, gm=20, gM=110, bm=90, bM=130, am=70, aM=180})

game.logSeen(target, "#F53CBE#%s's more survivable self from another timeline manifests!", target.name:capitalize())

end,
action = function(self, t)
--[THE CURRENT ERROR says there is an unexpected symbol near the above '=', but this code I did not even change so what does the error mean? This error wont let the race screen load.]--
local tg = {type="hit", range=self:getTalentRange(t), talent=t}
local x, y = self:getTarget(tg)
if not x or not y then return nil end
local _ _, x, y = self:canProject(tg, x, y)
if not x or not y then return nil end
local target = game.level.map(x, y, Map.ACTOR)
if not target then return nil end
end

end,
info = function(self, t)
return ([[When you kill a creature, you have a 50 percent chance to summon its clone from another timeline, one that is more likely to survive.]])
end,
}
Last edited by xnd on Tue May 05, 2015 9:23 pm, edited 3 times in total.

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Talent Code MESS here, so what advice please?

#2 Post by HousePet »

When pasting large sections of code, it is useful to use something like pastebin, which keeps the tabbing intact and can be set to colour code it as lua code.

As for the issue, why do you have an action for a passive talent anyway?
My feedback meter decays into coding. Give me feedback and I make mods.

xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

Re: Talent Code MESS here, so what advice please?

#3 Post by xnd »

i did get rid of that part of the code but the error remained. but i also wanted to know why it is saying there is an error in something i didnt even alter and how i can know what symbol this kind of error refers to.

xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

Re: Talent Code MESS here, so what advice please?

#4 Post by xnd »


HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Talent Code MESS here, so what advice please?

#5 Post by HousePet »

Line 105 of the pastebin stuff has a comma at the end of the line.
KILL IT!
My feedback meter decays into coding. Give me feedback and I make mods.

xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

Re: Talent Code MESS here, so what advice please?

#6 Post by xnd »

how can I tell when to put a comma or not to? it seems sometimes it is there and sometimes not there. what does the code determine from its use or lack?

anyway, making a talent load that doesnt do anything isnt very useful so I still need help making it actually work!

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Talent Code MESS here, so what advice please?

#7 Post by HousePet »

Commas are used for delineating elements in a table.
My feedback meter decays into coding. Give me feedback and I make mods.

xnd
Archmage
Posts: 307
Joined: Sat Mar 21, 2015 7:33 pm

Re: Talent Code MESS here, so what advice please?

#8 Post by xnd »

Below I tried to take a clone code that I did get to work and set it to clone the target I just killed by doing
on_kill = function(self, t) instead of action = function (self, t)

and change
local m = require("mod.class.NPC").new(self:cloneFull{

to
local m = require("mod.class.NPC").new(target:cloneFull{

but it does nothing.



newTalent{
short_name = "MUST_KILL_ANOTHER",
name = "Must Kill Another",
image = "talents/anomaly_swap.png",
type = {"race/Chrono_Xorn", 1},
no_npc_use = true,
no_unlearn_last = true,
points = 1,
mode = "passive",
require = racial_req1,
cooldown = 0,
paradox = 0,
range = 1000000,
direct_hit = true,
requires_target = true,
getDuration = function(self, t) return math.floor(self:combatTalentLimit(t, 50, 50, 50)) end, -- Limit <50
getModifier = function(self, t) return rng.range(t.getDuration(self,t)*2, t.getDuration(self, t)*4) end,
getChance = function(self, t)
return 50
end,
on_kill = function(self, t)
local tg = self:getTalentTarget(t)
local x, y = util.findFreeGrid(self.x, self.y, 3, true, {[Map.ACTOR]=true})
if not x then
return
end

local m = require("mod.class.NPC").new(target:cloneFull{
no_drops = true, keep_inven_on_death = false,
faction = enemies,
summoner = nil, summoner_gain_exp = false,
exp_worth = 1,
summon_time = t.getDuration(self, t),
ai_target = {actor=self},
ai = "summoned", ai_real = "tactical",
ai_tactic = resolvers.tactic("ranged"), ai_state = { talent_in=1, ally_compassion=-100},
desc = [[A temporal clone of an enemy you recently killed.]]
})

m:removeAllMOs()
m:setPersonalReaction(self, -100)
m:attack(self)
m.make_escort = nil
m.on_added_to_level = nil

m.energy.value = 0
m.player = nil
m.puuid = nil
m.max_life = m.max_life
m.life = util.bound(m.life, 0, m.max_life)
m.forceLevelup = function() end
m.die = nil
m.on_die = nil
m.on_acquire_target = nil
m.seen_by = nil
m.can_talk = nil
m.on_takehit = nil
m.faction = "enemies"
m:setPersonalReaction(self, -100)
m.target = self
m.no_inventory_access = true
m.clone_on_hit = nil
m.remove_from_party_on_death = nil

game.zone:addEntity(game.level, m, "actor", x, y)
game.level.map:particleEmitter(x, y, 1, "temporal_teleport")
game:playSoundNear(self, "talents/teleport")

return true
end,

info = function(self)
local duration = t.getDuration(self, t)
return
([[When you kill a creature, you have a 50 percent chance to summon its clone from another timeline, one that is more likely to survive.]]) :format(duration)
end,
}

What did I do to make it not work?




I also tried

-- Random Anomaly on kill, code adapted from void horror

on_kill = function(self, who)
local ts = {}
for id, t in pairs(self.talents_def) do
if t.type[1] == "race/onkill" then ts[#ts+1] = id end
end
self:forceUseTalent(rng.table(ts), {ignore_energy=true})
game.logSeen(self, "%s has brought in an enemy from another timeline.", self.name:capitalize())
end,


where I changed the talent tree from anomally to one I made where the only anomally I stuck in it was the temporal clone anomally to clone a random nearby creature, but even though the anomally works fine in the game, trying to use it myself _exactly_ as coded in the game, copy and pasted, makes it give nil value error to the paradoxclone at
local m = makeParadoxClone(self, a, getAnomalyDuration(self, t)*2)

How do I resolve this nil value issue?

--

Nil values are screwing me all over the place, so I need to know why.

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: On_Kill question using code that worked for cloning self

#9 Post by HousePet »

Just changing the action function to on_kill won't do anything. the game doesn't know to run it ever.
Lookup callbacks.

The nil issue is probably that getAnomalyDuration() isn't defined.
My feedback meter decays into coding. Give me feedback and I make mods.

Post Reply