Page 1 of 2
Adding items to a spawned entity
Posted: Sun Nov 04, 2012 3:29 pm
by SpiderFighter
Ok, so I've been around the forum and Google, and played around a bit in the editor, but I can't for the life of me figure out how to add an item to a spawned entity. That is (for example), spawn a monster, and give that monster an item that drops upon its death. I've tried renaming the spawner, but that doesn't seem to work (or I'm doing it wrong...which is likely, since I've really only begun dipping my toe into the lua waters recently).
Is this even possible?
Re: [LUA QUESTION] Adding items to a spawned entity?
Posted: Sun Nov 04, 2012 3:36 pm
by Neikun
Here's a work around.
Define a new monster that specifically drops an item, and have the spawner spawn that one.
Re: [LUA QUESTION] Adding items to a spawned entity?
Posted: Sun Nov 04, 2012 3:36 pm
by Skuggasveinn
I just do this
Code: Select all
cloneObject {
name = "ogre_w_skulls",
baseObject = "ogre",
onDie = function(self)
spawn("saphire_skull", 4, self.x, self.y, 4, "saphire_skull_1")
spawn("ruby_skull", 4, self.x, self.y, 4, "ruby_skull_1")
end
}
then when ogre_w_skulls dies, he will drop these quests skulls.
Re: [LUA QUESTION] Adding items to a spawned entity?
Posted: Sun Nov 04, 2012 3:37 pm
by Batty
Can't you just use:
Monster:addItem(item)
Adds an item to be carried by the monster. When the monster dies all items carried are dropped to ground.
so:
Re: [LUA QUESTION] Adding items to a spawned entity?
Posted: Sun Nov 04, 2012 3:39 pm
by SpiderFighter
Skuggasveinn wrote:I just do this
Code: Select all
cloneObject {
name = "ogre_w_skulls",
baseObject = "ogre",
onDie = function(self)
spawn("saphire_skull", 4, self.x, self.y, 4, "saphire_skull_1")
spawn("ruby_skull", 4, self.x, self.y, 4, "ruby_skull_1")
end
}
then when ogre_w_skulls dies, he will drop these quests skulls.
Brilliant. Thanks so much to all of you.
Batty, that would work if I wasn't using a spawner.
Re: Adding items to a spawned entity
Posted: Sun Nov 04, 2012 4:47 pm
by Periodiko
Wouldn't this work:
Activate a script along with your spawner. In the script, do an entitiesAt() at the location of your spawner. Isolate the newly spawned monster, and then addItem(item) the item(s).
Re: Adding items to a spawned entity
Posted: Sun Nov 04, 2012 10:46 pm
by Komag
just use a script and not a spawner. a spawner is nothing more than a GUI for the script anyway, so might as well use a script directly and have the control and options you want without having to set up custom monsters and stuff like that.
Re: Adding items to a spawned entity
Posted: Thu Nov 08, 2012 5:59 pm
by SpiderFighter
Komag wrote:just use a script and not a spawner. a spawner is nothing more than a GUI for the script anyway, so might as well use a script directly and have the control and options you want without having to set up custom monsters and stuff like that.
It does make more sense to me to do that...I tried the cloning way and still can't get it work, but I can't see the issue and, honestly, I'd like to get more into coding so I can learn.
Here's what I'm doing: just a simple script to replace a statue with a living monster who will drop a key when killed:
function ogreReplacers()
slenderjr:destroy()
spawn("stone_ogre", 8, 25, 18, 0):addItem("iron_key")
end
According to the Scripting Reference (and everything else I've read), this should work, but it doesn't. I've taken out quotes, I've tried a non-custom monster, I've tried other items instead of the key...nothing I do works, and I keep getting the same error:
"bad argument #1 to 'addItem' (item expected, got ???)
I know I'm doing something completely, newbishly, stupid and I've been avoiding posting this for two days from shame and embarrassment, but I'm at a point where I need this to work, or I can't progress much further. Can somebody please help?
Re: Adding items to a spawned entity
Posted: Thu Nov 08, 2012 6:03 pm
by petri
addItem() expects an object of type item ("iron_key" is a string, not an item).
This should work:
spawn("stone_ogre", 8, 25, 18, 0):addItem(spawn("iron_key"))
Re: Adding items to a spawned entity
Posted: Thu Nov 08, 2012 6:05 pm
by SpiderFighter
petri wrote:addItem() expects an object of type item ("iron_key" is a string, not an item).
This should work:
spawn("stone_ogre", 8, 25, 18, 0):addItem(spawn("iron_key"))
Ohhhhhh, now I understand. Thanks, Petri!!