Resources Scripts

Scripts for OTS activity. Mods, Events, Actions, Spells, Monsters,NPC.. written in Lua, XML and engine scripts in C++ too

1k
0

How Looks commands in game:
!autoloot add, itemId or name
!autoloot remove, itemId or name
!autoloot show
!autoloot clear

Add code to data/global.lua

-- AutoLoot config
    AUTO_LOOT_MAX_ITEMS = 5

    -- Reserved storage
    AUTOLOOT_STORAGE_START = 10000
    AUTOLOOT_STORAGE_END = AUTOLOOT_STORAGE_START + AUTO_LOOT_MAX_ITEMS
-- AutoLoot config end

Add code to talkactions/talkactions.xml

<talkaction words="!autoloot" separator=" " script="autoloot.lua"/>

Make file in talkactions/scripts called autoloot.lua and paste

function onSay(player, words, param)
    local split = param:split(",")

    local action = split[1]
    if action == "add" then
        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        if itemType:getId() == 0 then
            itemType = ItemType(tonumber(item))
            if itemType:getId() == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no item with that id or name.")
                return false
            end
        end

        local itemName = tonumber(split[2]) and itemType:getName() or item
        local size = 0
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            local storage = player:getStorageValue(i)
            if size == AUTO_LOOT_MAX_ITEMS then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The list is full, please remove from the list to make some room.")
                break
            end

            if storage == itemType:getId() then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." is already in the list.")
                break
            end

            if storage <= 0 then
                player:setStorageValue(i, itemType:getId())
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." has been added to the list.")
                break
            end

            size = size + 1
        end
    elseif action == "remove" then
        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        if itemType:getId() == 0 then
            itemType = ItemType(tonumber(item))
            if itemType:getId() == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no item with that id or name.")
                return false
            end
        end

        local itemName = tonumber(split[2]) and itemType:getName() or item
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            if player:getStorageValue(i) == itemType:getId() then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." has been removed from the list.")
                player:setStorageValue(i, 0)
                return false
            end
        end

        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." was not founded in the list.")
    elseif action == "show" then
        local text = "-- Auto Loot List --\n"
        local count = 1
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            local storage = player:getStorageValue(i)
            if storage > 0 then
                text = string.format("%s%d. %s\n", text, count, ItemType(storage):getName())
                count = count + 1
            end
        end

        if text == "" then
            text = "Empty"
        end

        player:showTextDialog(1950, text, false)
    elseif action == "clear" then
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            player:setStorageValue(i, 0)
        end

        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The autoloot list has been cleared.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Use the commands: !autoloot {add, remove, show, clear}")
    end

    return false
end

Add to creaturescripts/creaturescripts.xml

<event type="kill" name="AutoLoot" script="autoloot.lua" />

Create new file in creaturescripts/scripts called autoloot.lua and paste

local function scanContainer(cid, position)
    local player = Player(cid)
    if not player then
        return
    end

    local corpse = Tile(position):getTopDownItem()
    if not corpse then
        return
    end

    if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
        for a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            if containerItem then
                for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(b) == containerItem:getId() then
                        containerItem:moveTo(player)
                    end
                end
            end
        end
    end
end

function onKill(player, target)
    if not target:isMonster() then
        return true
    end

    addEvent(scanContainer, 100, player:getId(), target:getPosition())
    return true
end

Go to creaturescripts/scripts/login.lua and save

player:registerEvent("AutoLoot")

211
0
misiu posted Jan 6 '16 at 11:20 pm

This script adds the addon to the player in exchange for an item.

To install go to the folder OTFolder/data/talkactions/scripts, create a .lua file (addondoll.lua) and put this:

function onSay(player, words, param)

    local outfits =
    {
        --[outfit] = {id_female, id_male}
        ["citizen"] = {136, 128},
        ["hunter"] = {137, 129},
        ["mage"] = {138, 130},
        ["knight"] = {139, 131},
        ["noblewoman"] = {140, 132},
        ["summoner"] = {141, 133},
        ["warrior"] = {142, 134},
        ["barbarian"] = {147, 143},
        ["druid"] = {148, 144},
        ["wizard"] = {149, 145},
        ["oriental"] = {150, 146},
        ["pirate"] = {155, 151},
        ["assassin"] = {156, 152},
        ["beggar"] = {157, 153},
        ["shaman"] = {158, 154},
        ["norsewoman"] = {252, 251},
        ["nightmare"] = {269, 268},
        ["jester"] = {270, 273},
        ["brotherhood"] = {279, 278},
        ["demonhunter"] = {288, 289},
        ["yalaharian"] = {324, 325},
        ["warmaster"] = {336, 335},
        ["wayfarer"] = {366, 367},
        ["afflicted"] = {431, 430},
        ["elementalist"] = {433, 432},
        ["deepling"] = {464, 463},
        ["insectoid"] = {466, 465},
        ["red baron"] = {471, 472},
        ["crystal warlord"] = {513, 512},
        ["soil guardian"] = {514, 516},
        ["demon"] = {542, 541}
    }

    local param = string.lower(param)
    local addondoll_id = 9693

    if player:getItemCount(addondoll_id) > 0 then
        if param ~= "" and outfits[param] then
            if (not player:hasOutfit(outfits[param][1], 3)) or (not player:hasOutfit(outfits[param][2], 3)) then
                player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
                player:removeItem(addondoll_id, 1)
                player:addOutfitAddon(outfits[param][1], 3)
                player:addOutfitAddon(outfits[param][2], 3)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Seu Addon full foi adicionado!")
            else
                player:sendCancelMessage("Voce ja tem este addon")
            end
        else
            player:sendCancelMessage("Digite novamente, algo esta errado!")
        end
    else
        player:sendCancelMessage("Voce nao tem addon doll!")
    end

    return true
end

After adding the script, go OTFolder/data/talkactions, in the file talkactions.xml, add:

<talkaction words="!addon" script="addondoll.lua"/>

Set the addondoll ID in:

local addondoll_id = 9693
129
0
Mariola posted Dec 22 '15 at 9:32 pm

paste this script here
data/npcs/scripts/BlessMan.lua

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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
function onPlayerEndTrade(cid)                npcHandler:onPlayerEndTrade(cid)            end
function onPlayerCloseChannel(cid)            npcHandler:onPlayerCloseChannel(cid)        end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = cid
    local p = Player(cid)
    local heal = false
    local hp = p:getHealth()

    if msgcontains(msg, "heal") then
        if getCreatureCondition(cid, CONDITION_FIRE) then
            selfSay("You are burning. I will help you.", cid)
            doRemoveCondition(cid, CONDITION_FIRE)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_POISON) then
            selfSay("You are poisoned. I will cure you.", cid)
            doRemoveCondition(cid, CONDITION_POISON)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_ENERGY) then
            selfSay("You are electrificed. I will help you.", cid)
            doRemoveCondition(cid, CONDITION_ENERGY)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_PARALYZE) then
            selfSay("You are paralyzed. I will cure you.", cid)
            doRemoveCondition(cid, CONDITION_PARALYZE)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_DROWN) then
            selfSay("You are drowing. I will help you.", cid)
            doRemoveCondition(cid, CONDITION_DROWN)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_FREEZING) then
            selfSay("You are cold! I will help you.", cid)
            doRemoveCondition(cid, CONDITION_FREEZING)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_BLEEDING) then
            selfSay("You are bleeding! I will help you.", cid)
            doRemoveCondition(cid, CONDITION_BLEEDING)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_DAZZLED) then
            selfSay("You are dazzled! Do not mess with holy creatures anymore!", cid)
            doRemoveCondition(cid, CONDITION_DAZZLED)
            heal = true
        elseif getCreatureCondition(cid, CONDITION_CURSED) then
            selfSay("You are cursed! I will remove it.", cid)
            doRemoveCondition(cid, CONDITION_CURSED)
            heal = true
        elseif hp < 65 then
            selfSay("You are looking really bad. Let me heal your wounds.", cid)
            p:addHealth(65 - hp)
            heal = true
        elseif hp < 2000 then
            selfSay("I did my best to fix your wounds.", cid)
            p:addHealth(2000 - hp)
            heal = true
        end

        if heal then
            p:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        else
            local msgheal = {
                "You aren't looking really bad, " .. getCreatureName(cid) .. ". I only help in cases of real emergencies. Raise your health simply by eating {food}.", 
                "Seriously? It's just a scratch", 
                "Don't be a child. You don't need any help with your health.", 
                "I'm not an expert. If you need help find a medic.", 
                "Don't even waste my time, I have bigger problems than your scratched armor."
            }
            selfSay("" .. msgheal[math.random(1, #msgheal)] .. "", cid)
        end
    return true
    end

    if msgcontains(msg, "yes") and talkState[talkUser] > 90 and talkState[talkUser] < 96 then
        if getPlayerBlessing(cid, talkState[talkUser] - 90) then
            selfSay("You already have this blessing!", cid)
        else
            b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
            if b_price < 2000 then b_price = 2000 end

            if doPlayerRemoveMoney(cid, b_price) then
                selfSay("You have been blessed by one of the five gods!", cid)
                doPlayerAddBlessing(cid, talkState[talkUser] - 90)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
            else
                selfSay("I'm sorry. We need money to keep this temple up.", cid)
            end
        end
        talkState[talkUser] = 0
        return true
    end

    if msgcontains(msg, "yes") and talkState[talkUser] == 96 then
        havebless = {}

        for i = 1, 5 do
            if(getPlayerBlessing(cid, i)) then
                table.insert(havebless,i)
            end
        end

        if #havebless == 5 then
            selfSay('You already have all available blessings.',cid)
            talkState[talkUser] = 0
            return true
        end

        b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
        if b_price < 2000 then b_price = 2000 end
        b_price = ((5 - #havebless) * b_price)

        if doPlayerRemoveMoney(cid, b_price) then
            selfSay("You have been blessed by the five gods!", cid)
            for i = 1, 5 do doPlayerAddBlessing(cid, i) end
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        else
            selfSay("I'm sorry. We need money to keep this temple up.", cid)
        end

        talkState[talkUser] = 0
        return true
    end

    if msgcontains(msg, "all") then
        havebless = {}
        b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
        if b_price < 2000 then b_price = 2000 end

        for i = 1, 5 do
            if(getPlayerBlessing(cid, i)) then
                table.insert(havebless,i)
            end
        end

        b_price = ((5 - #havebless) * b_price)

        if b_price == 0 then
            selfSay('You already have all available blessings.',cid)
            talkState[talkUser] = 0
            return true
        end

        selfSay('Do you want to receive all blessings for ' .. b_price .. ' gold?',cid)
        talkState[talkUser] = 96
        return true
    end

    local blesskeywords = {'wisdom', 'spark', 'fire', 'spiritual', 'embrace'}
    local blessnames = {'Wisdom of Solitude', 'Spark of The Phoenix', 'Fire of Two Suns', 'Spiritual Shielding', 'The Embrace'}
    for i = 1, #blesskeywords do
        if msgcontains(msg, blesskeywords[i]) then

            b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
            if b_price < 2000 then b_price = 2000 end

            selfSay('Do you want me to grant you ' .. blessnames[i] .. ' blessing for ' .. b_price .. ' gold?',cid)
            talkState[talkUser] = 90 + i
            return true
        end
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
data/npcs/BlessMan.xml
<?xml version="1.0" encoding="UTF-8"?>
    <npc name="Willian" script="BlessMan.lua" walkinterval="2000" floorchange="0" speechbubble="1">
    <health now="100" max="100"/>
    <look type="134" head="58" body="114" legs="87" addons="3"/>
    <parameters>
        <parameter key="module_keywords" value="1" />
        <parameter key="keywords" value="bless;blessings" />
        <parameter key="keyword_reply1" value="I can grant you blessings such as {Wisdom} {of} {Solitude}, {Spark} {of} {The} {Phoenix}, our {Fire} {of} {Two} {Suns}, {Spiritual} {Shielding} and {The Embrace}. I can also grant you {all} of these blessings, just ask me." />
        <parameter key="keyword_reply2" value="I can grant you blessings such as {Wisdom} {of} {Solitude}, {Spark} {of} {The} {Phoenix}, our {Fire} {of} {Two} {Suns}, {Spiritual} {Shielding} and {The Embrace}. I can also grant you {all} of these blessings, just ask me." />
    </parameters>
</npc>
3
3
0
Actions
Hide topic messages
Enable infinite scrolling
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft