How to script a starting item for the party

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: How to script a starting item for the party

Post 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!
Finished Dungeons - complete mods to play
Hermundure
Posts: 46
Joined: Wed Sep 26, 2012 5:44 pm

Re: How to script a starting item for the party

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

Re: How to script a starting item for the party

Post by Komag »

yeah, once you start to get your head around stuff and you see the possibilities, the creativity and really flow!
Finished Dungeons - complete mods to play
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: How to script a starting item for the party

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

Re: How to script a starting item for the party

Post 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 :)
Finished Dungeons - complete mods to play
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: How to script a starting item for the party

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

Re: How to script a starting item for the party

Post 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)
:)
Finished Dungeons - complete mods to play
User avatar
TheLastOrder
Posts: 104
Joined: Wed Oct 17, 2012 1:56 am

Re: How to script a starting item for the party

Post 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!
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: How to script a starting item for the party

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

Re: How to script a starting item for the party

Post by Komag »

thanks, that info is good to have here :)
Finished Dungeons - complete mods to play
Post Reply