adding objects on quest grant

If you have a module that you'd like comments on or would like to know how to create your very own module, post here

Moderator: Moderator

Post Reply
Message
Author
Old Tomnoddy
Wayist
Posts: 19
Joined: Tue May 25, 2010 11:49 pm

adding objects on quest grant

#1 Post 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!

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: adding objects on quest grant

#2 Post 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)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Old Tomnoddy
Wayist
Posts: 19
Joined: Tue May 25, 2010 11:49 pm

Re: adding objects on quest grant

#3 Post 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.

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: adding objects on quest grant

#4 Post by darkgod »

Using makeEntityByName should work, what does your log says ?
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Old Tomnoddy
Wayist
Posts: 19
Joined: Tue May 25, 2010 11:49 pm

Re: adding objects on quest grant

#5 Post by Old Tomnoddy »

It works indeed! (But why not the generic makeEntity?) Thanks.

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: adding objects on quest grant

#6 Post 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.
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Old Tomnoddy
Wayist
Posts: 19
Joined: Tue May 25, 2010 11:49 pm

Re: adding objects on quest grant

#7 Post 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.

Post Reply