Is it possible to script party movement?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Is it possible to script party movement?

Post by Isaac »

I'd like to know if a script can fake a key-press (that the engine reacts to), or to call a function that causes the party to move; as though the player had pressed a key.

If there is no such method, I'd really like for that to be in the next patch (if one is planned).

I'm tackling the first spinner trap in EoB; the one with the cursed sling, that rotates the party if they step on it.

I planned to use teleporters that change the party facing, but I thought it would be a nice touch if the party view actually showed the spin take place. 8-)
User avatar
Brodie301
Posts: 286
Joined: Sun Apr 08, 2012 6:00 pm
Location: Mississippi, USA

Re: Is it possible to script party movement?

Post by Brodie301 »

Do you remember the one spinner from the Main game on level 9?
You see the walls and compass change. I have one in my mod as well.
When you say see the spin take place are you talking about an animation or kind of change facing twice?
The FORCE is with me!!!
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it possible to script party movement?

Post by Isaac »

I was thinking it would be neat to have the engine trigger a right or left turn via script.

**I mistook one of the teleporter functions for being able to change facing, but... nope it's not for that.
Edit: I don't actually remember that spinner trap on level 9 ~offhand.
User avatar
Brodie301
Posts: 286
Joined: Sun Apr 08, 2012 6:00 pm
Location: Mississippi, USA

Re: Is it possible to script party movement?

Post by Brodie301 »

It's between the armory and door where ice lizards start.
I didn't script mine just used the editor.
I used 3 spaces, 1 teleporter that is activated triggered by party change facing invisible and silent, then 2 hidden pressure plates on each side of it one that is activate teleporter activate and one that is activate teleporter deactivate.
When you hit first plate it leaves teleporter on you the hit teleporter which goes to next block but facing changed and deactivates the teleporter so you are walking back thru it to the other plate which activates it again.
The FORCE is with me!!!
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it possible to script party movement?

Post by Isaac »

Edit: There was a bug in this code but it did expose a repeatable editor crash.
SpoilerShow
I just stumbled upon the solution (or so I thought); the target of a teleporter can be set via script and it accepts a choice of facing. 8-)

However... This works for me (as I had expected); it changes the party facing, but then promptly crashes the editor. :shock:
function spinner()
x = math.random(4) << Bug
spinnerTrap:setTeleportTarget(19, 27, x, 2)
end

Setup:
One script object [with the above code]
One hidden pressure plate [connected to the script @ 19,27]
One teleporter [named spinnerTrap]
Last edited by Isaac on Tue Oct 16, 2012 3:29 am, edited 8 times in total.
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Is it possible to script party movement?

Post by Neikun »

Maybe with a timer you could have it activate multiple teleporters in sequence. Deactivate the timer with a counter perhaps?
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it possible to script party movement?

Post by Isaac »

Neikun wrote:Maybe with a timer you could have it activate multiple teleporters in sequence. Deactivate the timer with a counter perhaps?
I thought about it; but I tried the above; it works very well except for the side effect. :D

I hope I'm doing something wrong, and that I can use this method correctly/safely; it's perfect.

I'm thinking that I might need to script a deactivate function, as the teleporter points to itself. :o

Update: Solved; (no more crashes).

Code: Select all

function spinner()
x = (math.random(4)-1)
spinnerTrap:setTeleportTarget(19, 27, x, 2)
end
I noticed that it only crashed when the numbers directed it north. It was passing a '4' instead of a zero.

Still no turning animation, but it's accurate to EoB. Image
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Is it possible to script party movement?

Post by petri »

I think this is a good idea. Added to the list.
User avatar
djoldgames
Posts: 107
Joined: Fri Mar 23, 2012 11:28 pm
Contact:

Re: Is it possible to script party movement?

Post by djoldgames »

@isaac:

FOr the EOB mod I have scripts called party_rotators. This is the source:

Code: Select all

onMove = function(self,dir)
		for e in help.entitiesAtDir(self,dir) do
			if e.name == 'teleporter_rotator90' then
				e:setTeleportTarget(e.x, e.y, (self.facing + 1)%4)
				print("Party rotated by 90")
			end
			if e.name == 'teleporter_rotator180' then
				e:setTeleportTarget(e.x, e.y, (self.facing + 2)%4)
				print("Party rotated by 180")
			end
			if e.name == 'teleporter_rotator270' then					
				e:setTeleportTarget(e.x, e.y, (self.facing + 3)%4)
				print("Party rotated by 270")
			end
		end
end
This is for party.onMove hook. Only one thing you must to do is clone telepporter as new instance named "teleporter_rotator90" etc. and place it anywhere using the editor without additionaly scripting. There is also many places in EOB where teleporter target is out of teleporter x,y then you can free change teleporter target by editor.
You don't need to deactivate teleporter_rotator, if party is in One teleporter, trigger is activated only once.

Check my EOB thread, I upload my "cleaned" souce code soon...
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it possible to script party movement?

Post by Isaac »

petri wrote:I think this is a good idea. Added to the list.
8-)
djoldgames wrote:Check my EOB thread, I upload my "cleaned" souce code soon...
Very sharp [and elegant] solution. 8-)
Post Reply