I'm assigning a quest through a dialogue and would like the player to recieve a fixed quest item (the obvious letter) with it. I tried
Code: Select all
on_grant = function(self, who)
game.log("Creating letter …")
local o = game.zone:makeEntity(game.level, "object", {type="misc", subtype="scroll", defined="LETTER"})
if o then
o:identify(true)
who:addObject(who.INVEN_INVEN, o)
game.zone:addEntity(game.level, o, "object")
game.logPlayer(who, "You receive: %s", o:getName{do_color=true})
else
game.log("Letter creation failed.")
end
end
- Line 3: creating the letter fails. I have a “newEntity{}” definition in data/general/objects/misc-quest.lua that works correctly for inventory assignments during character creation, so I assumed I could access it this way. What would be the right way to access predefined entities?
- b Line 6: when temporarily replacing line 3 by some random item (say, ammo) the script fails with a Lua error “attempt to index local 'who' (a nil value)”. I assumed that this “who” is supposed to be the player as for instance in staff-absorption.lua and, therefore, I could use addObject the same way as ring_gift in mage-apprentice.lua. What am I doing wrong?