Another default script edit I thought I'd share. It's pretty inconsequential, but I think it's a nice quality of life tweak
I wanted to do things like "/up 2" to go up 2 floors rather than do the command twice, so I wrote a quick edit. Of course, it still works without a parameter, and just takes you up/down 1 floor as it did previously.
First, since we're adding a parameter, make sure you add a separator to the commands in your talkactions.xml for it to work
Nice! So now, let's update our up.lua and down.lua scripts
up.lua
down.lua
Enjoy!
I wanted to do things like "/up 2" to go up 2 floors rather than do the command twice, so I wrote a quick edit. Of course, it still works without a parameter, and just takes you up/down 1 floor as it did previously.
First, since we're adding a parameter, make sure you add a separator to the commands in your talkactions.xml for it to work
XML:
<talkaction words="/up" separator=" " script="up.lua" />
<talkaction words="/down" separator=" " script="down.lua" />
Nice! So now, let's update our up.lua and down.lua scripts
up.lua
Lua:
function onSay(player, words, param)
if not player:getGroup():getAccess() then
return true
end
local position = player:getPosition()
-- if we have a number param, use that. if not, just go up by 1
local value = tonumber(param)
if not value then
position.z = position.z - 1
else
position.z = position.z - value
end
player:teleportTo(position)
return false
end
down.lua
Lua:
function onSay(player, words, param)
if not player:getGroup():getAccess() then
return true
end
local position = player:getPosition()
-- if we have a number param, use that. if not, just go down by 1
local value = tonumber(param)
if not value then
position.z = position.z + 1
else
position.z = position.z + value
end
player:teleportTo(position)
return false
end
Enjoy!