• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua It is possible to disable hotkeys for a certain area?

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,764
Solutions
1
Reaction score
227
Location
Chile, Santiago
Hey everyone,

It is possible to disable hotkeys for a certain area?

By this I mean if there is a function or how could this be done.

Regards,
Kito

PS: By hotkeys I mean using potion/runes.
 
I think it is possible, but I don't know any existing built-in function for such purpose.

Maybe it would take some heavy modifications both on client side and sources.
Someone could be able to help you further mate
 
quite simple

data/lib/core/player.lua
Code:
function Player:isInArea(center, rangeX, rangeY)
    local spec = Game.getSpectators(center, false, true, rangeX, rangeX, rangeY, rangeY)
    if #spec > 0 then
        for i = 1, #spec do
            if spec[i] == self then
                return true
            end
        end
    end
    return false
end

action script
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isHotkey then
        if player:isInArea(Position(1022, 1001, 7), 3, 3) then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You may not use this on hotkey in this area.')
            return false
        end
    end
    return true
end
 
quite simple

data/lib/core/player.lua
Code:
function Player:isInArea(center, rangeX, rangeY)
    local spec = Game.getSpectators(center, false, true, rangeX, rangeX, rangeY, rangeY)
    if #spec > 0 then
        for i = 1, #spec do
            if spec[i] == self then
                return true
            end
        end
    end
    return false
end

action script
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isHotkey then
        if player:isInArea(Position(1022, 1001, 7), 3, 3) then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You may not use this on hotkey in this area.')
            return false
        end
    end
    return true
end

Thanks, but now I have to put all potions and runes on actions.xml and that that function to the regarding .lua files?

Edit: Also it is possible to set push time to 200 besides the config at config.lua only on this specific area? I mean using this onMove at events and checking if player is in area, then set time to move more quickly.
 
quite simple

data/lib/core/player.lua
Code:
function Player:isInArea(center, rangeX, rangeY)
    local spec = Game.getSpectators(center, false, true, rangeX, rangeX, rangeY, rangeY)
    if #spec > 0 then
        for i = 1, #spec do
            if spec[i] == self then
                return true
            end
        end
    end
    return false
end

action script
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isHotkey then
        if player:isInArea(Position(1022, 1001, 7), 3, 3) then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You may not use this on hotkey in this area.')
            return false
        end
    end
    return true
end
Code:
function Player:isInArea(center, rangeX, rangeY)
    local pos = self:getPosition()
    return (pos.x >= center.x-rangeX && pos.x <= center.x+rangeX && pos.y >= center.y+rangeY && pos.y <= center.y+rangeY)
end
why use specs when you can just compare x and y coordinates?
 
Code:
function Player:isInArea(center, rangeX, rangeY)
    local pos = self:getPosition()
    return (pos.x >= center.x-rangeX && pos.x <= center.x+rangeX && pos.y >= center.y+rangeY && pos.y <= center.y+rangeY)
end
why use specs when you can just compare x and y coordinates?

That function doesn't work, and the math is bad calculated, thanks for the idea, here is the update:

Code:
function isInArea(playerId, center, rangeX, rangeY)
    local player = Player(playerId)
  
    if not player then
        return false
    end  
  
    local pos = player:getPosition()
    if (pos.x <= center.x+rangeX and pos.x >= center.x-rangeX) and (pos.y <= center.y+rangeY and pos.y >= center.y-rangeY) and (pos.z == center.z) then
        return true
    else
        return false
    end
end


@Xeraphus Thanks, but now I have to put all potions and runes on actions.xml and that that function to the regarding .lua files?

Also it is possible to set push time to 200 besides the config at config.lua only on this specific area? I mean using this onMove at events and checking if player is in area, then set time to move more quickly.
 
That function doesn't work, and the math is bad calculated, thanks for the idea, here is the update:

Code:
function isInArea(playerId, center, rangeX, rangeY)
    local player = Player(playerId)
 
    if not player then
        return false
    end
 
    local pos = player:getPosition()
    if (pos.x <= center.x+rangeX and pos.x >= center.x-rangeX) and (pos.y <= center.y+rangeY and pos.y >= center.y-rangeY) and (pos.z == center.z) then
        return true
    else
        return false
    end
end


@Xeraphus Thanks, but now I have to put all potions and runes on actions.xml and that that function to the regarding .lua files?

Also it is possible to set push time to 200 besides the config at config.lua only on this specific area? I mean using this onMove at events and checking if player is in area, then set time to move more quickly.
i tried doing the area push thing but storage works weird with printer's exhaust check, returns false 100% of the time so ill look into it later
Code:
function Player:isInArea(center, rangeX, rangeY)
    local pos = self:getPosition()
    return (pos.x >= center.x-rangeX and pos.x <= center.x+rangeX and pos.y >= center.y-rangeY and pos.y <= center.y+rangeY)
end
this works perfectly fine he just had a + instead of a - for the 1st center.y

edit: nevermind i got the push thing working
player lib
Code:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end

player events (onmovecreature)
Code:
local storage, time = 80005, 10
local pos = Position(1022, 1001, 7)

function Player:onMoveCreature(creature, fromPosition, toPosition)
    local player = creature:getPlayer()
    if player then
        if player:isInArea(pos, 3, 3) then
            if self:getExhaustion(storage) > 0 then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, 'You may not push players this fast.')
                return false
            end
            self:setExhaustion(storage, time)
        end
    end
    return true
end
 
i tried doing the area push thing but storage works weird with printer's exhaust check, returns false 100% of the time so ill look into it later
Code:
function Player:isInArea(center, rangeX, rangeY)
    local pos = self:getPosition()
    return (pos.x >= center.x-rangeX and pos.x <= center.x+rangeX and pos.y >= center.y-rangeY and pos.y <= center.y+rangeY)
end
this works perfectly fine he just had a + instead of a - for the 1st center.y

edit: nevermind i got the push thing working
player lib
Code:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end

player events (onmovecreature)
Code:
local storage, time = 80005, 10
local pos = Position(1022, 1001, 7)

function Player:onMoveCreature(creature, fromPosition, toPosition)
    local player = creature:getPlayer()
    if player then
        if player:isInArea(pos, 3, 3) then
            if self:getExhaustion(storage) > 0 then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, 'You may not push players this fast.')
                return false
            end
            self:setExhaustion(storage, time)
        end
    end
    return true
end
[/QUOTE

Oh yeah, managed to work, thanks!

But I explained myself bad... The idea is to control the time by pushing a creature :P
 
quite simple

data/lib/core/player.lua
Code:
function Player:isInArea(center, rangeX, rangeY)
    local spec = Game.getSpectators(center, false, true, rangeX, rangeX, rangeY, rangeY)
    if #spec > 0 then
        for i = 1, #spec do
            if spec[i] == self then
                return true
            end
        end
    end
    return false
end

action script
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isHotkey then
        if player:isInArea(Position(1022, 1001, 7), 3, 3) then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You may not use this on hotkey in this area.')
            return false
        end
    end
    return true
end

How to make this action script for every item on the game? Use fromid-toid in a huge range? xD
 
Hello,

It's best to add functionality in the code to disable player hotkey using ability and in LUA, so whenever the player enters or leaves a desired area like in the given examples, you can just call this LUA function to enable or disable the use of hotkeys for items.
 
Back
Top