Script for an invisible teleporter with random spin

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
ParalHAXX
Posts: 2
Joined: Wed May 17, 2017 6:00 pm
Location: France

Script for an invisible teleporter with random spin

Post by ParalHAXX »

Hi there, i have a hard time finding a script to make an invisible teleporter making a random spin (using a floor trigger).
Is there a simple script that can make that ? In the first Grimrock i used this one:

Code: Select all

 function activate(object)
-- print (object.name)
   for i in entitiesAt(object.level, object.x, object.y) do
      if i.name == "teleporter" then
        local math = math.random (0,3)
      i:setTeleportTarget(i.x, i.y, math)
      end
   end
end


But the commands are differents in Grimrock 2, someone knows what do i have to change in this script by any chance ?

Thanks in advance for your help.
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Script for an invisible teleporter with random spin

Post by Zo Kath Ra »

If you put a floor trigger and a teleporter on the same square (and at the same elevation), and the party steps on the square, the floor trigger doesn't get activated, because the teleporter has a higher priority.

That's why I would do it like this:

1) Put an invisible teleporter on the square, and set its initialState to "deactivate".
Then set the teleporter's destination.

2) Put a floor trigger on the same square (and at the same elevation), and connect it to this script:

Code: Select all

function randomSpinTeleport(caller)
	for entity in caller.go.map:entitiesAt(caller.go.x, caller.go.y) do
		if entity.teleporter and (entity.elevation == caller.go.elevation) then
			local level, x, y, elevation = entity.teleporter:getTeleportTarget()
			party:setPosition(x, y, math.random(0, 3), elevation, level)
			break
		end
	end
end
How are you setting math.randomseed() ?
User avatar
ParalHAXX
Posts: 2
Joined: Wed May 17, 2017 6:00 pm
Location: France

Re: Script for an invisible teleporter with random spin

Post by ParalHAXX »

It work very well, and it seems i can use that as a base for more complex use of teleporters, thanks a lot Zo Kath Ra, it help me a lot.
Post Reply