Adding items to a spawned entity
- SpiderFighter
- Posts: 789
- Joined: Thu Apr 12, 2012 4:15 pm
Adding items to a spawned entity
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?
Is this even possible?
Last edited by SpiderFighter on Sun Nov 04, 2012 3:39 pm, edited 2 times in total.
Re: [LUA QUESTION] Adding items to a spawned entity?
Here's a work around.
Define a new monster that specifically drops an item, and have the spawner spawn that one.
Define a new monster that specifically drops an item, and have the spawner spawn that one.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
- Message me to join in!
- Skuggasveinn
- Posts: 562
- Joined: Wed Sep 26, 2012 5:28 pm
Re: [LUA QUESTION] Adding items to a spawned entity?
I just do this
then when ogre_w_skulls dies, he will drop these quests skulls.
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
}
Re: [LUA QUESTION] Adding items to a spawned entity?
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:
Monster:addItem(item)
Adds an item to be carried by the monster. When the monster dies all items carried are dropped to ground.
so:
Code: Select all
spawn("ogre"):addItem("skull")
- SpiderFighter
- Posts: 789
- Joined: Thu Apr 12, 2012 4:15 pm
Re: [LUA QUESTION] Adding items to a spawned entity?
Brilliant. Thanks so much to all of you.Skuggasveinn wrote:I just do this
then when ogre_w_skulls dies, he will drop these quests skulls.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 }
Batty, that would work if I wasn't using a spawner.
Re: Adding items to a spawned entity
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).
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
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.
Finished Dungeons - complete mods to play
- SpiderFighter
- Posts: 789
- Joined: Thu Apr 12, 2012 4:15 pm
Re: Adding items to a spawned entity
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.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.
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:
SpoilerShow
function ogreReplacers()
slenderjr:destroy()
spawn("stone_ogre", 8, 25, 18, 0):addItem("iron_key")
end
slenderjr:destroy()
spawn("stone_ogre", 8, 25, 18, 0):addItem("iron_key")
end
"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
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"))
This should work:
spawn("stone_ogre", 8, 25, 18, 0):addItem(spawn("iron_key"))
- SpiderFighter
- Posts: 789
- Joined: Thu Apr 12, 2012 4:15 pm
Re: Adding items to a spawned entity
Ohhhhhh, now I understand. Thanks, Petri!!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"))