Page 1 of 1

adding objects on quest grant

Posted: Sun May 30, 2010 2:29 pm
by Old Tomnoddy
Hi,

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
in the quest script but I have at least two problems with this code.
  • 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?
Thanks in advance for any help!

Re: adding objects on quest grant

Posted: Sun May 30, 2010 2:39 pm
by darkgod

Code: Select all

    local o = game.zone:makeEntityByName(game.level, "object", "LETTER")
I assume your entity does a define_as = "LETTER" ?

As for the lack of "who", well done! You have spotted a bug! ;)
For now you can just use game.player, it'll be fixed in beta3 (coming today)

Re: adding objects on quest grant

Posted: Sun May 30, 2010 2:56 pm
by Old Tomnoddy
My letter looks as follows:

Code: Select all

newEntity{ define_as = "LETTER",
    unique = true, quest=true,
    type = "misc", subtype="scroll",
    unided_name = "A Letter",
    name = "Letter to Reciever",
    display = "?", color=colors.KHAKI,
    encumber = .1, 
    desc = [[Standard quest item.]],

    on_drop = function(self, who)
        if who == game.player then                                                                                 
            game.logPlayer(who, "Dropping %s would break the game, you wisely decide against it.", self:getName())
            return true
        end 
    end,
}
As I said this works when I append it to the initial inventory by adding “{type="misc", subtype="scroll", defined="LETTER"}” to birth/descriptors.lua. (The latter is the case with another quest-letter I use.)

Glad to know the missing who was just a bug!

EDIT: It turns out that I can get normal items from the tome module (e.g. “STAFF_ABSORPTION”) that way -- perhaps I have to declare the “misc” object type somewhere first? I appended the line “ load("/data/general/objects/misc-quest.lua")” and thought this sufficed.

Re: adding objects on quest grant

Posted: Sun May 30, 2010 3:56 pm
by darkgod
Using makeEntityByName should work, what does your log says ?

Re: adding objects on quest grant

Posted: Sun May 30, 2010 4:04 pm
by Old Tomnoddy
It works indeed! (But why not the generic makeEntity?) Thanks.

Re: adding objects on quest grant

Posted: Sun May 30, 2010 4:59 pm
by darkgod
Because makeEntity generates random entities and checks them through the filter.
Your object (as it should) does not have a level_range or rarity, making it unable to be randomly generated.

Re: adding objects on quest grant

Posted: Sun May 30, 2010 7:39 pm
by Old Tomnoddy
Ahh, thanks for the insight. I had a similar guess from a look at the source but came to the wrong conclusion.