Town Portal Code

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
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Town Portal Code

Post by LordGarth »

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,
}
Dungeon Master and DOOM will live forever.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Town Portal Code

Post by zimberzimber »

Why not, instead of spawning a portal, have the scroll set the parties location to where you intend it to teleport the party to?

If you want the town portal to work like in Diablo where you can go back, add a teleporter in the editor near the place where the scroll brings the party to, and have the scroll find that teleporter by name, and just set its position to where the party used the scroll.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Town Portal Code

Post by LordGarth »

I tried to have setPartylocation but I guess I did not get the code exactly right.

LordGarth
Dungeon Master and DOOM will live forever.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Town Portal Code

Post by zimberzimber »

LordGarth wrote:setPartylocation
I don't know where you came up with this, but this function doesn't exist...
Make sure whatever you're trying to pass is written here or somewhere here.

What you need in your situation is this:

Code: Select all

-- Replace GameObject with the id of whatever you're trying to relocate, or 'party' if you want to move the party.
GameObject:setPosition(x, y, facing, elevation, level)
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Town Portal Code

Post by LordGarth »

Would this be correct?

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(party)

party:setPosition(27, 19, facing, elevation, 1)




end


},
},
}
Dungeon Master and DOOM will live forever.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Town Portal Code

Post by zimberzimber »

LordGarth wrote:party:setPosition(27, 19, facing, elevation, 1)
You're attempting to return a variable and not a value.
If you want to get the parties facing, you'll have to do party.facing , same goes to elevation. (Although I suggest elevation to be set, to prevent the party from falling from hights or getting stuck in the ground.)
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Town Portal Code

Post by LordGarth »

party:setPosition(27, 19, 0, 0, 1)


?
Dungeon Master and DOOM will live forever.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Town Portal Code

Post by zimberzimber »

Yup.

You could use party.facing to get their current facing.
My asset pack [v1.10]
Features a bit of everything! :D
Post Reply