• 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!

RevScripts set to charge

pisquila

New Member
Joined
Nov 14, 2023
Messages
28
Reaction score
3
set to charge item when pulling the lever
item: 2160 / quantity 70



local config = {
daily = "yes", -- allow only one enter per day? (like in global Tibia)
level = 500,
storage = 30015,
entry =
{
{x = 319, y = 669, z = 7},
{x = 319, y = 668, z = 7},
{x = 319, y = 667, z = 7},
{x = 319, y = 666, z = 7}
},
destination =
{
{x = 276, y = 653, z = 7},
{x = 276, y = 653, z = 7},
{x = 276, y = 653, z = 7},
{x = 276, y = 653, z = 7}
}
}

config.daily = getBooleanFromString(config.daily)
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(item.itemid == 1946) then
if(config.daily) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
else
doTransformItem(item.uid, item.itemid - 1)
end

return true
end

if(item.itemid ~= 1945) then
return true
end

local players = {}
for _, position in ipairs(config.entry) do
local pid = getTopCreature(position).uid
if(pid == 0 or not isPlayer(pid) or getCreatureStorage(pid, config.storage) > 0 or getPlayerLevel(pid) < config.level) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
return true
end

table.insert(players, pid)
end

for i, pid in ipairs(players) do
doSendMagicEffect(config.entry, CONST_ME_POFF)
doTeleportThing(pid, config.destination, false)
doSendMagicEffect(config.destination, CONST_ME_ENERGYAREA)
end

doTransformItem(item.uid, item.itemid + 1)
return true
end
 
set to charge item when pulling the lever
item: 2160 / quantity 70
LUA:
local config = {
    daily = true,
    level = 500,
    storage = 30015,
    itemId = 2160,
    itemCount = 70,
    entry = {x = 319, y = 669, z = 7},
    destination = {x = 276, y = 653, z = 7}
}

local leverAction = Action()

function leverAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() == 1946 then
        if config.daily then
            player:sendCancelMessage("This lever cannot be used in this state.")
            return true
        else
            item:transform(item:getId() - 1)
            return true
        end
    end

    if item:getId() ~= 1945 then
        return true
    end

    local playerPos = player:getPosition()
    if playerPos.x ~= config.entry.x or playerPos.y ~= config.entry.y or playerPos.z ~= config.entry.z then
        player:sendCancelMessage("You must stand at the correct position.")
        return true
    end

    if player:getLevel() < config.level then
        player:sendCancelMessage("You need to be at least level " .. config.level .. ".")
        return true
    end

    if config.daily and player:getStorageValue(config.storage) > 0 then
        player:sendCancelMessage("You can only enter once per day.")
        return true
    end

    if player:getItemCount(config.itemId) < config.itemCount then
        player:sendCancelMessage("You need " .. config.itemCount .. " Crystal Coins to use this lever.")
        return true
    end

    if not player:removeItem(config.itemId, config.itemCount) then
        player:sendCancelMessage("Failed to remove the required items.")
        return true
    end

    if config.daily then
        player:setStorageValue(config.storage, 1)
    end

    Position(config.entry):sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(config.destination)
    Position(config.destination):sendMagicEffect(CONST_ME_ENERGYAREA)

    item:transform(item:getId() + 1)

    return true
end

leverAction:id(1945, 1946)
leverAction:register()
 
only the player who pulls the lever



LUA:
local config = {
    daily = "yes",
    level = 500,
    storage = 30015,
    entry = {
        {x = 319, y = 669, z = 7},
        {x = 319, y = 668, z = 7},
        {x = 319, y = 667, z = 7},
        {x = 319, y = 666, z = 7}
    },
    destination = {
        {x = 276, y = 653, z = 7},
        {x = 276, y = 653, z = 7},
        {x = 276, y = 653, z = 7},
        {x = 276, y = 653, z = 7}
    },
    requiredItem = 2160,
    requiredCount = 70
}

config.daily = getBooleanFromString(config.daily)

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1946 then
        if config.daily then
            doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        else
            doTransformItem(item.uid, item.itemid - 1)
        end
        return true
    end

    if item.itemid ~= 1945 then
        return true
    end

    if getPlayerItemCount(cid, config.requiredItem) < config.requiredCount then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "NEED "..config.requiredCount.." CC FOR PULL .")
        return true
    end

    local players = {}
    for _, position in ipairs(config.entry) do
        local pid = getTopCreature(position).uid
        if pid == 0 or not isPlayer(pid) or getCreatureStorage(pid, config.storage) > 0 or getPlayerLevel(pid) < config.level then
            doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
            return true
        end
        table.insert(players, pid)
    end

    doPlayerRemoveItem(cid, config.requiredItem, config.requiredCount)

    for i, pid in ipairs(players) do
        doSendMagicEffect(config.entry[i], CONST_ME_POFF)
        doTeleportThing(pid, config.destination[i], false)
        doSendMagicEffect(config.destination[i], CONST_ME_ENERGYAREA)
    end

    doTransformItem(item.uid, item.itemid + 1)
    return true
end
Post automatically merged:

If you are using TFS 1.X+, I recommend trying the other code. Not mine.
 

Similar threads

Back
Top