How to script a starting item for the party

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Hermundure
Posts: 46
Joined: Wed Sep 26, 2012 5:44 pm

How to script a starting item for the party

Post by Hermundure »

Hi all,

I am very unexperienced with scripting and managed to do some easy things with the help of some "guide" postings already but I struggle with the following task:

I want to add an iron key and a scroll with text on my starting party and remove the torch which the normal party usually starts with.

If any experienced scripter out there could lend me a hand I would be very glad.

Herm

EDIT:

I got it to work!

I tested around a bit and here is what worked for me, any new scripters might find this useful too:

local startMessage = spawn("scroll")
startMessage:setScrollText("This is an important\nmessage!")
party:getChampion(1):insertItem(11,startMessage)

local startKey = spawn("iron_key")
party:getChampion(1):insertItem(12,startKey)

startMessage and startKey are words you can change to whatever you like as long as you call the items the same way in every line.
the numbers after insertItem (namingly 11 and 12) point to the first and second place in the backpack of champion number 1 (the top left one).
The \n is a break in the text of the scroll.
Last edited by Hermundure on Wed Sep 26, 2012 9:03 pm, edited 2 times in total.
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 »

the torch is only there when testing in the editor, so you don't need to worry about that
Finished Dungeons - complete mods to play
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 »

Welcome to the forums..

Firstly, the torch you get in the editor is not present when the dungeon is exported and loaded in the main game.

Secondly, you could take a look at the SDP (set default party) postings.. specifically the inventory part.

viewtopic.php?f=14&t=3201
Hermundure
Posts: 46
Joined: Wed Sep 26, 2012 5:44 pm

Re: How to script a starting item for the party

Post by Hermundure »

I already found the SDP but to be honest it was to much for me because I have no idea how to add the text to the scroll and I am not sure if this lets me mod the inventory of player created parties (and how) so I thought a few short lines of script to add the key and scroll with text to the backpack of character 1 would be much easier.
Does anyone know how to do this?
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 »

maybe this post will yield some clues...
viewtopic.php?p=33070#p33070
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 »

Hehe, yesterday I have found this posting too but I didnt even manage to get it done what it is supposed to do, let alone modifying it, there are just to many placeholders in the text which I need to fill with something that makes sense which would be a piece of cake for one who knows what he does but I try this scripting since yesterday.

For instance I have no idea why (from the script of the page you mentioned)
party:getChampion(champ):insertItem(slot,x) - I suppose champ is the champion number (1 for my case), slot is the slot number (I have chosen 7) and x is the name of the item (in my case "iron_key") works for the script but only creates an error if I use this line without the rest.

also I dont know why this script works which spawns a scroll with text in an alcove:

local message = spawn("scroll")
message:setScrollText("This is an important\nmessage!")

scrollAlcove:addItem(message)



but if I use

local message = spawn("scroll")
message:setScrollText("This is an important\nmessage!")

party:getChampion(1):addItem(7,"scroll")

it dont work anymore...
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: How to script a starting item for the party

Post by Montis »

because you need to use it like this

Code: Select all

local message = spawn("scroll")
message:setScrollText("This is an important\nmessage!")

party:getChampion(1):addItem(7,message)
notice that I replaced "scroll" with message - including the quotation marks with make a difference between a variable and a string.
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
Hermundure
Posts: 46
Joined: Wed Sep 26, 2012 5:44 pm

Re: How to script a starting item for the party

Post by Hermundure »

Sadly this doesnt work too,

if you use the script you provided it shows the following error:

attempt to call method "addItem" (a nil value) x (whatever that means...)

EDIT:

I got it to work!

I tested around a bit and here is what worked for me, any new scripters might find this useful too:

local startMessage = spawn("scroll")
startMessage:setScrollText("This is an important\nmessage!")
party:getChampion(1):insertItem(11,startMessage)

local startKey = spawn("iron_key")
party:getChampion(1):insertItem(12,startKey)

startMessage and startKey are words you can change to whatever you like as long as you call the items the same way in every line.
the numbers after insertItem (namingly 11 and 12) point to the first and second place in the backpack of champion number 1 (the top left one).
The \n is a break in the text of the scroll.
Last edited by Hermundure on Wed Sep 26, 2012 9:04 pm, edited 1 time in total.
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 »

You can also just create the items in the editor on the dungeon level somewhere (they don't even have to be in a room, just anywhere in the solid wall, or in a room, doesn't matter) and then insert them onto the champion

Create whatever items you want, even a whole arsenal, lots of scrolls with custom text, food supplies, ammo, treasures they must place on altars, whatever. Give them custom IDs if you want to, or just make note of their default IDs

Then make a script, such as:

Code: Select all

party:getChampion(1):insertItem(11,mywelcomescroll)
party:getChampion(1):insertItem(7,dagger_1)
party:getChampion(2):insertItem(4,leather_boots_1)
party:getChampion(3):insertItem(5,tattered_cloak_1)
party:getChampion(4):insertItem(5,tattered_cloak_2)
party:getChampion(4):insertItem(8,whitewood_wand_1)
and so on and etc. This way don't have to bother with the code for local this and that and the spawning. The item slots are:
1 - head
2 - chest
3 - legs
4 - feet
5 - shoulders
6 - neck
7 - left grip
8 - right grip
9 - hands
10 - wrist
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 »

I tried this too but if I create the item on the floor, add it to a character with the command and start the test it works, he wields the axe I gave to him for example.
But if I take this axe and throw it or put it on the floor you will get a crash with an error who says something like "This item is already spawned".
With the local command this crash doesnt happen.

(I wonder where this item is created if I use the local command and why I can create just one item with it and insert it on four different characters like I did here:)

local startFood = spawn("pitroot_bread")
party:getChampion(1):insertItem(11,startFood)
party:getChampion(2):insertItem(11,startFood)
party:getChampion(3):insertItem(11,startFood)
party:getChampion(4):insertItem(11,startFood)

Scripting is a strange beast for sure (for persons like me) ^^
Post Reply