Teleportation scroll request
Teleportation scroll request
Please somebody could define scroll of teleportation ?
After use (right click) it will be destroyed and it will teleport party to some coordinates. thanks
After use (right click) it will be destroyed and it will teleport party to some coordinates. thanks
Re: Teleportation scroll request
Sort of a WIP, somebody could probably improve what I made so far.
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.
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
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.
Re: Teleportation scroll request
I have placed few scroll on floor and used on of them - editor crashed with this

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)

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)
Re: Teleportation scroll request
You could try defining something like array of destinations:
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
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
}
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.
Re: Teleportation scroll request
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:
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.
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
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.
Re: Teleportation scroll request
wonderfull, its working ! Will definitely credit you for this, thanks man.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 }, }, }
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.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
Edit: Added a teleportation effect to the script.
Re: Teleportation scroll request
Scticked in the superthread as useful item 

Re: Teleportation scroll request
Glad I could help 

Re: Teleportation scroll request
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:
2. Place script_entity with name teleportTarget (doesn't matter where) and put inside:
This one actually works, my previous entry in this thread was rather messy
--
Blichew
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
},
},
}
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

--
Blichew
Re: Teleportation scroll request
Just tried yours out Blichew, works perfectly.