Events

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!
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Events

Post by NutJob »

Are there any global events that can trigger scripts? The one I'm looking for is something to run a script when the players loads a game. Such as onLoad, OnEnter, onPlayerStart or anything that represents the game is fully loaded that can trigger a script to initialize other scripts, spawn items, set effects, etc.

OR

Must I set all my scripts to an object? Which is fine, can simply set an invisible object (floor_trigger) but I would have to set them down everywhere over every square inch because people will not one-shoot dungeons without any saving or loading.

Am I missing something obviously critical/simplistic? I'm very used to having events run the program or loops or polling but can not figure it out in this editor.
User avatar
Skuggasveinn
Posts: 562
Joined: Wed Sep 26, 2012 5:28 pm

Re: Events

Post by Skuggasveinn »

you can have a script entity that doesn't use a function that needs to be called
like placing a command inside a script but outside a function will run it when the dungeon starts

Code: Select all

Spawn("rock",1,16,20,0,2)
So you should be able to just spawn items and effects directly that way without the need to trigger them

but placing it within a function means that you need to call it with a trigger

Code: Select all

function spawnrock()
      Spawn("rock",1,16,20,0,2)
end
Hope that helps.

Skuggasveinn.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
User avatar
Chimera005ao
Posts: 187
Joined: Sun Jun 29, 2014 8:34 am

Re: Events

Post by Chimera005ao »

Spawn("rock",1,16,20,0,2)
Mind running through the parameters there?
First designates it will be a rock, easy enough.
I'm going to assume three of them that are next to each other will be the map coordinate, to tell what map to spawn it in.
Then two of the others are the x, y coordinate within that map?
But then there could also be height, and I remember one in the first Grimrock was facing direciton... : /
User avatar
Chimera005ao
Posts: 187
Joined: Sun Jun 29, 2014 8:34 am

Re: Events

Post by Chimera005ao »

Ok, messing around with it a bit.
The first number seems to be the map, though I'm not sure how that works.
Numbers 2 and 3 indicate the x, y cordinates of the floor.
Number 4 is the facing direction.
Number 5 is the height it seems.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Events

Post by NutJob »

Appreciate the answer Skuggasveinn. I'll assume whatever script_entity I set on a level runs only when a player enters that level or do all the script_entities trigger on first load?

Ex 1. (assuming correct)

Party loads into the game on LevelB
LevelA [0,0,0] lua does nothing
LevelB [0,0,1] lua executes
LevelC [0,0,2] lua does nothing

--

Ex 2. (potentially what is happening; suppose I should just test =] )

Party loads into the game on LevelC
LevelA [0,0,0] lua executes
LevelB [0,0,1] lua executes
LevelC [0,0,2] lua executes

--

Ex 3. (what I was expecting being I came from a heavy event-run environment)

Party loads into the game on LevelA
onLoad init() run
LevelA [0,0,0] lua executes
LevelB [0,0,1] lua does nothing
LevelC [0,0,2] lua does nothing

--

Anyways I'll get a hold how it's done or figure out a way. I just wanted to get my bearings before starting a project.
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Events

Post by SnowyOwl47 »

NutJob wrote:Appreciate the answer Skuggasveinn. I'll assume whatever script_entity I set on a level runs only when a player enters that level or do all the script_entities trigger on first load?

Ex 1. (assuming correct)

Party loads into the game on LevelB
LevelA [0,0,0] lua does nothing
LevelB [0,0,1] lua executes
LevelC [0,0,2] lua does nothing

--

Ex 2. (potentially what is happening; suppose I should just test =] )

Party loads into the game on LevelC
LevelA [0,0,0] lua executes
LevelB [0,0,1] lua executes
LevelC [0,0,2] lua executes

--

Ex 3. (what I was expecting being I came from a heavy event-run environment)

Party loads into the game on LevelA
onLoad init() run
LevelA [0,0,0] lua executes
LevelB [0,0,1] lua does nothing
LevelC [0,0,2] lua does nothing

--

Anyways I'll get a hold how it's done or figure out a way. I just wanted to get my bearings before starting a project.
I'll check to see if there is a way to do that you never know we ourselves the master coders xD don't know everything.
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

Re: Events

Post by antti »

NutJob wrote:Appreciate the answer Skuggasveinn. I'll assume whatever script_entity I set on a level runs only when a player enters that level or do all the script_entities trigger on first load?
All the script entities are triggered when the game is started since the simulation runs on all the levels. If you want something to trigger when entering a level for the first time, one handy way to do it is to use a timer and enable its currentLevelOnly and disableSelf -parameters (but leave the timer component activated so the timer doesn't need to be started separately). Then when the player enters the level, the timer will start and its connectors will fire after the timer runs. A timerInterval of 0 seems to work for this purpose, but do remember the disableSelf! This will only work only for the first time though so if repeated use is needed, something more custom would need to be done.

There's no way to detect when player loads the game as far as I know.
Steven Seagal of gaming industry
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Events

Post by minmay »

In Grimrock 1 you could detect reloads by creating an FX entity with an infinite lifetime and checking for its existence every so often, since reloads destroyed FX entities. Maybe there's something like that?
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Events

Post by NutJob »

antti wrote:... one handy way to do it is to use a timer and enable its currentLevelOnly and disableSelf -parameters (but leave the timer component activated so the timer doesn't need to be started separately)...
minmay wrote:...detect reloads by creating an FX entity with an infinite lifetime and checking for its existence every so often...
Magnificent, and the information I sought.

Great game and community.

Really looking forward to the Scripting Reference that's currently on the TODO list. What must I do, Buy a fourth bundle on Steam for a friend to get this going? /giving you a hard time =)
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Events

Post by NutJob »

Chimera005ao wrote:Ok, messing around with it a bit.
The first number seems to be the map, though I'm not sure how that works.
This appears to work like the first editor and is literally the order the levels descend (why there's a 'move up' and ' move down' when you right-click a level); under the Project Tab. Though the new way of assigning where the levels are placed [in the world] is much better in this editor.
Numbers 2 and 3 indicate the x, y cordinates of the floor.
Number 4 is the facing direction.
Number 5 is the height it seems.
The sixth variable is the "string_id"

Ex. spawn("dungeon_pit",1,3,3,2,-7,"dungeon_pit_of_doooooom")
Post Reply