Page 1 of 1
[Solved] Having trouble adding an item to a monster
Posted: Sun Nov 02, 2014 3:55 am
by MrChoke
I am thinking we can do this. So I have a monster spawned when the map loads. I want to give him a "gold_key" let's say. I try this:
Code: Select all
skeleton_trooper_1.monster:addItem("gold_key")
And I get "bad argument #1 ItemComponent expected, got ???".
So ok, yes I passed it a string. But how do I create an ItemComponent? All I know how to do right now is spawn an item onto the ground somewhere. I know about createComponent() but you call that on an existing GameObject. I must be missing something.....
UPDATE: The spawning of the item to the ground first seems to be easy enough. I was afraid that the item would stay on the ground after the addItem but it doesn't. Works for me unless someone does have another way.
Re: Having trouble adding an item to a monster via script
Posted: Sun Nov 02, 2014 4:54 am
by Doridion
Seen
MonsterComponent:addItem(item : ItemComponent) in the script reference. ItemComponent refers to the ID of an object.
If it's ok when you spawn the key on the ground first, symbollise that you create at least 1 entity of a gold_key ( so gold_key_1 ). Got same issue with my mod on LoG1, if i didn't have iteration of an item, i can't spawn it in a monster pocket.
Trying with :
Code: Select all
skeleton_trooper_1.monster:addItem("gold_key_1")
Re: Having trouble adding an item to a monster via script
Posted: Sun Nov 02, 2014 5:44 am
by cameronC
Or try this to have it spawn directly in the monster.
Code: Select all
skeleton_trooper_1.monster:addItem(spawn("gold_key").item)
[Solved] Having trouble adding an item to a monster via scri
Posted: Sun Nov 02, 2014 5:17 pm
by MrChoke
cameronC wrote:Or try this to have it spawn directly in the monster.
Code: Select all
skeleton_trooper_1.monster:addItem(spawn("gold_key").item)
Oh! I will try that. That would be much easier if it works. Though I thought spawn() as a global function needs all those parameters? I'll try it out.
UPDATE: Perfect. It works. spawn() must use the object being referenced for where to go.
Re: [Solved] Having trouble adding an item to a monster
Posted: Sun Nov 02, 2014 6:12 pm
by NutJob
Because this thread is similar I have a question about insertItem.
When I use spawn directly into a players slot (that is empty) it always produces a ghost copy (for lack of a better term) in front of the party.
Code: Select all
champObj:insertItem(1,spawn("dagger").item)
That will put the dagger in the champions hand (desired), but will also put a dagger in front of the party (undesired).
So, I resorted to:
Code: Select all
-- this is just a 1x1 room to spawn items into that the player has no access to entering
oPrimary = spawn(weapOfChoice,1,31,0,0,0)
-- then I take the object and place it in the champion slot
champObj:insertItem(1,oPrimary.item)
That has the desired effect of the player not running into the object but it is still there [on the ground in that 1x1 inaccessible room].
Once the player interacts with the object 'in the inventory' (picks it up, right clicks it, etc) the object on the ground always disappears (why I called it a ghost copy earlier.)
Re: [Solved] Having trouble adding an item to a monster
Posted: Sun Nov 02, 2014 7:08 pm
by MrChoke
Nutjob,
Try spawning it with the single parameter in the addItem() call. It seems to be different somehow than the global spawn() where you place it on the ground. It might work, who knows.
Re: [Solved] Having trouble adding an item to a monster
Posted: Sun Nov 02, 2014 7:17 pm
by NutJob
addItem is only part of the Monster, Socket, Surface, and Container components. insertItem is part of the Champion, so I can't use addItem on a Champion.