Teleportation scroll request

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
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Teleportation scroll request

Post by Drakkan »

Please somebody could define scroll of teleportation ?
After use (right click) it will be destroyed and it will teleport party to some coordinates. thanks
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
sps999
Posts: 44
Joined: Sun Oct 26, 2014 11:16 pm

Re: Teleportation scroll request

Post by sps999 »

Sort of a WIP, somebody could probably improve what I made so far.

Code: Select all

defineObject{
	name = "teleport_scroll",
	baseObject = "tome_wisdom",
	components = {
		{
			class = "Model",
			model = "assets/models/items/scroll.fbx",
			castShadow = true,
		},
		{
			class = "Item",
			uiName = "Teleportation Scroll",
			gfxIndex = 112,
			description = "Reading this will warp you to another location.",
			weight = 0.3,
		},
		{
			class = "UsableItem",
			sound = "teleport",
			onUseItem = function(self)
				teleportScroll.script.onUseItem(self)
			end
		},
	},
}

Code: Select all

function onUseItem(self)

	warp = spawn("teleporter", party.level, party.x, party.y, 0, party.elevation)
	warp.teleporter:setTeleportTarget(1, 7, 22, 0)  -- (Target Level, Target X, Target Y, Target Elevation)

end
This works as intended, just define the top code as an object and put the bottom code in a script entity named "teleportScroll," but there are quite a few limitations depending on how you want to use this:
Since the scrolls only call the onUseItem function of the "teleportScroll" script, they can only teleport you to the one location you set. If somebody could figure out a way to set a target for each scroll, then it will be possible to have a unique target for each scroll.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Teleportation scroll request

Post by Drakkan »

I have placed few scroll on floor and used on of them - editor crashed with this
Image


btw:I am ok if each of these scroll will return you to the same location. I see you tried to solve it with spawning teleport. What about some setPartyposition command directly just with for example playing teleport sound ? Btw not sure if I see that in script but scroll should be destroyed after use (and the spawned teleport as well)
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: Teleportation scroll request

Post by Blichew »

You could try defining something like array of destinations:

Code: Select all

teleportScrollCoords = {1,1,7,22,0, -- 1st scroll - Target Level, Target X, Target Y, Target Elevation
						2,1,9,30,0 -- 2nd scroll - Target Level, Target X, Target Y, Target Elevation
						}
Then, your onUseItem(self) would check id of scroll that was used. This could work that way in theory - I didn't test it...

Code: Select all

function onUseItem(self) -- can it go with sender instead of self ? Can it pass BOTH variables ? 

   warp = spawn("teleporter", party.level, party.x, party.y, 0, party.elevation)
   local scrollID = string.sub(self.go.id,16) -- as long if it's scroll's ID "teleport_scroll_x"
   local dl = teleportScrollCords[scrollID + 1]
   local dx = teleportScrollCords[scrollID + 2]
   local dy = teleportScrollCords[scrollID + 3]
   local de = teleportScrollCords[scrollID + 4]
   warp.teleporter:setTeleportTarget(dl,dx,dy,de)  -- (Target Level, Target X, Target Y, Target Elevation)

end
Last edited by Blichew on Sun Nov 02, 2014 9:04 pm, edited 1 time in total.
User avatar
sps999
Posts: 44
Joined: Sun Oct 26, 2014 11:16 pm

Re: Teleportation scroll request

Post by sps999 »

Alright, so I overlooked the teleporter staying where it was.

I started messing with getWorldPosition and setWorldPosition and this is what I came up with:

Code: Select all

defineObject{
	name = "teleport_scroll",
	baseObject = "tome_wisdom",
	components = {
		{
			class = "Model",
			model = "assets/models/items/scroll.fbx",
			castShadow = true,
		},
		{
			class = "Item",
			uiName = "Teleportation Scroll",
			gfxIndex = 112,
			description = "Reading this will warp you to another location.",
			weight = 0.3,
		},
		{
			class = "UsableItem",
			sound = "teleport",
			onUseItem = function()
				teleportTarget.script.onUseItem() -- name the script entity "teleportTarget"
			end
		},
	},
}

Code: Select all

function onUseItem()
	local target = self.go:getWorldPosition()
	party:setWorldPosition(target)
	spawn("teleportation_effect", party.level, party.x, party.y, 0, party.elevation)
end
Also, be sure to rename your script entity to "teleportTarget" (it used to be "teleportScroll") or using the item will give you an error, because the item is looking for something that doesn't exist. The scroll will now warp the party to the location of the script entity itself.

Edit: Added a teleportation effect to the script.
Last edited by sps999 on Wed Nov 05, 2014 2:08 am, edited 1 time in total.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Teleportation scroll request

Post by Drakkan »

sps999 wrote:Alright, so I overlooked the teleporter staying where it was.

I started messing with getWorldPosition and setWorldPosition and this is what I came up with:

Code: Select all

defineObject{
	name = "teleport_scroll",
	baseObject = "tome_wisdom",
	components = {
		{
			class = "Model",
			model = "assets/models/items/scroll.fbx",
			castShadow = true,
		},
		{
			class = "Item",
			uiName = "Teleportation Scroll",
			gfxIndex = 112,
			description = "Reading this will warp you to another location.",
			weight = 0.3,
		},
		{
			class = "UsableItem",
			sound = "teleport",
			onUseItem = function()
				teleportTarget.script.onUseItem() -- name the script entity "teleportTarget"
			end
		},
	},
}

Code: Select all

function onUseItem()
	target = self.go:getWorldPosition()
	party:setWorldPosition(target)
	spawn("teleportation_effect", party.level, party.x, party.y, 0, party.elevation)
end
Also, be sure to rename your script entity to "teleportTarget" (it used to be "teleportScroll") or using the item will give you an error, because the item is looking for something that doesn't exist. The scroll will now warp the party to the location of the script entity itself.

Edit: Added a teleportation effect to the script.
wonderfull, its working ! Will definitely credit you for this, thanks man.
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Teleportation scroll request

Post by Doridion »

Scticked in the superthread as useful item ;)
User avatar
sps999
Posts: 44
Joined: Sun Oct 26, 2014 11:16 pm

Re: Teleportation scroll request

Post by sps999 »

Glad I could help :D
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: Teleportation scroll request

Post by Blichew »

I think I found a solution to have multiple scrolls, each with different target:

1. Changed your object definition a bit to send ID of scroll which was used:

Code: Select all

defineObject{
   name = "teleport_scroll",
   baseObject = "tome_wisdom",
   components = {
      {
         class = "Model",
         model = "assets/models/items/scroll.fbx",
         castShadow = true,
      },
      {
         class = "Item",
         uiName = "Teleportation Scroll",
         gfxIndex = 112,
         description = "Reading this will warp you to another location.",
         weight = 0.3,
      },
      {
         class = "UsableItem",
         sound = "teleport",
         onUseItem = function(self)
            teleportTarget.script.validateTarget(self.go.id) -- name the script entity "teleportTarget"
         end
      },
   },
}
2. Place script_entity with name teleportTarget (doesn't matter where) and put inside:

Code: Select all

teleport_scroll_targets = {"teleport_scroll_1",1,25,12,0, -- {scrollID,level,X,Y,elevation}
							"teleport_scroll_2",1,27,12,0}


function validateTarget(sender)
	for i = 1,#teleport_scroll_targets do
		if teleport_scroll_targets[i] == sender then
			local targetL = teleport_scroll_targets[i+1]
			local targetX = teleport_scroll_targets[i+2]
			local targetY = teleport_scroll_targets[i+3]
			local targetE = teleport_scroll_targets[i+4]
			moveToTarget(targetL,targetX,targetY,targetE)
		end
	end
end

function moveToTarget(L,X,Y,E)
	local tp = spawn("teleporter", party.level, party.x, party.y, 0, party.elevation)
	tp.teleporter:setTeleportTarget(L,X,Y,E)
	tp:destroyDelayed(1)
end
This one actually works, my previous entry in this thread was rather messy :oops:

--
Blichew
User avatar
sps999
Posts: 44
Joined: Sun Oct 26, 2014 11:16 pm

Re: Teleportation scroll request

Post by sps999 »

Just tried yours out Blichew, works perfectly.
Post Reply