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

Lua Xikini's Free Scripting Service TFS 1.4.2

  • Thread starter Thread starter Xikini
  • Start date Start date
Status
Not open for further replies.
X

Xikini

Guest
Request whatever you want, within reason.

Please do not request for things that require source editing or database queries.

------------------------------------
If I've reacted to your post, it means I've read it. 👍😍🤣😲🙁😡🤔😉

------------------------------------
Completed Requests

A boss that randomly creates effects on tiles, that when stepped on, gives the player increased damage/mitigation to that boss.
Kill monster and gain X% extra loot chance or Y% extra experience for Z minutes
A pack of 6 useful simple scripts.
-> (1) Simple quest npc
-> (2,3,4,5) use levers in specific order / stand with 4 players / use 4 objects / place items -> to open wall
-> (6) use lever to add/remove/replace objects
Wave type spell, with multiple effects
-> Same spell, but with default combat system
House market system. (owner places price on blackboard and object on the ground, other players buy with a lever)
Respawn System (closest anchor (like darks souls bonfire) / tavern / temple)
Vocation Death Protection (protect the noobs!)
Spell that shows area it will damage, before it strikes.
RAID SYSTEM - rebuilt in Lua, with some more features.
Modal Window - Teleport Item with saving/deleting of positions
Show top 3 Online Players (outfit, name, level) (as monsters, in set positions)
onLook function showing kill count of player.
Modal Window - Use Item -> choose reward.
Talkaction - !backpacks - to buy backpacks (or single items) anywhere. uses bank & current money on players
Quest/Event? Turn a bunch of objects with a monster, spawn portal.
Spawn Monsters, after they've all been killed, give global increased experience/loot in specific area's
Evolving Weapons - Kill X amount of specific creatures, evolve weapon and gain extra damage to those creatures.
Random Portals spawn at XX:XX time(s). (can exit 'off' portals, if you have the storage.)
Monster that adjusts speed based on target
Monster that increases damage output based on # of players nearby
Experience recovery Item. Die -> Use Item -> gain % of lost experience
Character Snapshot - Keeps track of all skills & level, for resetting later.
Fire Dagger - Physical Damage Melee Weapon, with % added damage
Players in specific level ranges don't lose skills/loot/experience, when they die.
Multiclient Limit Check - with admin account not being counted towards limit
Capacity Increasing Items
Upgradeable Protection Amulet - 10% to all elements
-> upgrade amulet, but for all items.
onKill - give reward to all players who dealt damage
-> example: give reward based on damage contribution
Quest Book - Record your quest progress into a book.
Stat System, using modal windows
Holy Tible (POI) - Require Item to use teleport tiles
Item Upgrade System
Skill Stages
-> individual stages for each skill type
-> talkaction to check rates (by @Extrodus)
Random Reward Item - gives different rewards based on vocation
Bounty Hunter System
NPC & Player Walk System (Follow Nodes to destination)
Health/Mana gain permanent - limited use items

------------------------------------
Support

If you have an issue with one of my scripts, I will attempt to help you, but not in this thread.
Make a thread in the support board.
Ensure to follow all rules of the support board.
Without all necessary information it's impossible to help you.

------------------------------------
I will only be scripting for TFS 1.4.2

Not TFS 1.1 / 1.2
Not OTServBR / OTX
and certainly not TFS 0.4

When requesting a script, don't ask for "this script I saw on super popular OT".

I don't care where the idea came from.
I don't want to see a video of the script in action.

Just describe what the script is supposed to do, and I'll try to make it.

Any script that I make in response to a request from this thread will be shared publicly, here, in this thread.

I'm not going to make anything in private, so post your request in this thread only.
Please, for the love of god, don't pm me asking to make a script.
I will actually add you to my ignore list if you do that.
--------------

Anyways!

Thanks for coming by and checking the thread out.
If you think there is a better way to script something, feel free to let me know.
I'm here to learn.

Cheers,

Xikini
---------

P.S.
I've been doing free scripting service's on/off for awhile.
And if you want to see the previous threads, go check them here.

 
Last edited by a moderator:
Base npc from here.

Modified, for your request.

Doubles sell price, if player is holding the special item.
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                    end

local specialTradeItem = 4444

local tradeList = {
    {id = 2470, buy = 0, sell = 15000, name = "golden legs"},
    {id = 2495, buy = 0, sell = 25000, name = "demon legs"},
    {id = 2195, buy = 0, sell = 15000, name = "boots of haste"},
    {id = 2645, buy = 0, sell = 15000, name = "steel boots"},
    {id = 2520, buy = 0, sell = 15000, name = "demon shield"},
    {id = 2514, buy = 0, sell = 25000, name = "mastermind shield"}
}

local function getTradeItems(t)
    local list, obj = {}
    for i = 1, #t do
        obj = t[i]
        list[obj.id] = {id = obj.id, buy = obj.buy, sell = obj.sell, name = ItemType(obj.id):getName():lower()}
    end
    return list
end

local function joinTables(old, new, mergeSameItems)
    for k, v in pairs(new) do
        if mergeSameItems then
            local found = false
            for _k, _v in pairs(old) do
                if v.id == _v.id then
                    found = true
                    if v.buy < _v.buy then
                        _v.buy = v.buy
                    end
                    if v.sell > _v.sell then
                        _v.sell = v.sell
                    end
                    break
                end
            end
            if not found then
                old[#old + 1] = v
            end
        else
            old[#old + 1] = v
        end
    end
    return old
end

local shopInfo = {
    --[cid] = "last known trade message"
}

local function createTradeInformation(cid, newMessage)
    if newMessage then
        shopInfo[cid] = newMessage
    end
    local lastKnownMessage = shopInfo[cid]
    local tradeItems = {}
  
    if not lastKnownMessage then
        return tradeItems
    end
  
    if lastKnownMessage == "regularTrade" then
        tradeItems = getTradeItems(tradeList)      
    end  
    return tradeItems
end

local function onBuy(player, itemid, subType, amount, ignoreCap, inBackpacks)
    local cid = player:getId()
    local shopInfo = createTradeInformation(cid)
    if not shopInfo[itemid] then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "No item selected?")
    end
  
    if not ignoreCap and player:getFreeCapacity() < ItemType(itemid):getWeight(amount) then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough capacity.")
    end
  
    local totalMoney = amount * shopInfo[itemid].buy
    if player:getTotalMoney() < totalMoney then  
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough money.")
    end
  
    player:removeTotalMoney(totalMoney)
    player:addItem(itemid, amount, true)
    return player:sendTextMessage(MESSAGE_INFO_DESCR, "Bought " .. amount .. "x " .. shopInfo[itemid].name .. " for " .. totalMoney .. " gold coins.")
end

local function onSell(player, itemid, subType, amount, ignoreCap, inBackpacks)
    local cid = player:getId()
    local shopInfo = createTradeInformation(cid)
    if not shopInfo[itemid] then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "No item selected?")
    end
  
    local hasSpecialItem = false
    local totalMoney = amount * shopInfo[itemid].sell
    if player:getItemCount(specialTradeItem) > 0 then
        totalMoney = totalMoney * 2
        hasSpecialItem = true
    end
 
    player:removeItem(itemid, amount)  
    player:addMoney(totalMoney)
    return player:sendTextMessage(MESSAGE_INFO_DESCR, "Sold " .. amount .. "x " .. shopInfo[itemid].name .. " for " .. totalMoney .. " gold coins." .. (hasSpecialItem and " (2x sell price)" or ""))
end

local function greetCallback(cid)
    local player = Player(cid)
    -- npcHandler:setMessage(MESSAGE_GREET, 'Welcome back old chap. What brings you here this time?')
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then return false end
  
    local player = Player(cid)
  
    if msgcontains("trade", msg) then
        local tradeItems = createTradeInformation(cid, "regularTrade")
        openShopWindow(cid, tradeItems, onBuy, onSell)
        npcHandler:say("If you have {valuable object} in your possession when selling items to me, I'll double the price!", cid)
      
    end  
    return true
end


-- npcHandler:setMessage(MESSAGE_FAREWELL, 'Happy hunting, old chap!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Nothing happens when I say, for example, 'sell golden legs'. I mention this because the script is for an 8.0 server where the dialogues are written, there is no 'trade'."
 
Nothing happens when I say, for example, 'sell golden legs'. I mention this because the script is for an 8.0 server where the dialogues are written, there is no 'trade'."
Untested.
Attempted to basically recreate the old way of trading.. 🤷‍♂️
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)         npcHandler:onCreatureAppear(cid)         end
function onCreatureDisappear(cid)      npcHandler:onCreatureDisappear(cid)      end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                     npcHandler:onThink()                     end

local shopInfo = {
    --[cid] = "last known trade message"
}

local specialTradeItem = 4444

local tradeList = {
    ["golden legs"]       = {id = 2470, buy = -1, sell = 15000}, -- -1 disables the buy/sell function for that item. 0 is free.
    ["demon legs"]        = {id = 2495, buy = -1, sell = 25000},
    ["boots of haste"]    = {id = 2195, buy = -1, sell = 15000},
    ["steel boots"]       = {id = 2645, buy = -1, sell = 15000},
    ["demon shield"]      = {id = 2520, buy = -1, sell = 15000},
    ["mastermind shield"] = {id = 2514, buy = -1, sell = 25000}
}

local function completeTrade(player, tradeType, tradeInfo)
    local itemName, itemPrice, itemId, amount = tradeInfo.name, tradeInfo.price, tradeInfo.id, tradeInfo.amount
    if tradeType == "buy" then
        if player:getFreeCapacity() < ItemType(itemId):getWeight(amount) then
            return "You don't have enough capacity."
        end
       
        local totalMoney = amount * itemPrice
        if player:getTotalMoney() < totalMoney then   
            return "You don't have enough money."
        end
       
        player:removeTotalMoney(totalMoney)
        player:addItem(itemid, amount, true)
        return "Bought " .. amount .. "x " .. itemName .. " for " .. totalMoney .. " gold coins."
       
    elseif tradeType == "sell" then
        local hasSpecialItem = false
        local totalMoney = amount * itemPrice
        if player:getItemCount(specialTradeItem) > 0 then
            totalMoney = totalMoney * 2
            hasSpecialItem = true
        end
       
        player:removeItem(itemId, amount)   
        player:addMoney(totalMoney)
        return "Sold " .. amount .. "x " .. itemName .. " for " .. totalMoney .. " gold coins." .. (hasSpecialItem and " (2x sell price)" or "")
       
    end
    return "Something is wrong. Contact admin."
end

local function parsePurchaseString(text)
    text = text:lower()
    local purchaseType, amount, itemName = string.match(text, "(%a+)%s*(%d*)%s*(.*)")
    purchaseType = purchaseType or ""
    amount = tonumber(amount) or 1
    itemName = itemName or ""
    return purchaseType, amount, itemName
end

local function greetCallback(cid)
    local player = Player(cid)
    shopInfo[cid] = nil
    npcHandler.topic[cid] = 0
    -- npcHandler:setMessage(MESSAGE_GREET, 'Welcome back old chap. What brings you here this time?')
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
   
    local player = Player(cid)
   
    local purchaseType, amount, itemName = parsePurchaseString(msg)
   
    if table.contains({"buy", "sell"}, purchaseType) then
        if tradeList[itemName] then
            local tradePrice = (purchaseType == "buy" and tradeList[itemName].buy or tradeList[itemName].sell)
            if tradePrice < 0 then
                return true
            end
            npcHandler:say("Would you like to " .. purchaseType .. " " .. amount .. " " .. itemName .. " for " .. (tradePrice * amount) .. "?", cid)
            shopInfo[cid] = msg
            npcHandler.topic[cid] = 1
        end
        return true
           
    elseif npcHandler.topic[cid] == 1 then
        npcHandler.topic[cid] = 0
        if not msgcontains(msg, "yes") then
            npcHandler:say("Another time then.", cid)
            return true
        end
        purchaseType, amount, itemName = parsePurchaseString(shopInfo[cid])
        local tradeResult = completeTrade(player, purchaseType, {name = itemName, price = (purchaseType == "buy" and tradeList[itemName].buy or tradeList[itemName].sell), id = tradeList[itemName].id, amount = amount})
        npcHandler:say(tradeResult, cid)
        return true
       
    end
   
    return true
end


-- npcHandler:setMessage(MESSAGE_FAREWELL, 'Happy hunting, old chap!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
What could be cool and would be really good for many people is a movement event script revscript based where people can regist their items there instead of movements.xml with a simple config?

LUA:
local config = {
    [2420] = {slot = CONST_SLOT_ARMOR, level = 1000} -- Item ID, Slot, Level required to use
}
 
What could be cool and would be really good for many people is a movement event script revscript based where people can regist their items there instead of movements.xml with a simple config?

LUA:
local config = {
    [2420] = {slot = CONST_SLOT_ARMOR, level = 1000} -- Item ID, Slot, Level required to use
}
Problem with this, is that when onEquip is triggered, the item is already equipped.
You're just dealing with the aftermath. you can't return false something that has already happened.

You could try to do all of that through onMoveItem or w/e it's called, but then you still have to deal with all the other forms of getting items.. like through npc's/quests/trading/any random script that adds items to the character, basically.

It's just not feasible currently, unless someone adds a function that precedes onEquip, that can return true/false.
But if you return false.. what then happens to the item? Just not created? Not traded? Dropped to the floor?

It's just a big mess. lmao
 
Não testado.
Tentou basicamente recriar a antiga maneira de negociar.🤷‍♂️
[código=lua]
palavra-chave localHandler = KeywordHandler:new()
npcHandler local = NpcHandler:novo(keywordHandler)
NpcSystem.parseParameters(npcHandler)

função onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) fim
função onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) fim
função onCreatureSay(cid, tipo, msg) npcHandler:onCreatureSay(cid, tipo, msg) fim
função onThink() npcHandler:onThink() fim

loja localInfo = {
--[cid] = "última mensagem comercial conhecida"
}

local especialTradeItem = 4444

lista de comércio local = {
["pernas douradas"] = {id = 2470, comprar = -1, vender = 15000}, -- -1 desabilita a função de compra/venda para aquele item. 0 é grátis.
["pernas de demônio"] = {id = 2495, comprar = -1, vender = 25000},
["botas de pressa"] = {id = 2195, comprar = -1, vender = 15000},
["botas de aço"] = {id = 2645, comprar = -1, vender = 15000},
["escudo demoníaco"] = {id = 2520, comprar = -1, vender = 15000},
["escudo do mestre"] = {id = 2514, comprar = -1, vender = 25000}
}

função local completeTrade(jogador, tradeType, tradeInfo)
itemName local, itemPrice, itemId, quantidade = tradeInfo.name, tradeInfo.price, tradeInfo.id, tradeInfo.amount
se tradeType == "comprar" então
se player:getFreeCapacity() < ItemType(itemId):getWeight(amount) então
retornar "Você não tem capacidade suficiente."
fim

totalMoney local = quantidade * itemPrice
se jogador:getTotalMoney() < totalMoney então
retornar "Você não tem dinheiro suficiente."
fim

jogador:removeTotalMoney(totalMoney)
jogador:addItem(itemid, quantidade, verdadeiro)
retornar "Comprado" .. quantidade .. "x" .. itemName .. " para " .. totalMoney .. " moedas de ouro."

elseif tradeType == "vender" então
local temItemEspecial = falso
totalMoney local = quantidade * itemPrice
se jogador:getItemCount(specialTradeItem) > 0 então
totalMoney = totalMoney * 2
hasSpecialItem = verdadeiro
fim

jogador:removeItem(itemId, quantidade)
jogador:addMoney(totalMoney)
retornar "Vendido" .. quantidade .. "x" .. itemName .. " para " .. totalMoney .. " moedas de ouro." .. (hasSpecialItem e " (2x preço de venda)" ou "")

fim
return "Algo está errado. Entre em contato com o administrador."
fim

função local parsePurchaseString(texto)
texto = texto:inferior()
local purchaseType, quantidade, itemName = string.match(texto, "(%a+)%s*(%d*)%s*(.*)")
purchaseType = purchaseType ou ""
quantidade = tonumber(quantidade) ou 1
itemName = itemName ou ""
devolver tipo de compra, valor, nome do item
fim

função local greetCallback(cid)
jogador local = Jogador(cid)
shopInfo[cid] = nulo
npcHandler.tópico[cid] = 0
-- npcHandler:setMessage(MESSAGE_GREET, 'Bem-vindo de volta, meu velho. O que o traz aqui desta vez?')
retornar verdadeiro
fim

função local criaturaSayCallback(cid, tipo, msg)
se não npcHandler:isFocused(cid) então
retornar falso
fim

jogador local = Jogador(cid)

local purchaseType, quantidade, itemName = parsePurchaseString(msg)

se table.contains({"comprar", "vender"}, purchaseType) então
se tradeList[itemName] então
local tradePrice = (purchaseType == "comprar" e tradeList[itemName].comprar ou tradeList[itemName].vender)
se tradePrice < 0 então
retornar verdadeiro
fim
npcHandler:say("Você gostaria de " .. purchaseType .. " " .. amount .. " " .. itemName .. " para " .. (tradePrice * amount) .. "?", cid)
lojaInfo[cid] = mensagem
npcHandler.tópico[cid] = 1
fim
retornar verdadeiro

elseif npcHandler.topic[cid] == 1 então
npcHandler.tópico[cid] = 0
se não msgcontains(msg, "sim") então
npcHandler:say("Outra hora então.", cid)
retornar verdadeiro
fim
purchaseType, quantidade, itemName = parsePurchaseString(shopInfo[cid])
local tradeResult = completeTrade(player, purchaseType, {name = itemName, price = (purchaseType == "buy" e tradeList[itemName].buy ou tradeList[itemName].sell), id = tradeList[itemName].id, amount = amount})
npcHandler:say(tradeResult, cid)
retornar verdadeiro

fim

retornar verdadeiro
fim


-- npcHandler:setMessage(MESSAGE_FAREWELL, 'Boa caça, meu velho!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, criaturaSayCallback)
npcHandler:addModule(FocusModule:new())
[/código]
Thank you very much, it worked perfectly.
 
A good old popular thing from old ots:

If you step on a ice ground as example: player will be pushed/tped in the direction he has been looking at till he reach a object and then the pushing/teleporting stops.

You can not move when you get pushed/tped

here a old thread of it:
 
A good old popular thing from old ots:

If you step on a ice ground as example: player will be pushed/tped in the direction he has been looking at till he reach a object and then the pushing/teleporting stops.

You can not move when you get pushed/tped

here a old thread of it:
What happens when a player goes diagonal on the tile?
or logs out while sliding? xD
 
What happens when a player goes diagonal on the tile?
or logs out while sliding?

Add condition in fight or something when he get pushed to avoid the log
about the diagonal on the tile.. Good question that's alredy to much for my brain :D
 
Hello, I need a script lottery scroll
chances of getting item or ded
Untested, cuz I don't have a server setup anymore, but should work.

data/scripts
LUA:
local lotteryScrollId = 1111
local deathChance = 10 -- percent
local lotteryItems = {
    {itemId = 1111, amount = 1},
    {itemId = 2222, amount = 1},
    {itemId = 3333, amount = 1}
}

local function youDedBro(playerId, percent)
    local player = Player(playerId)
    if not player then
        return
    end
  
    percent = percent + 1
  
    local deathMessages = {
        "death",
        "Death",
        "DEath",
        "DEAth",
        "DEATh",
        "DEATH"
    }
  
    local text = ""
    if percent <= #deathMessages then
        text = deathMessages[percent]
    else
        text = deathMessages[#deathMessages]
        for i = 1, (percent - #deathMessages) do
            text = text .. "."
        end
    end
    player:say(text, TALKTYPE_MONSTER_SAY)
    player:getPosition():sendMagicEffect(CONST_ME_MORTAREA)
  
    local damage = (player:getMaxHealth() / 100) * percent
    player:addHealth(-damage)
  
    addEvent(youDedBro, 500, playerId, percent)
end

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    item:remove(1)
    if math.random(100) <= deathChance then
        youDedBro(player:getId(), 0)
        return true
    end
    local rand = math.random(#lotteryItems)
    player:addItem(lotteryItems[rand].itemId, lotteryItems[rand].amount, true)
    player:say("Congratulations!", TALKTYPE_MONSTER_SAY)
    player:getPosition():sendMagicEffect(CONST_ME_SOUND_PURPLE)
    return true
end

action:id(lotteryScrollId)
action:register()
 
Last edited by a moderator:
Untested, cuz I don't have a server setup anymore, but should work.

data/scripts
LUA:
local lotteryScrollId = 1111
local deathChance = 10 -- percent
local lotteryItems = {
    {itemId = 1111, amount = 1},
    {itemId = 2222, amount = 1},
    {itemId = 3333, amount = 1}
}

local function youDedBro(playerId, percent)
    local player = Player(playerId)
    if not player then
        return
    end
 
    percent = percent + 1
 
    local deathMessages = {
        "death",
        "Death",
        "DEath",
        "DEAth",
        "DEATh",
        "DEATH"
    }
 
    local text = ""
    if percent <= #deathMessages then
        text = deathMessages[percent]
    else
        text = deathMessages[#deathMessages]
        for i = 1, (percent - #deathMessages) do
            text = text .. "."
        end
    end
    player:say(text, TALKTYPE_MONSTER_SAY)
    player:getPosition():sendMagicEffect(CONST_ME_MORTAREA)
 
    local damage = (player:getMaxHealth() / 100) * percent
    player:addHealth(-damage)
 
    addEvent(youDedBro, 500, playerId, percent)
end

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    item:remove(1)
    if math.random(100) <= deathChance then
        youDedBro(player:getId(), 0)
        return true
    end
    local rand = math.random(#lotteryItems)
    player:addItem(lotteryItems[rand].itemId, lotteryItems[rand].amount, true)
    player:say("Congratulations!", TALKTYPE_MONSTER_SAY)
    player:getPosition():sendMagicEffect(CONST_ME_SOUND_PURPLE)
    return true
end

action:id(lotteryScrollId)
action:register()
Thank you very much, it worked perfectly.
<3 <3
 
Just like the old system
It is possible to change gold to itemid or
gold+itemid[token] = item
LUA:
local shopToken = 1111
local lever = {left = 1945, right = 1946}

local shopLevers = {
--  [actionid] = {gold and token cost, item recieved}
    [45001] = {gold = 10000, tokens = 1, itemId = 1111, amount = 1},
    [45002] = {gold = 10000, tokens = 1, itemId = 1111, amount = 1},
    [45003] = {gold = 10000, tokens = 1, itemId = 1111, amount = 1}
}

local function resetLever(position)
    Tile(position):getItemById(lever.right):transform(lever.left)
end

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() ~= lever.left then
        toPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    
    local shop = shopLevers[item:getActionId()]
    
    if player:getItemCount(shopToken) < shop.tokens or player:getTotalMoney() < shop.gold then
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        local cost = ""
        if shop.gold > 0 then
            cost = shop.gold .. " gold coins"
        end
        if shop.tokens > 0 then
            if cost ~= "" then
                cost = cost .. " and "
            end
            cost = cost .. shop.tokens .. " shop tokens" 
        end
        player:say("Costs\n" .. cost, TALKTYPE_MONSTER_SAY, false, player, toPosition)
        return true
    end
    
    if shop.tokens > 0 then
        player:removeItem(shopToken, shop.tokens)
    end
    if shop.gold > 0 then
        player:removeTotalMoney(shop.gold)
    end
    
    item:transform(lever.right)
    addEvent(resetLever, 1500, toPosition)
    toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    
    player:addItem(shop.itemId, shop.amount, true)
    return true
end

for actionId, _ in pairs(shopLevers) do
    action:aid(actionId)
end
action:register()
 
Last edited by a moderator:
LUA:
local shopToken = 1111
local lever = {left = 1945, right = 1946}

local shopLevers = {
--  [actionid] = {gold and token cost, item recieved}
    [45001] = {gold = 10000, tokens = 1, itemId = 1111, amount = 1},
    [45002] = {gold = 10000, tokens = 1, itemId = 1111, amount = 1},
    [45003] = {gold = 10000, tokens = 1, itemId = 1111, amount = 1}
}

local function resetLever(position)
    Tile(position):getItemById(lever.right):transform(lever.left)
end

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() ~= lever.left then
        toPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
   
    local shop = shopLevers[item:getActionId()]
   
    if player:getItemCount(shopToken) < shop.tokens or player:getTotalMoney() < shop.gold then
        toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
        local cost = ""
        if shop.gold > 0 then
            cost = shop.gold .. " gold coins"
        end
        if shop.tokens > 0 then
            if cost ~= "" then
                cost = cost .. " and "
            end
            cost = cost .. shop.tokens .. " shop tokens"
        end
        player:say("Costs\n" .. cost, TALKTYPE_MONSTER_SAY, false, player, toPosition)
        return true
    end
   
    if shop.tokens > 0 then
        player:removeItem(shopToken, shop.tokens)
    end
    if shop.gold > 0 then
        player:removeTotalMoney(shop.gold)
    end
   
    item:transform(lever.right)
    addEvent(resetLever, 1500, toPosition)
    toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
   
    player:addItem(shop.itemId, shop.amount, true)
    return true
end

for actionId, _ in pairs(shopLevers) do
    action:aid(actionId)
end
action:register()
man, it works perfectly, thanks :)!!
Post automatically merged:

Untested, cuz I don't have a server setup anymore, but should work.

data/scripts
LUA:
local lotteryScrollId = 1111
local deathChance = 10 -- percent
local lotteryItems = {
    {itemId = 1111, amount = 1},
    {itemId = 2222, amount = 1},
    {itemId = 3333, amount = 1}
}

local function youDedBro(playerId, percent)
    local player = Player(playerId)
    if not player then
        return
    end
 
    percent = percent + 1
 
    local deathMessages = {
        "death",
        "Death",
        "DEath",
        "DEAth",
        "DEATh",
        "DEATH"
    }
 
    local text = ""
    if percent <= #deathMessages then
        text = deathMessages[percent]
    else
        text = deathMessages[#deathMessages]
        for i = 1, (percent - #deathMessages) do
            text = text .. "."
        end
    end
    player:say(text, TALKTYPE_MONSTER_SAY)
    player:getPosition():sendMagicEffect(CONST_ME_MORTAREA)
 
    local damage = (player:getMaxHealth() / 100) * percent
    player:addHealth(-damage)
 
    addEvent(youDedBro, 500, playerId, percent)
end

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    item:remove(1)
    if math.random(100) <= deathChance then
        youDedBro(player:getId(), 0)
        return true
    end
    local rand = math.random(#lotteryItems)
    player:addItem(lotteryItems[rand].itemId, lotteryItems[rand].amount, true)
    player:say("Congratulations!", TALKTYPE_MONSTER_SAY)
    player:getPosition():sendMagicEffect(CONST_ME_SOUND_PURPLE)
    return true
end

action:id(lotteryScrollId)
action:register()
when the character logs out, he avoids death
the question is whether it is possible to add protection against logging out?
 
Last edited:
man, it works perfectly, thanks :)!!
Post automatically merged:


when the character logs out, he avoids death
the question is whether it is possible to add protection against logging out?
Non-logout tiles in remeres.. Or give the character a battle sign?

Depends on situation.
 
Hello Xikini!

I have TFS 1.4.2 and otcv8.

I saw that it is possible to make the loot appear on the screen in different colors (e.g. golder helmet in red and fire sword in green). There are scripts that require you to add everything manually, but apparently the best scripters can write a specific script that counts the rarity of items in the store and gives them a color = value. Could you do something like that?

I will really be grateful to you! :)
 
Status
Not open for further replies.
Back
Top