Page 2 of 2

Re: How to script a starting item for the party

Posted: Wed Sep 26, 2012 11:01 pm
by Komag
ah, I see, didn't know about that crash! But I solved it, just destroy the original item (which is still on the ground) right after giving it to the champion. here is the fixed version:

Code: Select all

party:getChampion(1):insertItem(11,mywelcomescroll)
mywelcomescroll:destroy()
party:getChampion(1):insertItem(7,dagger_1)
dagger_1:destroy()
party:getChampion(2):insertItem(4,leather_boots_1)
leather_boots_1:destroy()
party:getChampion(3):insertItem(5,tattered_cloak_1)
tattered_cloak_1:destroy()
party:getChampion(4):insertItem(5,tattered_cloak_2)
tattered_cloak_2:destroy()
party:getChampion(4):insertItem(8,whitewood_wand_1)
whitewood_wand_1:destroy()
Now you can lay items down, throw, etc, no problem!

Re: How to script a starting item for the party

Posted: Wed Sep 26, 2012 11:24 pm
by Hermundure
Nice!

I hate this scripting already, its addictive, you can do so many things with it... :-)

I only wanted to know how to add items to the starting party, now I stumbled across a script which lets random people of your party talk to each other which might add a good bit of atmosphere to the game if implemented right so I think I will bother you guys with silly questions again in the next weeks ;-)

Thank you for the help so far :-)

Re: How to script a starting item for the party

Posted: Thu Sep 27, 2012 4:21 am
by Komag
yeah, once you start to get your head around stuff and you see the possibilities, the creativity and really flow!

Re: How to script a starting item for the party

Posted: Thu Sep 27, 2012 7:40 am
by petri
Komag wrote:ah, I see, didn't know about that crash! But I solved it, just destroy the original item (which is still on the ground) right after giving it to the champion. here is the fixed version:

Code: Select all

party:getChampion(1):insertItem(11,mywelcomescroll)
mywelcomescroll:destroy()
party:getChampion(1):insertItem(7,dagger_1)
dagger_1:destroy()
party:getChampion(2):insertItem(4,leather_boots_1)
leather_boots_1:destroy()
party:getChampion(3):insertItem(5,tattered_cloak_1)
tattered_cloak_1:destroy()
party:getChampion(4):insertItem(5,tattered_cloak_2)
tattered_cloak_2:destroy()
party:getChampion(4):insertItem(8,whitewood_wand_1)
whitewood_wand_1:destroy()
Now you can lay items down, throw, etc, no problem!
Don't do this. You should never use an entity after it has been destroyed. The correct way is to spawn each item "up in air" i.e. without coordinates and insert into inventory slot.

Re: How to script a starting item for the party

Posted: Thu Sep 27, 2012 11:57 am
by Komag
If I have these items on the floor in a room and I start in that room so I can see them, and I set a timer for a couple seconds, I expected the items to disappear off the floor when they were inserted into the party's hands/packs. But they don't disappear, only a "copy" is placed in the party's hands/packs, which is why I then set the floor versions to be destroyed.

So anyway, I guess the spawning and such is the only good way to do this then. Okay :)

Re: How to script a starting item for the party

Posted: Thu Sep 27, 2012 12:22 pm
by petri
Yeah, unfortunately at the moment there is no clean/correct way to pick up an item from a level and put it to character's inventory. Destroy really means destroy, so the item can't be used after that. The next build will throw an error if you try to use a destroyed entity.

Also, it's illegal to insert the same item into multiple inventory slots. This will cause all sorts of strange issues.

Re: How to script a starting item for the party

Posted: Thu Sep 27, 2012 12:32 pm
by Komag
So my version with these items will now be:

Code: Select all

local startScroll = spawn("scroll")
startScroll:setScrollText("This is your wake-up call\nTime to go to work!")
party:getChampion(1):insertItem(11,startScroll)
local startDagger = spawn("dagger")
party:getChampion(1):insertItem(7,startDagger)
local startBoots = spawn("leather_boots")
party:getChampion(2):insertItem(4,startBoots)
local startCloak1 = spawn("tattered_cloak")
party:getChampion(3):insertItem(5,startCloak1)
local startCloak2 = spawn("tattered_cloak")
party:getChampion(4):insertItem(5,startCloak2)
local startWand = spawn("whitewood_wand")
party:getChampion(4):insertItem(8,startWand)
:)

Re: How to script a starting item for the party

Posted: Fri Oct 19, 2012 7:11 pm
by TheLastOrder
Komag wrote:ah, I see, didn't know about that crash! But I solved it, just destroy the original item (which is still on the ground) right after giving it to the champion. here is the fixed version:

Code: Select all

party:getChampion(1):insertItem(11,mywelcomescroll)
mywelcomescroll:destroy()
party:getChampion(1):insertItem(7,dagger_1)
dagger_1:destroy()
party:getChampion(2):insertItem(4,leather_boots_1)
leather_boots_1:destroy()
party:getChampion(3):insertItem(5,tattered_cloak_1)
tattered_cloak_1:destroy()
party:getChampion(4):insertItem(5,tattered_cloak_2)
tattered_cloak_2:destroy()
party:getChampion(4):insertItem(8,whitewood_wand_1)
whitewood_wand_1:destroy()
Now you can lay items down, throw, etc, no problem!
I didn't knew that possibility :)

I done that, to solve the same problem about the already exist objects:

Code: Select all

local startClothes = spawn("loincloth")
party:getChampion(1):insertItem(3,startClothes)
Isn't easier???
Thanks!

Re: How to script a starting item for the party

Posted: Mon Oct 22, 2012 5:31 pm
by Grimwold
just want to add this here: if you need to spawn an item and give it a specific ID, you can use:

Code: Select all

spawn(spawn_name,nil,nil,nil,nil,spawn_id)
Here we use nil for each of the co-ordinates, so it first spawns the item "up in the air" and there is no issue with a duplicate

e.g.

Code: Select all

party:getChampion(1):insertItem(11,spawn("blueberry_pie",nil,nil,nil,nil,"poisoned_pie"))
Then you can check and see if the champion eats the specific pie called "poisoned_pie", and do something nasty if he does. or any number of other things.

Re: How to script a starting item for the party

Posted: Mon Oct 22, 2012 6:16 pm
by Komag
thanks, that info is good to have here :)