Adding items to a spawned entity

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Adding items to a spawned entity

Post 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?
Last edited by SpiderFighter on Sun Nov 04, 2012 3:39 pm, edited 2 times in total.
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: [LUA QUESTION] Adding items to a spawned entity?

Post by Neikun »

Here's a work around.
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
  • Message me to join in!
User avatar
Skuggasveinn
Posts: 562
Joined: Wed Sep 26, 2012 5:28 pm

Re: [LUA QUESTION] Adding items to a spawned entity?

Post 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.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: [LUA QUESTION] Adding items to a spawned entity?

Post 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:

Code: Select all

spawn("ogre"):addItem("skull")
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: [LUA QUESTION] Adding items to a spawned entity?

Post 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.
Periodiko
Posts: 19
Joined: Fri Oct 19, 2012 2:45 am

Re: Adding items to a spawned entity

Post 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).
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Adding items to a spawned entity

Post 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.
Finished Dungeons - complete mods to play
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: Adding items to a spawned entity

Post 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:
SpoilerShow
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?
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Adding items to a spawned entity

Post 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"))
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: Adding items to a spawned entity

Post 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!!
Post Reply