Adding items to a spawned entity

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
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 »

addItem almost always has to be followed by a spawn command :)
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:addItem almost always has to be followed by a spawn command :)
I had no way of knowing that...in the official scripting reference it says "Monster:addItem(item)" :)
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 »

I know, it would best if it were noted there, many of us ran into the same problem.

The thing is, it needs an actual item, not just an item name, which is what you put. Any item in the game that has been created has it's own "itemness" (a code or hex or number or something, I'm not sure, call it "ether") and two useful identifiers, a name, and an id. The name is the type of item it is. The id is the useful identifier for that particular item, but is not the same as the item's "ethereal" self.

Anyway, that script needs an actual item, not a name or even an id, and the only way to really access an item is to create one on the spot
Finished Dungeons - complete mods to play
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 »

Try these functions to see more about how items really work. Just stick them in a script entity and link a couple buttons or pressure plates to them.

Code: Select all

function makeRock()
  spawn("rock", party.level, party.x, party.y, 0, "myRock")
  print(myRock)
  print(myRock.id)
  print(myRock.name)
end
this one can only be done once, because if you try to do it again you'll get a crash due to the fact that you already made a rock with the id myRock and there can be only one. But it does illustrate the three different identifiers of what a rock is in the game's mind

Code: Select all

function whatRock()
  local thisRock = spawn("rock", party.level, party.x, party.y, 0)
  print(thisRock)
  print(thisRock.id)
  print(thisRock.name)
end
This one can be done infinite times, and you'll notice that the game keeps assigning a higher and higher id number for each new rock you create.
Finished Dungeons - complete mods to play
Post Reply