• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TalkAction /up and /down with parameter

Relicz

Programmer
Joined
Mar 18, 2010
Messages
18
Reaction score
4
Location
Australia
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
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!
 
Back
Top