~Basic Scripting and Editor Help(Easy Scripting Updated!)

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!
Post Reply
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

~Basic Scripting and Editor Help(Easy Scripting Updated!)

Post by SnowyOwl47 »

Basic Scripting

Easy methods:

I noticed that the coding seemed to be pretty complicated so I decided to turn it into an easy scripting!

From What I know I've come up with this. Go to your Dungeon in dungeon editor and copy paste this into a new script_entity:

Code: Select all

--                                                           Easy Commands:
--                                                            Version: 0.2
--
--              Easy commands is a complicated proccess of code turned into easier commands but probly less control, it also makes
--                          commands shorter and less bunchy. To use easy commands follow the instructions below!
--
--
--                                                            Instructions:
-- 
--              Simply name this script_entity to game and make sure all of this script is copy pasted into that script_entity, 
--                                                              thats it!
--
--  
--                                                              Commands:
--
--              Enable/disabled Champions: game.script.champEnabled(champion, bool)
--            
--              Get if a champion is enabled/disabled: game.script.getEnabled(champion)
--
--              Get Champion: game.script.champ(champion)
--
--              Give exp to a champion: game.script.gainExp(champion, amount)
--
--              Easily set up the outdoors dungeon area: game.script.setUpOutDoors(level) (Currently bugged you will have to place a forest_heightmap
--
--              DISABLED::::Set the Xp gain for the champions: game.script.setXpGain(percentage) (In the percentage there is no need for a % sign)
--
--              Add Item to an alcove or possibly something else: game.script.addItem(entity, item)

playing = true
fighting = false
function champEnabled(champion, bool)
    -- This bit of coding is checking to see what the player set the method parematers to because for champions to enable disabled
    -- You can't simply say return party.part:getChampion(champion):setEnabled(bool) it won't work that way :D.
    if champion == 1 then
       if bool == false then
           return party.party:getChampion(1):setEnabled(false)
       end
       if bool == true then
           return party.party:getChampion(1):setEnabled(true)
       end
    end
    if champion == 2 then
       if bool == false then
           return party.party:getChampion(2):setEnabled(false)
       end
       if bool == true then
           return party.party:getChampion(2):setEnabled(true)
       end
    end
    if champion == 3 then
       if bool == false then
           return party.party:getChampion(3):setEnabled(false)
       end
       if bool == true then
           return party.party:getChampion(3):setEnabled(true)
       end
    end
    if champion == 4 then
       if bool == false then
           return party.party:getChampion(4):setEnabled(false)
       end
       if bool == true then
           return party.party:getChampion(4):setEnabled(true)
       end
    end

end
function gainExp(champion, amount)
    return party.party:getChampion(champion):gainExp(amount)
end
function champ(champion)
    return party.party:getChampion(champion)
end
function getEnabled(champion)
    return party.party:getChampion(champion):getEnabled()
end
function setUpOutDoors(level)
    return spawn("forest_day_sky",level,1,0,0,0,"forest_day_sky_1") and spawn("forest_heightmap",level,2,0,0,0,"forest_heightmap")
end
function setXpGain(percent)
      -- This checks to see if the party is dead
      while party.party.getHealth() == 0 do
            playing = false
      end
      -- This is just making sure that the party is still alive
      while playing == true do
            playing = true
      end
      -- This checks to see what percentage was put and then sets the gain Xp
      if percent == 10 then
          -- This makes sure the player is still alive
          while playing == true do
              -- Sets the Xp Gain
          end
      end
end
function addItem(entity, item)
   return entity.surface:addItem(item)
end
then name it game.

Here are some new methods:

Disable Enable Party:

Code: Select all

game.script.champEnabled(champion, bool)
Champion gain exp

Code: Select all

game.script.gainExp(champion, amount)
Get Champion Enabled:

Code: Select all

game.script.getEnabled(champion)
Get champion:

Code: Select all

game.script.champ(champion)
Sets Xp Gain(Currently Disabled do to lack of scripting knowledge in LOG2):

Code: Select all

game.script.setXpGain(percentage) 
--In the percentage there is no need for a % sign
Easily Set Up the outdoors levels: (Half working, you still have to place down a forest_heightmap):

Code: Select all

game.script.setUpOutDoors(level)
Add items to an alcove or possibly something else:

Code: Select all

game.script.addItem(entity, item)
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!

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:
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

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 Tue Oct 21, 2014 5:20 pm, edited 43 times in total.
User avatar
Rubilax
Posts: 51
Joined: Mon Oct 13, 2014 4:56 am

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by Rubilax »

I wish I could give you a hand with figuring out some codes, but I've forgotten the bare minimum of knowledge I had of coding. However, I can give suggestions for easy scripts (at least I hope they will be).

One such script would be using a pressure plate to trigger a pre-written note/scroll to spawn in a champion's inventory; I intend to use this as a journal entry system along with a hudPrint to alert the player to new entries.

Oh, also how exactly can you control how long a hudPrint stays on screen for?
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by SnowyOwl47 »

Rubilax wrote:I wish I could give you a hand with figuring out some codes, but I've forgotten the bare minimum of knowledge I had of coding. However, I can give suggestions for easy scripts (at least I hope they will be).

One such script would be using a pressure plate to trigger a pre-written note/scroll to spawn in a champion's inventory; I intend to use this as a journal entry system along with a hudPrint to alert the player to new entries.

I'm not quite getting that... You want me to find out how to make a scroll that is pre-written or a note and make it spawn in the champs inv at begging of the game?
User avatar
Rubilax
Posts: 51
Joined: Mon Oct 13, 2014 4:56 am

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by Rubilax »

SnowyOwl47 wrote:
Rubilax wrote:I wish I could give you a hand with figuring out some codes, but I've forgotten the bare minimum of knowledge I had of coding. However, I can give suggestions for easy scripts (at least I hope they will be).

One such script would be using a pressure plate to trigger a pre-written note/scroll to spawn in a champion's inventory; I intend to use this as a journal entry system along with a hudPrint to alert the player to new entries.

I'm not quite getting that... You want me to find out how to make a scroll that is pre-written or a note and make it spawn in the champs inv at begging of the game?
Say I step on a pressure plate (hidden) in front of a door. I want to provide a hint about how this works without breaking immersion. I have this plate trigger a script that sets a note/scroll (whichever one, interchangable would be great) to be spawned in the player's inventory, and the note/scroll has a predefined message on it. I had this script working in LoG 1, I have no idea where I found it, but I can go grab it quick and show you what it looks like, because I'm not sure if it works anymore.

Here it is:

local startMessage = spawn("scroll")
startMessage:setScrollText("text")
party:getChampion(1):insertItem(11,startMessage)
Last edited by Rubilax on Sat Oct 18, 2014 7:50 am, edited 1 time in total.
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by SnowyOwl47 »

Rubilax wrote:
SnowyOwl47 wrote:
Rubilax wrote:I wish I could give you a hand with figuring out some codes, but I've forgotten the bare minimum of knowledge I had of coding. However, I can give suggestions for easy scripts (at least I hope they will be).

One such script would be using a pressure plate to trigger a pre-written note/scroll to spawn in a champion's inventory; I intend to use this as a journal entry system along with a hudPrint to alert the player to new entries.

I'm not quite getting that... You want me to find out how to make a scroll that is pre-written or a note and make it spawn in the champs inv at begging of the game?
Say I step on a pressure plate (hidden) in front of a door. I want to provide a hint about how this works without breaking immersion. I have this plate trigger a script that sets a note/scroll (whichever one, interchangable would be great) to be spawned in the player's inventory, and the note/scroll has a predefined message on it. I had this script working in LoG 1, I have no idea where I found it, but I can go grab it quick and show you what it looks like, because I'm not sure if it works anymore.
If you show me it I can probably convert it quickly.
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by SnowyOwl47 »

@Rubilax It's getting late for me but here it is:

Code: Select all

spawnspawn("scroll",x,y,height,value i don't know D:,"startMessage")
startMessage.control:setScrollText("text")
party.party:getChampion(1):insertItem(11,startMessage)
This might work but I don't have the editor open bc I'm to tried ill check back in tomorrow and see if it was wrong and if it is ill fix it :geek:
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by Mysterious »

I cant believe how hard it is to try and script 2 Torches to open a door lol. It has to be simple surely.
User avatar
Rubilax
Posts: 51
Joined: Mon Oct 13, 2014 4:56 am

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by Rubilax »

Mysterious wrote:I cant believe how hard it is to try and script 2 Torches to open a door lol. It has to be simple surely.
Add a counter at value 2 that links to your door and link the two torches up to that. Then make the two torches decrement that counter onActivate if you want the torches to be placed in the holder, or vice versa. No scripting necessary :3
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by Drakkan »

Hello man,
Altough I am total lame in coding and I did not understand majority of the codes, I still appreicate this thread and also welcoming some summary for map editor, that will help many people ! I am counting on your help with scriptingin the future ;) :D
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Basic Scripting and Editor Help(Short Script Reference)

Post by JohnWordsworth »

Food for thought for someone with more time than me at the moment (I'm using all my spare time at the moment on the new model editor)...

If you want to see a list of most of the components in the game, you can probably use this screenshot from an old blog post... http://www.grimrock.net/wp-content/uplo ... ofiler.jpg

Sure, we don't know what all of the definitions and methods are for these components, but it gives you a place to start experimenting. Using the above chart, we could likely try to make a breakable door that can also be opened by putting something in a socket on it with something like...

Code: Select all

defineObject{
  name = "my_door",
  components = {
    {
      class = "Model",
      model = "...",
    },
    {
      class = "Door",
      ???
    },
    {
      class = "Socket",
      ???
    },
    {
      class = "Health",
      health = 15,
      immunities = { "poison" },
    },
  },
  placement = ??,
  editorIcon = ??
}
There will likely be a lot of trial and error involved but some of the properties on the components will be the same (or similar to) LOG1 I guess. However, I expect there will also be lots of new ones too!

Equally, using the attached list of components, it means you can start trying to play around with entities from the console in the main game (to see what functions exist) doing things like...

Code: Select all

entity = spawn(...); entity.animation:stop(); 
The above might not be a function, but it might work. Anyway, I think I'll just wait for the official asset pack and modding guide to come out, but if you're really eager - this could be a good place to start!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Post Reply