• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua help with my rope script

gubbo123

New Member
Joined
Aug 15, 2017
Messages
145
Solutions
1
Reaction score
3
My script
Lua:
local ropeSpots = {
    386, 421
}
 
local holeSpots = {
    293, 294, 369, 370, 385, 394, 411, 412,
    421, 432, 433, 435, 482, 5081, 483, 594,
    595, 607, 609, 610, 615, 1066, 1067, 1080
}
 
function onUse(player, item, fromPosition, target, toPosition)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    if not target:isItem() then
        return false
    end
  
    if target:getId() >= 2886 and target:getId() <= 2891 or target:getId() == 2895 then
        target = tile:getGround()
    end
  
    if table.contains(ropeSpots, target:getId()) then
        player:teleportTo(target:getPosition():moveRel(0, 1, -1))
        return true
    elseif table.contains(holeSpots, target:getId()) or target:getId() == 435 then
        local tile = Tile(target:getPosition():moveRel(0, 0, 1))
        if not tile then
            return false
        end
      
        local thing = tile:getTopCreature()
        if not thing then
            thing = tile:getTopVisibleThing()
        end
      
        if thing:isCreature() then
            thing:teleportTo(target:getPosition():moveRel(0, 1, 0), false)
            return true
        end
        if thing:isItem() and thing:getType():isMovable() then
            thing:moveTo(target:getPosition():moveRel(0, 1, 0))
            return true
        end
        return true
    end
    return false
end

how can a 3 second temporary storage be added when the player uses the rope and after 3 seconds the storage will be changed to another one?
storage when use the rope 500,1 after 3 seconds 500,0

Thanks in advance
 
Solution
You'll need to create a login script as well, to reset the storage to 0, in case the player dies / logout before the storage resets.

inside your onUse function (wherever you want the storage to be added and then reset)
Lua:
player:setStorageValue(500, 1)
addEvent(resetStorage, 3000, player:getId(), 500, 0)
above your onUse function
Lua:
local function resetStorage(playerId, storageKey, storageValue)
    local player = Player(playerId)
    if not player then
        return
    end
    player:setStorageValue(storageKey, storageValue)
    return
end
login code
Lua:
function onLogin(player)
    if player:getStorageValue(500) == 1 then
        player:setStorageValue(500, 0)
    end
    return true
end

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,482
You'll need to create a login script as well, to reset the storage to 0, in case the player dies / logout before the storage resets.

inside your onUse function (wherever you want the storage to be added and then reset)
Lua:
player:setStorageValue(500, 1)
addEvent(resetStorage, 3000, player:getId(), 500, 0)
above your onUse function
Lua:
local function resetStorage(playerId, storageKey, storageValue)
    local player = Player(playerId)
    if not player then
        return
    end
    player:setStorageValue(storageKey, storageValue)
    return
end
login code
Lua:
function onLogin(player)
    if player:getStorageValue(500) == 1 then
        player:setStorageValue(500, 0)
    end
    return true
end
 
Solution
OP
OP
G

gubbo123

New Member
Joined
Aug 15, 2017
Messages
145
Solutions
1
Reaction score
3
thanks for replying but i need something i don't need to log in again to change

I thought it could be used in the function something like os.time()
something like this
player:setStorageValue(500,1, os.time() + 3000)
then
if os.time() >
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,482
thanks for replying but i need something i don't need to log in again to change
You don't need to log in again to change..?
Did you even read my post?
You'll need to create a login script as well, to reset the storage to 0, in case the player dies / logout before the storage resets.

I thought it could be used in the function something like os.time()
something like this
player:setStorageValue(500,1, os.time() + 3000)
then
if os.time() >
Assuming the situation you are wanting to create can use that method, you can use this method.
But because you gave us no information about what you are actually trying to do, I have no idea if that method is even useable in this scenario.
 
OP
OP
G

gubbo123

New Member
Joined
Aug 15, 2017
Messages
145
Solutions
1
Reaction score
3
You don't need to log in again to change..?
Did you even read my post?



Assuming the situation you are wanting to create can use that method, you can use this method.
But because you gave us no information about what you are actually trying to do, I have no idea if that method is even useable in this scenario.
I'm creating a quest that the player needs to use the rope and in less than 3 seconds can open a door
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,482
I'm creating a quest that the player needs to use the rope and in less than 3 seconds can open a door
What is the rope being used on to trigger the storage?

A specific itemId?
A specific position?
An item with a uniqueId or actionId?
A specific monster/npc/player?

anyway, both my posted method and os.time() method can be used here.
Arguably my posted method is better suited for this situation, since you won't need to edit doors.lua
 
OP
OP
G

gubbo123

New Member
Joined
Aug 15, 2017
Messages
145
Solutions
1
Reaction score
3
What is the rope being used on to trigger the storage?
A specific itemId?
A specific position?
An item with a uniqueId or actionId?
A specific monster/npc/player?

anyway, both my posted method and os.time() method can be used here.
Arguably my posted method is better suited for this situation, since you won't need to edit doors.lua
yes I understood

thank you very much, it worked
 
Top