Page 1 of 2

Help needed for little script.

Posted: Fri Oct 11, 2013 9:53 pm
by YannBastian
Hi all. I'm a grimrock newbie. I'm french and my english sucks a little. forgive if i said something weird...
So i started grimrock a couple of week ago, and i try the editor. I love it. But i don't really understand lua scripting. Thanks to komag and spider fighter's tutorials i understand some things, but scripting is just a pain in the ass for me. I worked two hours to make a simple hudprint on a door opening ( shame on me).
I've tried to make a script on a monster death, i found some post on ondie function, but i don't understant how it works. I want to do things like door opens, hudprint or spawn something when a monster is dead. If someone can help me i give him my wife !!! if she's don't kill me. Thanks

Re: Help needed for little script.

Posted: Sat Oct 12, 2013 10:50 am
by Eleven Warrior
Hi

Here is a Monster I cloned to make Some Doors to open, plus some text he say's, XP for the party and heal the party

What you need:

1 - A counter on the Map Called (ucounter1) Set the Initial Value to 1
What happens is when the Monster dies it starts the (ucounter) When the ucounter1 reaches the Value 0 the Doors will open.
The counter is not connected to anything, It's just on the Editor Map say level 1 for Egxample..

2 - Create 3 Doors named: udoor1 , udoor2 , udoor3 and place them in the level where this Monster will be.
When the Monster dies these 3 Doors will open..

3 - I have also added some extra stuff in the Monster Object EG: Heal the Party, when the Monster dies he says some last words (hudPrint)
You can delete the hudPrint if you want to, it wont kill the Code here and Last of all I have added: for i = 1,4 do party:getChampion(i):gainExp(300)
The party gains 300 Experience Points..

4 - Paste this Code into your monster.lua File..

cloneObject{
name="Ulan",
baseObject = "ogre",
onDie = function(monster) -- The onDie Hook --
ucounter1:decrement() -- This the name of the Counter in the Dungeon Editor Map (Eg: Level 1). ---
if ucounter1:getValue() == 0 then --- When the Monster die the ucounter goes to 0 and doors will open ---
udoor1:open()
udoor2:open()
udoor3:open()
playSound("cult_aware")
party:shakeCamera(1.5,1.5) -- The Room Shake aliitle with this function ---
hudPrint("DRACO: NOOOOooo... THAT WAS A EPIC BATTLE...") -- What the Monster say on Death ---
hudPrint("")
hudPrint("YOU ARE WORTHY, THE Sage Orlandio will like you....")
party:heal() -- The party gets healed ---
for i = 1,4 do party:getChampion(i):gainExp(300) -- Xp the party gets when Monster dies. ----
end
return true
end
end
}

I Hope this helps you out.. Have fun ahy...

EDIT: I f you want ill make a Editor Dungeon with the new Monster in it so you can see how it works if you like..

Re: Help needed for little script.

Posted: Sat Oct 12, 2013 11:34 am
by YannBastian
Thanks and thanks. I'll try this early. Can i send my wife to you by fedex? I thought about téléportation... i'm not sure that is possible :p

Re: Help needed for little script.

Posted: Sat Oct 12, 2013 12:15 pm
by Pecen
Hi, if you don't did this yet, i recommend you to look at Komag's remake of LoG source, there is lot of notes how things work and it's great for learning ;)

Re: Help needed for little script.

Posted: Sat Oct 12, 2013 12:45 pm
by YannBastian
good idea pecen. i'll do that. thanks

Re: Help needed for little script.

Posted: Sun Oct 13, 2013 3:06 am
by Eleven Warrior
Hi how did it go?

Yeah like Pecen said Komag's work is Awesome. There is a lot of good resources in his Module..

LOL You can keep your wife LOL..

Re: Help needed for little script.

Posted: Sun Oct 13, 2013 1:37 pm
by YannBastian
It works. thanks elven.

Edit: i change the code, now i have just heal party and 1 door open. very nice.
Hum if i change udoors:open() by something like spawn("machintruc", x, y, z, X), is it good?
Last question: why "return true"?

Re: Help needed for little script.

Posted: Sun Oct 13, 2013 3:17 pm
by Eleven Warrior
Hi again..

What do you want the Monster to do?

1 - When the monster dies the object is spawned on the level somewhere or right where the monster dies.

If you want the object to spawn where the Monster dies its easier to add the Item to the monster in the Dungeon Editor..
or if you want the item to spawn somewhere in the level or another level i can help there..

Just need to know what it is you want ahy.. Ill do as soon as i get home from work for you NP..

Re: Help needed for little script.

Posted: Sun Oct 13, 2013 3:46 pm
by YannBastian
you don't speak french? grr not easy ^^
Hum i want to do: spawn a door and lock (connected) in another level, the monster droop the key
I found in this forum how make connector on spawning things ( i forget where :/), i just don't know how spawning it on a monster dying.

Re: Help needed for little script.

Posted: Sun Oct 13, 2013 9:33 pm
by Komag
the onDie hook will happen whenever that monster type dies, so if you only want it once then you set up a unique monster definition for it and only use it once.