Town Portal Code
Posted: Thu Dec 01, 2016 6:21 pm
Here is some code for a town portal scroll. The name and ui Name can be changed for the name of the town teleporting to.
The coordinates in set teleport target can be changed to where you want to go.
The first number is level then x then y then elevation.
I can not find a way to deactivate the teleporter after it is used though.
LordGarth
defineObject{
name = "ratanscroll",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/scroll_recipe.fbx",
},
{
class = "Item",
uiName = "Ratan Town Portal Scroll",
gfxIndex = 456,
weight = 0.3,
stackable = true,
traits = { "potion" },
},
{
class = "UsableItem",
sound = "teleport",
onUseItem = function(champion, x, y, direction, elevation, skillLevel)
local dX,dY = getForward(party.facing) --Directional offsets
if party.map:isWall(party.x, party.y, party.elevation) then
dX,dY = 0,0 --Targets Party's cell if cast on a wall
end
--spell cast and tagged for the champion who cast it.
spawn("teleporter_1", party.level, party.x, party.y, party.facing, party.elevation).teleporter:setTeleportTarget(1,27,19,0)
end
},
},
}
defineObject{
name = "teleporter_1",
components = {
{
class = "Particle",
particleSystem = "teleporter",
},
{
class = "Light",
color = vec(69/255, 95/255, 115/255),
brightness = 15,
range = 8,
castShadow = true,
shadowMapSize = 128,
staticShadows = true,
staticShadowDistance = 0, -- use static shadows always
offset = vec(0, 1.5, 0),
onUpdate = function(self)
self:setBrightness((math.noise(Time.currentTime() + 12) * 0.5 + 0.5 + 0.1) * 15)
end,
},
{
class = "Sound",
sound = "teleporter_ambient",
},
{
class = "Teleporter",
},
{
class = "Controller",
onInitialActivate = function(self)
self.go.teleporter:enable()
end,
onInitialDeactivate = function(self)
self.go.teleporter:disable()
self.go.light:fadeOut(0)
self.go.sound:fadeOut(0)
self.go.particle:fadeOut(0)
end,
onActivate = function(self)
self.go.teleporter:disable()
end,
onDeactivate = function(self)
self.go.teleporter:disable()
self.go.light:fadeOut(0.01)
self.go.sound:fadeOut(0.1)
self.go.particle:fadeOut(0.01)
end,
onToggle = function(self)
if self.go.teleporter:isEnabled() then
self:deactivate()
else
self:activate()
end
end,
},
},
placement = "floor",
editorIcon = 36,
}
The coordinates in set teleport target can be changed to where you want to go.
The first number is level then x then y then elevation.
I can not find a way to deactivate the teleporter after it is used though.
LordGarth
defineObject{
name = "ratanscroll",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/scroll_recipe.fbx",
},
{
class = "Item",
uiName = "Ratan Town Portal Scroll",
gfxIndex = 456,
weight = 0.3,
stackable = true,
traits = { "potion" },
},
{
class = "UsableItem",
sound = "teleport",
onUseItem = function(champion, x, y, direction, elevation, skillLevel)
local dX,dY = getForward(party.facing) --Directional offsets
if party.map:isWall(party.x, party.y, party.elevation) then
dX,dY = 0,0 --Targets Party's cell if cast on a wall
end
--spell cast and tagged for the champion who cast it.
spawn("teleporter_1", party.level, party.x, party.y, party.facing, party.elevation).teleporter:setTeleportTarget(1,27,19,0)
end
},
},
}
defineObject{
name = "teleporter_1",
components = {
{
class = "Particle",
particleSystem = "teleporter",
},
{
class = "Light",
color = vec(69/255, 95/255, 115/255),
brightness = 15,
range = 8,
castShadow = true,
shadowMapSize = 128,
staticShadows = true,
staticShadowDistance = 0, -- use static shadows always
offset = vec(0, 1.5, 0),
onUpdate = function(self)
self:setBrightness((math.noise(Time.currentTime() + 12) * 0.5 + 0.5 + 0.1) * 15)
end,
},
{
class = "Sound",
sound = "teleporter_ambient",
},
{
class = "Teleporter",
},
{
class = "Controller",
onInitialActivate = function(self)
self.go.teleporter:enable()
end,
onInitialDeactivate = function(self)
self.go.teleporter:disable()
self.go.light:fadeOut(0)
self.go.sound:fadeOut(0)
self.go.particle:fadeOut(0)
end,
onActivate = function(self)
self.go.teleporter:disable()
end,
onDeactivate = function(self)
self.go.teleporter:disable()
self.go.light:fadeOut(0.01)
self.go.sound:fadeOut(0.1)
self.go.particle:fadeOut(0.01)
end,
onToggle = function(self)
if self.go.teleporter:isEnabled() then
self:deactivate()
else
self:activate()
end
end,
},
},
placement = "floor",
editorIcon = 36,
}