~Advanced Scripting and Editor Help

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

~Advanced Scripting and Editor Help

Post by SnowyOwl47 »

Advanced Scripting

How to make your own methods/scripts


First of when making your own methods you name a script_entity to whatever you want but in my case ill name it game,

So lets get started first off making a function.

Code: Select all

-- This is a simple function it does nothing.
function kill()
end
Now were not done here, thats just a function and plus it has nothing to get the entity from.

Lets add something to get the entity so we can define which entity we want to kill!

Code: Select all

function kill(entity)
end
We simply add entity in the () thats the parameters.

Lets add the killing part! :D

Code: Select all

function kill(entity)
--   use return to return whatever your wanting to return!
     return entity :destroy()
end
Now sense this is simple all were doing is destroying it no killing it but it will be killed but with no animation or anything.

Now to use this sense our scrip_enttiy is named game we simpply say:

Code: Select all

game.script.kill(my_monster)
With that said now to make sure your not confused when you make your own methods/scripts never use : in it it will always be this.that.someFunction(some par)
[/color]

Entities to know!

With Entities to get values and things are basically the same as the normal scripting but this time you need to do some special things.
To change anything in monsters you must say your_monster_name.monster.getHealth() or something else, for party its party.party and torches torch_name.controller basically if you place an object or something down click on it and at the bottom right of the entire editor you'll see something like a list with all these set able things so for monsters place one down and click on it. You'll see all these things but then theres a little tab called monster and it has all the stable values that is what you want to say when you want to do something to that entity so you_monster.monster.Value()


An example of some possibilities in what commands you can use.
Image

Real Lua Scripts:

All Item Icons in numbers:
Leki wrote:Table of LoG 2 Editor Icons:

Image

It's based on John's LoG1 table for visualisation (thanks for that). Enjoy and report bugs :twisted:

New Defining an object:

Code: Select all

defineObject{
   name = "animated_thingy",
   components = {
      {
         class = "Model",
         model = "assets/models/env/thingy.fbx",
      },
      {
         class = "Animation",
         animations = {
            doTheTwist = "assets/animations/env/thingy_twist.fbx",
         },
         onAnimationEvent = function(self, event)
            if event == "bang" then
               self.go:playSound("boom")
               self.go.obstacle:disable()
            end
         end,
      },
      {
         class = "Sound",
         sound = "hum_looping"
      },
      {
         class = "Obstacle",
         hitSound = "barrel_hit",
         hitEffect = "hit_wood",
      },
      {
         class = "Health",
         health = 15,
         immunities = { "poison" },
         spawnOnDeath = "broken_thingy",
      },
      {
         class = "Controller",
         onActivate = function(self)
            self.go.animation:play("doTheTwist")
            self:disable()
         end,
      },
   },
   placement = "floor",
   editorIcon = 120,
}
Cloning an Object:
JohnWordsworth wrote:Having said that, the following will clone the "Tome of Wisdom" with a new title and description!

Code: Select all

defineObject{
	name = "jw_tome_of_wisdom",
	baseObject = "tome_wisdom",
	components = {
		{
			class = "Item",
			uiName = "Boo Yah!",
			gfxIndex = 30,
			description = "A mysterious tome that will give you a skill point!",
		}
	},
}

Defining music

Go to mod_assets/Scripts/music.lua

Defining music:

Code: Select all

defineAmbientTrack{
   name = "spooky",
   filename = "mod_assets/sounds/spooky.ogg",
   volume = 0.18,
}
More to come!

All Know Entities scripts:

Floor_trigger

Code: Select all

floor_trigger_1.floortrigger:setTriggeredByParty(true)
floor_trigger_1.floortrigger:setTriggeredByMonster(false)
floor_trigger_1.floortrigger:setTriggeredByItem(false)
floor_trigger_1.floortrigger:setTriggeredByDigging(false)
--Disables self:
floor_trigger_1.floortrigger:setDisableSelf(true)
--Adds Connector:
floor_trigger_1.floortrigger:addConnector("onActivate", "script_entity_1", "setupgame")
InvisibleTeleporter

Code: Select all

--Area it tps you
invisible_teleporter_1.teleporter:setTeleportTarget(1,11,15,0)
--Spin the player to a certain point(North, South, East,West,etc)
invisible_teleporter_1.teleporter:setSpin("south")
invisible_teleporter_1.teleporter:setTriggeredByParty(true)
invisible_teleporter_1.teleporter:setTriggeredByMonster(false)
invisible_teleporter_1.teleporter:setTriggeredByItem(false)
invisible_teleporter_1.teleporter:setTriggeredBySpell(false)
invisible_teleporter_1.controller:setInitialState("deactivate")
Timer

Code: Select all

timer_1.timer:setTimerInterval(15)
timer_1.timer:setDisableSelf(true)
timer_1.timer:setTriggerOnStart(true)
timer_1.timer:setCurrentLevelOnly(true)
timer_1.timer:addConnector("onActivate", "invisible_teleporter_1", "activate")
timer_1.timer:addConnector("onActivate", "invisible_teleporter_3", "activate")
timer_1.timer:addConnector("onActivate", "invisible_teleporter_2", "activate")
--Starts Timer
timer_1.timer:start()
--Stops Timer
timer_1.timer:stop()

Undefined Scripting:

Spawns and entity with the name at the location of type:

Code: Select all

spawn("entity name",level,x,y,facing,height,"your_cusotm_name")
Adding Items to acloves or anhything you can add items to.

Code: Select all

entity_name.surface:addItem(item_name.item)
Example:

Code: Select all

dungeon_alcove_1.surface:addItem(water_flask_1.item)
Playing a sound:

Code: Select all

playSound("Your_Sound.extension")

Player Scripts:

Prints text to the players hud:

Code: Select all

hudPrint("Your Text") 
Returns the party champion:

Code: Select all

party.party:getChampion(champion in numbers)
Party Gain Exp:

Code: Select all

party.party:getChampion(champion in numbers):gainExp(amount in numbers)
Party Disable/Enable:

Code: Select all

party.party:getChampion(champion):setEnabled(boolean)
Party get Disable/Enable:

Code: Select all

party.party:getChampion(champion):getEnabled()

More to be found out

Variables:(Basic Lua)

Creates a local variable to be used

Code: Select all

myvar = false or 0 or "String/Text"
(Example

Code: Select all

mylar = false
function something()
     if myvar == true then
     myvar = false
     else
     myvar = true
     end
end
Setting variables in entites

Click Url to see more on how to sett variables in entities, this link goes to top of page!
viewtopic.php?f=22&t=7306

Code: Select all

entite_name.controller:setValue(Value)
Example:

Code: Select all

torch_holder_1.controller:setHasTorch(true)
More to be found out

BOSSES

So I've got it all worked out now!!! :geek: :geek: :geek: :geek:

1) Creating the boss battle:

All you need to do place an boss_fight entity down, name it whatever for example ill name it boss.

2) Adding a monster to the boss:

Simply make a script and have something trigger a function in it and the function could be this:

Code: Select all

function bossstart()
     boss.bossfight:addMonster(monster.monster)
end
So if I spawned a monster with lua and then named the monster boss
just replace monster.monster with boss.monster

3) Setting name in lua:

Code: Select all

boss_fight_entity.bossfight:setName("Boss Name")
4) Setting autoDeactivate in lua:

Code: Select all

boss_fight_entity.bossfight:setAutoDeactivate(BOOL)
5) Setting Music in lua:

Code: Select all

boss_fight_entity.bossfight:setMusic("Music")
6) Activating a Boss fight in lua:

Code: Select all

boss_fight_entity.bossfight:activate()
7 Deactivating a Boss fight in lua:

Code: Select all

boss_fight_entity.bossfight:deactivate()
Advanced Editor Help

Hidden Pressure Plate

floor_trigger

How to make forests, and beaches

Forests

Image

To make a forest shift + left click or right click with forest floor 1 to place down that tile all over the dungeon easily,
Then find the entity forest_day_sky and place it any were on the dungeon doesn't matter where, and find the forest_hightmap and place it
any were as well doesn't matter were again. and your done! To add forest walls just place down the forest_wall tile!


Beaches

To make a beach shift + left click or right click with the beach floor to place down that tile all over the dungeon easily,
Then find the entity forest_day_sky and place it any were on the dungeon doesn't matter where, and find the forest_hightmap and place it
any were as well doesn't matter were again. Then find the beach_ocean entity and place it down somewhere in the map and your pretty much done! (Warning the beach_ocean goes really far but will not cover the whole map unless you make it be at the complete left of the dungeon and make it face west!)

Beach_Oceans only go were ever there facing so if its facing south it will only be south. Another thing about oceans is they take up the entire map of south/north/east/west from the entity start point.
Example:

Lets say you made a beach_ocean at the middle of the map and it was facing south then the ocean would cover half the map on the south side.

Water

To make simple water just add water, well its not that simple what you really do is place your water tiles were you want them to be, then browse your assets for swamp_water or water_surface or water_surface_unerground and in saying that your pretty much done.

Terrain Height

To change the terrain height all you do is go to the little tab called Layerwhen your editing tiles,and change it to height map and that will only be there if you've added the forest
height map, then change the height to whatever and click on a tile then reload/start your dungeon and you'll see that tile is higher or lower.


Image

Handling Tiles

Handling tiles can be a little confusing at times or the first time you open the editor, To use tiles correct they're actually pretty simple, simple select a tile out of your many tiles and if your using forest or beach or anything special look back up at how to make beaches and forests they'll help you a lot, but basically you select your tile and and you see you have the little choosing thing don't touch that it might be a little confusing but I don't think you'd really want to touch it anyway :D, what the LMB and RMB mean are Left Mouse Button and Right Mouse Button so if you left click on a tile in the tile browser you set the Left Mouse Button to that tile if you right click on a tile in the browser you set the Right Mouse Button to that tile.

Now the Floor and Ceil Floor Will mean how high or low the floor is Ceil will mean how high or low the ceiling will be. And so you simply place your tiles after setting your tile settings at the top and your done!

Portraits:

Legendary:
Ok I found out how to make it work, the file names needs to have the correct naming convention, [race]_[gender]_[01.. etc].tga

ex. human_female_01.tga

there is a subfolder in the LoG2 install directory with the portraits from LoG1, using their naming convention makes custom portraits show up in LoG2
Non-consumable key?
SpoilerShow
Skuggasveinn:
master_key (but spoiler tag since its a major item in the end game of LoG2)
But it is also is able to open up every lock there is, so ones the party has it, finding a key will never be an issue.

Its not until AH releases the scripting reference that we can see if we can clone the master_key and change it so that it only opens locks that it has been assigned to and still remain with the party.

More Info Coming soon when more is found out!

Want to see a little dungeon I'm working on that has lots of examples?

Download: https://dl.dropboxusercontent.com/u/278 ... 20hand.zip

This dungeon has some things that currently don't work such as bosses, and damaging entities!


Video Tutorials: (By Skuggasveinn)
Skuggasveinn wrote:I've created some tutorials for the new Dungeon Editor
Please note that I'm just learning this stuff myself, and I've not seen the lua code behind the assets so I reserve the right to be complete wrong about what I'm talking about :D


Part 1 - http://youtu.be/vMMBC9B2qjM GUI and new features
Part 2 - http://youtu.be/eDaeqUUOuSc Elevations inside dungeons
Part 3 - http://youtu.be/6cv3P8dxCgY Coordinates and level transition
Part 4 - http://youtu.be/hVpY60Ptjdk Creating Water and Reflections
Part 5 - http://youtu.be/bLwSL8mhJOk Outdoor scenario
Part 6 - http://youtu.be/dxonfsoRYOY Bossfight
Code from part 6
SpoilerShow

Code: Select all

function startBrothersBossFight()
	boss_fight_brothers.bossfight:addMonster(skeleton_commander_1.monster)
	boss_fight_brothers.bossfight:addMonster(skeleton_commander_2.monster)
	boss_fight_brothers.bossfight:activate()
end

function startMedusaBossFight()
	boss_fight_medusa.bossfight:addMonster(medusa_1.monster)
	boss_fight_medusa.bossfight:activate()

end
Playlist link https://www.youtube.com/playlist?list=P ... B7joLG52Nc

Hope that this will help someone get started.
Maybe I will add to these in the future.

Skuggasveinn.

Have anything I missed or don't know post it as a comment!
Last edited by SnowyOwl47 on Fri Oct 24, 2014 5:30 pm, edited 10 times in total.
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: ~Advanced Scripting and Editor Help

Post by Mysterious »

Hi thxs for the Script help I need it. I was wondering how to use this code you came up with. Could you make an example with a hudPrint and playSound in it please thxs :(

Code: Select all

mylar = false
function something()
     if myvar == true then
     myvar = false
     else
     myvar = true
     end
end
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: ~Advanced Scripting and Editor Help

Post by SnowyOwl47 »

@Mysterious

Code: Select all

myvar = false
function something()
     if myvar == true then
            playSound("Your_Sound")
            hudPrint("Sound Played")
            myvar = false
     else
            playSound("Your_Sound")
            hudPrint("Sound Played")
           myvar = true
     end
end
User avatar
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: ~Advanced Scripting and Editor Help

Post by 7Soul »

How do I make a pressure plate deactivate if I get off of it? What about timed pressure plates?
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: ~Advanced Scripting and Editor Help

Post by SnowyOwl47 »

7Soul wrote:How do I make a pressure plate deactivate if I get off of it? What about timed pressure plates?
Please explain what you need a little more, so I can help you.
User avatar
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: ~Advanced Scripting and Editor Help

Post by 7Soul »

SnowyOwl47 wrote:
7Soul wrote:How do I make a pressure plate deactivate if I get off of it? What about timed pressure plates?
Please explain what you need a little more, so I can help you.
I want a pressure plate that I can press, and when I walk out of it, it deactivates. When I add a pressure plate in the editor and I step on it, it stays pressed forever, but in the game there are ones that deactivate when you get out, or some that deactivate some time after you leave, and I would like to know how to make those
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: ~Advanced Scripting and Editor Help

Post by SnowyOwl47 »

7Soul wrote:
SnowyOwl47 wrote:
7Soul wrote:How do I make a pressure plate deactivate if I get off of it? What about timed pressure plates?
Please explain what you need a little more, so I can help you.
I want a pressure plate that I can press, and when I walk out of it, it deactivates. When I add a pressure plate in the editor and I step on it, it stays pressed forever, but in the game there are ones that deactivate when you get out, or some that deactivate some time after you leave, and I would like to know how to make those
That's easy if you have any items on the pressure plate it will stay activated intel the item is taken off, now another thing you could've had is the pressure plate could be set to disable self do not set to disable self, you can also set the pressure plate to not take items or monsters etc but just the party.
User avatar
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: ~Advanced Scripting and Editor Help

Post by 7Soul »

SnowyOwl47 wrote:
7Soul wrote:
SnowyOwl47 wrote:Please explain what you need a little more, so I can help you.
I want a pressure plate that I can press, and when I walk out of it, it deactivates. When I add a pressure plate in the editor and I step on it, it stays pressed forever, but in the game there are ones that deactivate when you get out, or some that deactivate some time after you leave, and I would like to know how to make those
That's easy if you have any items on the pressure plate it will stay activated intel the item is taken off, now another thing you could've had is the pressure plate could be set to disable self do not set to disable self, you can also set the pressure plate to not take items or monsters etc but just the party.
I figured it out, I have to set the pressure plate to "onToggle" and the door to "toggle"
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: ~Advanced Scripting and Editor Help

Post by Mysterious »

Hi SnowyOwl47. Thxs for that I get it now good job. It's cool when people help out with coding like this thxs again :) Just a question though how do you know if myvar is true or false? I assume it is activated by another script? thxs.
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: ~Advanced Scripting and Editor Help

Post by SnowyOwl47 »

Mysterious wrote:Hi SnowyOwl47. Thxs for that I get it now good job. It's cool when people help out with coding like this thxs again :) Just a question though how do you know if myvar is true or false? I assume it is activated by another script? thxs.
All you do is first declare it

myvar = false

then you can say
if myvar == false then
end

that says if myvar = false then do the following
Post Reply