Adding items to a spawned entity
Re: Adding items to a spawned entity
addItem almost always has to be followed by a spawn command
Finished Dungeons - complete mods to play
- SpiderFighter
- Posts: 789
- Joined: Thu Apr 12, 2012 4:15 pm
Re: Adding items to a spawned entity
I had no way of knowing that...in the official scripting reference it says "Monster:addItem(item)"Komag wrote:addItem almost always has to be followed by a spawn command
Re: Adding items to a spawned entity
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
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
Re: Adding items to a spawned entity
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.
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
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.
Code: Select all
function makeRock()
spawn("rock", party.level, party.x, party.y, 0, "myRock")
print(myRock)
print(myRock.id)
print(myRock.name)
end
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
Finished Dungeons - complete mods to play