• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action [MOD]Alchemy System - New UPDATE!

Shinmaru

エロルアー Scripter!
Joined
Aug 20, 2007
Messages
1,988
Reaction score
88
Location
Puerto Rico
[MOD]Alchemy System - Update- MOD v3.0, NPC v2.0! 9-25-2010

Update Date: September 25, 2010
Update By: soul4soul!
Announcement: As of today all reps for this script goes to soul4soul for keeping this updated and fixed, so please rep him if you haven't, I've been unable to keep it updated, due to I been working IRL and working with a small project.
[Recognitions and Creator Details = Start]
Creator's Script Full Name: Alchemy System
Idea by:Whiskey - For the whole Idea
Functions by:Athern
Original Creator (Version 1):Shinmaru
(Version 1.1):Soul4Soul --Created the MOD. Made the whole MOD use only one table.
NPC Version 1:Shinmaru
(Version 2):Shinmaru and Soul4Soul --Movevent and One Config Alchemy List
NPC Version 1.5:Shinmaru and Soul4Soul --Shortened bug fixes, Little Touch ups
NPC version 2:Soul4Soul --Reorganized and Shortened
(Version 3):Soul4Soul --Functions moved to MOD, stacked items, Shortened Main script (1 For instead of 8 Ifs), new destroy option, removed the double window pop up on the recipe book.
Current(Version 4):Soul4Soul --Better recipe book and design, fixed the random starting comma also shows the recipe difficulty.
Alchemy leveling is 100% fixed.
Highscore book displays the top players with the top skills.
[Recognitions and Creator Details = End]

alchd.png


[Install [Alchemy NPC 0.3.6] = Start]
Script Name: alchemyNPC.lua
Type: NPC
Lua Location: data/npc/scripts/
Lua Code:
Lua:
local focus = 0
local talk_start = 0

function onCreatureDisappear(cid, pos)
        if focus == cid then
                selfSay('Good bye then.')
                focus = 0
                talk_start = 0
        end
end

function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
msg = string.lower(msg)

        if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
                selfSay('Hello ' .. getCreatureName(cid) .. '! I sell all things related to "alchemy".')
                focus = cid
                talk_start = os.clock()

        elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
                selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')

        elseif focus == cid then
                talk_start = os.clock()

                if msgcontains(msg, 'alchemy') then
                                selfSay('Ahh, yes I have "recipes", "recipe book", and "alchemic kits" , for sale which do you want to know more about?')
                                talk_state = 1

                elseif talk_state == 1 then
                        if msgcontains(msg, 'recipe book') then
                                        price = 1000
                                        selfSay('I have this recipe book that you can use to see the recipes you have learned, do you want to buy it for '.. price ..' gold?')
                                        talk_state = 4
                                        item = 1965
                                        rtrn = 1
                        elseif msgcontains(msg, 'recipes') then
                                if getPlayerStorageValue(cid, 50500) == -1 then
                                        selfSay('You don\'t seem to know much about alchemy go study first.')
                                        talk_state = 1
                                else
                                        selfSay('Yes, I have a list of recipes for "beginner" and "advanced" Alchemists, which would you like to see?.')
                                        talk_state = 2
                                end
                        elseif msgcontains(msg, 'alchemic kit') then
                                        price = 10000
                                        selfSay('This is a special kit used just for alchemy, would you like to buy it for '.. price ..' gold?.')
                                        talk_state = 4
                                        item = 6104
                                        rtrn = 1
                        elseif msgcontains(msg, 'bye') then
                                selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
                                focus = 0
                                talk_start = 0 
                        end    
                elseif talk_state == 2 then
                        if msgcontains(msg, 'beginner') then
                                selfSay('At the beginner level I sell recipes for: "antidote", "platinum coin", "mind stone", "soul orb", "blood orb", "love potion", "ectoplasm", "weak mana rune", "crystal coin", "sparkling mummy doll". which one do you want?')
                                talk_state = 3
                        elseif msgcontains(msg, 'advanced') then
                                selfSay('At the Advanced level I sell recipes for: "berserk potion", "mastermind potion", "bullseye potion", "mead horn", "gold bar", "mana rune", "clover amulet", "sword", "magic", "arrow". which one do you want?')
                                talk_state = 3
                        else
                                selfSay('That\'s too bad, maybe next time.')
                                talk_state = 1
                        end
                elseif talk_state == 3 then
                        item = 1954
                        rtrn = 2
                        if msgcontains(msg, 'antidote') then
                                price = 1000
                                selfSay('Do you want to buy an Antidote recipe for ' ..price.. ' gold?')
                                action = 50001
                                desc = 'This contains the recipe to make an Antidote.'
                                talk_state = 4
                        elseif msgcontains(msg, 'platinum coin') then
                                price = 2000
                                selfSay('For ' .. price ..' gold i can sell you the secert to minting platinum coins?')
                                action = 50002
                                desc = 'This contains the formula for minting Platinum Coins.'
                                talk_state = 4
                        elseif msgcontains(msg, 'mind stone') then
                                price = 2000
                                selfSay('Do you want to buy a Mind Stone recipe for ' ..price.. ' gold?')
                                action = 50003
                                desc = 'This contains the recipe to make a Mind Stones.'
                                talk_state = 4 
                        elseif msgcontains(msg, 'soul orb') then
                                price = 2000
                                selfSay('Do you want to buy a Soul Orb recipe for ' ..price.. ' gold?')
                                action = 50004
                                desc = 'This contains the recipe to make a Soul Orbs.'
                                talk_state = 4 
                        elseif msgcontains(msg, 'blood orb') then
                                price = 5000
                                selfSay('Do you want to buy a Blood Orb recipe for ' ..price.. ' gold?')
                                action = 50005
                                desc = 'This contains the recipe to make a Blood Orbs.'
                                talk_state = 4
                        elseif msgcontains(msg, 'love potion') then
                                price = 30000
                                selfSay('Do you want to buy a Love Potion recipe for ' ..price.. ' gold?')
                                action = 50006
                                desc = 'This contains the recipe to make a Love Potions.'
                                talk_state = 4
                        elseif msgcontains(msg, 'ectoplasm') then
                                price = 20000
                                selfSay('Do you want to buy a Ectoplasm recipe for ' ..price.. ' gold?')
                                action = 50007
                                desc = 'This contains the recipe to make some Ectoplasm.'
                                talk_state = 4
                        elseif msgcontains(msg, 'intense mana rune') then
                                price = 60000
                                selfSay('Do you want to buy a Intense Mana Rune recipe for ' ..price.. ' gold?')
                                action = 50008
                                desc = 'This contains the recipe to make a Intense Mana Runes.'
                                talk_state = 4
                        elseif msgcontains(msg, 'crystal coin') then
                                price = 100000
                                selfSay('For ' .. price ..' gold i can sell you the secert to minting crystal coins?')
                                action = 50009
                                desc = 'This contains the formula for minting Crystal coins.'
                                talk_state = 4 
                        elseif msgcontains(msg, 'sparkling mummy doll') then
                                price = 100000
                                selfSay('Do you want to buy a Sparkling Mummy Doll Recipe for ' ..price.. ' gold?')
                                action = 50010
                                desc = 'This contains the recipe to make a Sparkling Mummy Doll.'
                                talk_state = 4
                        elseif msgcontains(msg, 'berserk potion') then
                                price = 100000 
                                selfSay('Do you want to buy a Berserk Potion recipe for ' ..price.. ' gold?')
                                action = 50018
                                desc = 'This contains the recipe to make a Beserk Potion.'
                                talk_state = 4 
                        elseif msgcontains(msg, 'mastermind potion') then
                                price = 100000
                                selfSay('Do you want to buy a Mastermind Potion recipe for ' ..price.. ' gold?')
                                action = 50019
                                desc = 'This contains the recipe to make a Mastermind Potion.'
                                talk_state = 4
                        elseif msgcontains(msg, 'bullseye potion') then
                                price = 100000
                                selfSay('Do you want to buy a Bullseye Potion Recipe for ' ..price.. ' gold?')
                                action = 50020
                                desc = 'This contains the recipe to make a Bullseye Potion.'
                                talk_state = 4 
                        elseif msgcontains(msg, 'mead horn') then
                                price = 200000
                                selfSay('Do you want to buy a Mead Horn Recipe for ' ..price.. ' gold?')
                                action = 50021
                                desc = 'This contains the recipe to make a Mean Horn.'
                                talk_state = 4 
                        elseif msgcontains(msg, 'gold bar') then
                                price = 10000000
                                selfSay('For ' .. price ..' gold i can sell you the secret to minting gold bars?')
                                action = 50022
                                desc = 'This contains the formula for minting Gold Bars.'
                                talk_state = 4
                        elseif msgcontains(msg, 'ultimate mana rune') then
                                price = 500000
                                selfSay('Do you want to buy a Potion of Ultimate Mana Recipe for ' ..price.. ' gold?')
                                action = 50023
                                desc = 'This contains the recipe to make a Ultimate Mana rune.'
                                talk_state = 4 
                        elseif msgcontains(msg, 'clover amulet') then
                                price = 1000000
                                selfSay('Do you want to buy a Clover Amulet Recipe for ' ..price.. ' gold?')
                                action = 50024
                                desc = 'This contains the recipe to make a Clover Amulet.'
                                talk_state = 4
                        elseif msgcontains(msg, 'sword') then
                                price = 2000000
                                selfSay('Do you want to buy a sword Recipe for ' ..price.. ' gold?')
                                action = 50025
                                desc = 'This contains the recipe to make a sword.'
                                talk_state = 4
                        elseif msgcontains(msg, 'magic') then
                                price = 2000000
                                selfSay('Do you want to buy magic Recipe for ' ..price.. ' gold?')
                                action = 50026
                                desc = 'This contains the recipe to make magic.'
                                talk_state = 4
                        elseif msgcontains(msg, 'arrow') then
                                price = 2000000
                                selfSay('Do you want to buy an arrow Recipe for ' ..price.. ' gold?')
                                action = 50027
                                desc = 'This contains the recipe to make arrow.'
                                talk_state = 4
                        elseif msgcontains(msg, 'bye') then
                                selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
                                focus = 0
                                talk_start = 0 
                        end    
                elseif talk_state == 4 then
                        if msgcontains(msg, 'yes') then
                                if getPlayerMoney(cid) >= price then
                                        selfSay('Here you go!')
                                        doPlayerRemoveMoney(cid, price)
                                        doPlayerAddItem(cid, item, 1)
                                        if action then
                                                doItemSetAttribute(getPlayerItemById(cid, true, 1954).uid, "aid", action)
                                        end
                                        if desc then
                                                doItemSetAttribute(getPlayerItemById(cid, true, 1954).uid, "description", desc)
                                        end    
                                        if rtrn == 1 then
                                                talk_state = 2
                                        else   
                                                talk_state = 3
                                        end    
                                else
                                        selfSay('You don\'t seem to have enough money.')
                                        if rtrn == 1 then
                                                talk_state = 2
                                        else   
                                                talk_state = 3
                                        end    
                                end
                        else
                                selfSay('That\'s too bad, maybe next time.')
                                if rtrn == 1 then
                                        talk_state = 2
                                else   
                                        talk_state = 3
                                end            
                        end    
                elseif msgcontains(msg, 'bye') then
                        selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
                        focus = 0
                        talk_start = 0
                end
        elseif msgcontains(msg, 'bye') and focus == cid then
                selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
                focus = 0
                talk_start = 0 
        end
end

function onThink()
        doNpcSetCreatureFocus(focus)
        if (os.clock() - talk_start) > 30 then
                if focus > 0 then
                        selfSay('Next Please...')
                end
                focus = 0
        end
        if focus ~= 0 then
                if getDistanceToCreature(focus) > 5 then
                        selfSay('Good bye then.')
                        focus = 0
                end
        end
end
XML Location: data/npc/elric.xml
XML Code:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Elric" script="data/npc/scripts/alchemy.lua" walkinterval="3000">
<health now="100" max="100"/>
<look type="333"/>
</npc>
Extra Details: N/A
Description: NPC that sells all things related to Alchemy.
[Install [Alchemy NPC 0.3.6] = End]

[Install [Alchemy MOD 0.3.6] = Start]
Script Name: AlchemySystem.xml
Type: Action
MOD Location: mods/
MOD Code:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Alchemy System" version="4.0" author="soul4soul" enabled="yes">
    <item id="1954" article="a" name="recipe paper" override="yes">
        <attribute key="weight" value="100" />
    </item>
    <item id="1965" article="a" name="book of alchemy" override="yes">
        <attribute key="weight" value="1300" />
    </item>
    <item id="6104" article="a" name="alchemy kit" override="yes">
        <attribute key="weight" value="170" />
        <attribute key="containerSize" value="10" />
    </item>
    <item id="8977" article="a" name="top characters encyclopedia" override="yes">
        <attribute key="description" value="A list of the best alchemists are inside." />
        <attribute key="weight" value="1337" />
    </item>
    <config name="recipeinfo"><![CDATA[
    t =  {
        --[uid] = {newitemid, lvl, slots = {{item to be used, count},{item to be used, count}},  difficulty = 10-100 by 10's, destroy = 'yes' or 'no'}, 
        [50001] = {item = 8474, alchemylvl = 10, slots = {{2007, 1}, {2795, 1}, {2760, 1}}, difficulty = 20, destroy = 'no'},
        [50002] = {item = 2152, alchemylvl = 15, slots = {{2148, 10}, {10608, 2}}, difficulty = 20, destroy = 'no'},
        [50003] = {item = 2178, alchemylvl = 20, slots = {{2177, 1}, {1295, 1}, {2146, 3}}, difficulty = 40, destroy = 'no'},
        [50004] = {item = 5944, alchemylvl = 20, slots = {{2177, 1}, {1295, 1}, {2150, 3}}, difficulty = 40, destroy = 'no'},
        [50005] = {item = 2363, alchemylvl = 25, slots = {{2177, 1}, {2177, 1}, {1295, 1}, {2798, 1}, {2788, 1}}, difficulty = 50, destroy = 'no'},
        [50006] = {item = 10092, alchemylvl = 30, slots = {{2677, 3}, {1685, 1}, {2013, 1}, {2015, 1}}, difficulty = 60, destroy = 'no'},
        [50007] = {item = 4864, alchemylvl = 35, slots = {{4850, 1}, {2913, 1}, {2144, 1}}, aid = 105, difficulty = 40, destroy = 'no'},
        [50008] = {item = 2276, alchemylvl = 40, slots = {{10558, 1}, {2260, 1}, {10554, 1}, {2151, 1}, {5951, 1}, {2265, 1}}, difficulty = 40, destroy = 'no'},
        [50009] = {item = 2160, alchemylvl = 45, slots = {{2152, 1}, {2145, 1}, {2146, 1}, {2800, 1}}, difficulty = 30, destroy = 'no'},
        [50010] = {item = 11201, alchemylvl = 45, slots = {{2759, 1}, {10565, 1}, {2803, 1}, {2692, 1}}, difficulty = 40, destroy = 'no'},
        [50011] = {item = 5892, alchemylvl = 5, slots = {{5468, 1}, {2393, 1}}, difficulty = 50, destroy = 'yes'},
        [50012] = {item = 5887, alchemylvl = 5, slots = {{5468, 1}, {2487, 1}}, difficulty = 50, destroy = 'yes'},
        [50013] = {item = 5888, alchemylvl = 5, slots = {{5468, 1}, {2462, 1}}, difficulty = 50, destroy = 'yes'},
        [50014] = {item = 5889, alchemylvl = 5, slots = {{5468, 1}, {2516, 1}}, difficulty = 50, destroy = 'yes'},
        [50015] = {item = 5891, alchemylvl = 10, slots = {{2195, 1}, {4265, 1}, {2151, 1}}, difficulty = 40, destroy = 'yes'},
        [50016] = {item = 5884, alchemylvl = 10, slots = {{2498, 1}, {2498, 1}, {2913, 1}, {5865, 1}}, difficulty = 40, destroy = 'yes'},
        [50017] = {item = 5885, alchemylvl = 10, slots = {{2475, 1}, {2475, 1}, {2475, 1}, {2475, 1}, {2015, 1}, {5865, 1}}, difficulty = 40, destroy = 'yes'},
        [50018] = {item = 7439, alchemylvl = 60, slots = {{6558, 1}, {2007, 1}, {4993, 1}, {5480, 1}, {2796, 1}}, difficulty = 30, destroy = 'no'},
        [50019] = {item = 7440, alchemylvl = 60, slots = {{6558, 1}, {2007, 1}, {4992, 1}, {3955, 1}, {7250, 1}}, difficulty = 30, destroy = 'no'},
        [50020] = {item = 7443, alchemylvl = 60, slots = {{6558, 1}, {2007, 1}, {4994, 1}, {2193, 1}, {2031, 1}}, difficulty = 30, destroy = 'no'},
        [50021] = {item = 7140, alchemylvl = 65, slots = {{7141, 1}, {2015, 1}, {5014, 1}, {2235, 1}, {7439, 1}, {7440, 1}, {7443, 1}, {4845, 1}}, difficulty = 60, destroy = 'no'},
        [50022] = {item = 9971, alchemylvl = 70, slots = {{10552, 1}, {2157, 1}, {2159, 1}, {5906, 1}}, difficulty = 50, destroy = 'no'},
        [50023] = {item = 2284, alchemylvl = 75, slots = {{10523, 1}, {2260, 1}, {10554, 1}, {2151, 1}, {2273, 1}}, difficulty = 30, destroy = 'no'},
        [50024] = {item = 11387, alchemylvl = 80, slots = {{2805, 1}, {2798, 1}, {8582, 1}}, difficulty = 70, destroy = 'no'},
        [50025] = {item = 8980, alchemylvl = 90, slots = {{5941, 1}, {10559, 1}, {2194, 1}, {2377, 1}}, difficulty = 80, destroy = 'no'},
        [50026] = {item = 2184, alchemylvl = 90, slots = {{9942, 1}, {9941, 1}, {9980, 1}, {2445, 1}}, difficulty = 80, destroy = 'no'},
        [50027] = {item = 2352, alchemylvl = 90, slots = {{2177, 1}, {2160, 1}, {2544, 1}, {2544, 1}, {2802, 1}}, difficulty = 80, destroy = 'no'},
        [50028] = {item = 9969, alchemylvl = 100, slots = {{5741, 1}, {2229, 1}, {5669, 1}, {5809, 1}, {2143, 1}}, difficulty = 90, destroy = 'yes'},
        [50029] = {item = 9006, alchemylvl = 110, slots = {{8859, 1}, {2289, 1}, {2807, 1}, {10556, 1}, {2545, 1}, {5879, 1}}, difficulty = 100, destroy = 'yes'},
        [50030] = {item = 2348, alchemylvl = 120, slots = {{2153, 1}, {2154, 1}, {2155, 1}, {2156, 1}, {2158, 1}, {2260, 1}, {2260, 1}, {2600, 1}}, difficulty = 100, destroy = 'yes'}
        }    
        
    --[CustomSkill]-- By:Athern
    function getCustomSkill(cid, storage)
        return getPlayerStorageValue(cid, storage)
    end
 
    function addCustomSkill(cid, skillName, storage)
        local skillStorage = math.max(10, getPlayerStorageValue(cid, storage))
        local skillTries =  math.max(0, getPlayerStorageValue(cid, storage+1))
 
        doPlayerSetStorageValue(cid, storage, skillStorage+1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You advanced in " .. skillName .. ".")
        doPlayerSetStorageValue(cid, storage+1, 0)
    end

    function addCustomSkillTry(cid, skillName, storage)
        local skillStorage = math.max(10, getPlayerStorageValue(cid, storage))
        local skillTries =  math.max(0, getPlayerStorageValue(cid, storage+1))
    
        doPlayerSetStorageValue(cid, storage+1, skillTries + 1)
 
        if skillTries > math.floor(20 * math.pow(1.1, (skillStorage-11)) / 10) then
            addCustomSkill(cid, skillName, storage)
        end
    end

    function getCustomSkillPercent(cid, storage)
        local skillStorage = math.max(10, getPlayerStorageValue(cid, storage))
        local skillTries =  math.max(0, getPlayerStorageValue(cid, storage+1))
        local triesNeeded = math.floor(20 * math.pow(1.1, (skillStorage-11)) / 10)
        local percent = math.floor(100*(1-skillTries / triesNeeded))
        if percent > 1 and percent <= 100 then
            return percent
        else
            percent = 1
            return percent
        end
    end
    --[/CustomSkill]--     
    
    --[highscore book]--
function doPlayerShowHighscore(uid, storage, name)
    -- Function made by Ragheed and Zyntax from OTFans. --
    -- small edit by soul4soul
    if storage then
        if(isNumber(storage) == true) then
            if(isPlayer(uid)) then
                if name then
                    if(type(name)== 'string') then
                        if(string.len(name) <= 20) then
                            gameName = name
                        else
                            print("[ERROR] : doPlayerShowHighscore: name cannot be longer then 20 characters.")
                            return false
                        end
                    else
                        print("[ERROR] : doPlayerShowHighscore: name is not a string.")
                        return false
                    end
                else
                    gameName = "Game"
                end
                local shownPlayers = 10
                local str = ""..gameName.." Highscore:\n#  Player - [Score]\n"
                local result = db.getResult('SELECT `value`, `player_id` FROM `player_storage` WHERE `key`='..storage..' ORDER BY `value` DESC;')
                if(result:getID() ~= -1) then
                    local i = 1
                    while TRUE do
                        str = str .. "\n " .. i .. ". "..getPlayerNameByGUID(result:getDataInt("player_id")).." - [" .. result:getDataInt("value") .. "]"
                        if not(result:next()) or i > shownPlayers then
                            break
                        end
                        i = i+1
                    end
                    result:free()
                else
                    str = ""..gameName.." Highscore is empty."
                end
                if(str ~= "") then
                    doShowTextDialog(uid, 8977, str)
                end
            else
                print("[ERROR] : doPlayerShowHighscore: player not found.")
                return false
            end
        else
            print("[ERROR] : doPlayerSetHighscore: storage is not a number value.")
            return false
        end
    else
        print("[ERROR] : doPlayerShowHighscore: storage not found.")
        return false
    end
    return true
end    
--[/highscore book]--        
    ]]></config>
    <action  itemid="2217"  event="script"><![CDATA[
    function onUse(cid, item, toPosition, fromPosition)
        local function burn()
            local Cpos = getCreaturePosition(cid)
            local north = {x = Cpos.x, y = Cpos.y-1, z = Cpos.z}
            local south = {x = Cpos.x, y = Cpos.y+1, z = Cpos.z}
            local west = {x = Cpos.x-1, y = Cpos.y, z = Cpos.z}
            local east = {x = Cpos.x+1, y = Cpos.y, z = Cpos.z}
            if getCreatureLookDirection(cid) == 0 then
                doSendMagicEffect(north, 6)
            elseif getCreatureLookDirection(cid) == 1 then
                doSendMagicEffect(east, 6)
            elseif getCreatureLookDirection(cid) == 2 then
                doSendMagicEffect(south, 6)    
            elseif getCreatureLookDirection(cid) == 3 then
                doSendMagicEffect(west, 6)  
            end
        end
        local learned = getPlayerStorageValue(cid, 50500)
        if learned == -1 then  
            setPlayerStorageValue(cid, 50500, 10)
            doRemoveItem(item.uid)
            doPlayerSendTextMessage(cid, 25, "You have learned Alchemy, then the book burned to ashes after learning its Alchemic Secrets.")
            addEvent(burn, 500, {cid = cid, toPosition = toPosition, fromPosition = fromPosition})
        else
            doPlayerSendCancel(cid, "You already know Alchemy.")
        end
        return true
    end    
    ]]></action>
    <action itemid="8977" event="buffer"><![CDATA[
        if item.actionid == 50500 then
            doPlayerShowHighscore(cid, item.actionid, "Alchemy")
        else
            _result = false
        end
    ]]></action>
    <action  itemid="1954"  event="script"><![CDATA[
        domodlib("recipeinfo")
        function onUse(cid, item, toPosition, item2, fromPosition)
            if item.actionid == nil then
                return true
            end
            k = t[item.actionid]
            if getPlayerStorageValue(cid, item.actionid) == -1 then
                if getCustomSkill(cid, 50500) >= k.alchemylvl then
                    doPlayerSetStorageValue(cid, item.actionid, item.actionid-50000)
                    doPlayerSendTextMessage(cid, 25, "You learned how to make ".. getItemInfo(k.item).article.." "..getItemInfo(k.item).name..".")
                    doSendMagicEffect(getCreaturePosition(cid), 13)
                else
                    doPlayerSendCancel(cid, "You require "..k.alchemylvl.." in Alchemy or you don't know Alchemy.")
                end
            else
                doPlayerSendCancel(cid, "You have already learned this recipe.")
            end
            return true
        end    
    ]]></action>
    <action  itemid="1965"  event="script"><![CDATA[
        local skillIDs = {
                {50500, "Alchemy"} -- The first ID is the skill value, the second ID is the name of the skill
        }
        domodlib("recipeinfo")
    function onUse(cid, item, fromPosition, itemEx, toPosition)
        local a = {}
        skill = "Alchemy Level: " .. math.max(10, getCustomSkill(cid, skillIDs[1][1])) .. ". Percent to go: " .. getCustomSkillPercent(cid, skillIDs[1][1]) .. "%\n-------\n\n"
        table.insert(a, skill)
        table.insert(a, "Learned Recipes:\n\n")
        recipe = ""
        for i, k in pairs(t) do
            if getPlayerStorageValue(cid, i) > 0 then
                for i2 = 1, #k.slots do
                    test = k.slots[i2]
                    recipe = ""..recipe..", "..test[2].. " ".. getItemInfo(test[1]).name .. ""
                end
                recipe = "[" ..getItemInfo(k.item).name.. "]\n-Alchemy Level: " .. k.alchemylvl .. ", Difficulty: " .. k.difficulty .. "\n--Ingredients: recipe paper".. recipe .. ". \n\n"
                table.insert(a, recipe)
                recipe = ""
            end
        end
        doSetItemText(item.uid, table.concat(a, ""))    
    end
    ]]></action>
    <movevent type="AddItem" tileitem="1" itemid="1426" event="script"><![CDATA[        
    function onAddItem(moveItem, tileItem, position, cid) 
        domodlib("recipeinfo")
        if getItemInfo(moveItem.itemid).type == ITEM_TYPE_CONTAINER then  
            container = getTileItemByType(position, 4)
            inContainer = {
                            getContainerItem(container.uid, 0),
                            getContainerItem(container.uid, 1),
                            getContainerItem(container.uid, 2),
                            getContainerItem(container.uid, 3),
                            getContainerItem(container.uid, 4),
                            getContainerItem(container.uid, 5),
                            getContainerItem(container.uid, 6),
                            getContainerItem(container.uid, 7),
                            getContainerItem(container.uid, 8)
                        }
            pass = 0
            k = t[inContainer[1].actionid]
            if getPlayerStorageValue(cid, inContainer[1].actionid) == inContainer[1].actionid-50000 then
                for size = #k.slots + 1,2, -1 do
                    testin = k.slots[size-1]
                    if testin[1] == inContainer[size].itemid then
                        if doRemoveItem(inContainer[size].uid, testin[2]) == LUA_NO_ERROR then
                            pass = pass + 1
                        end
                    end
                end
                
                if pass == #k.slots then
                    if moveItem.itemid == 6104 then
                        chance = k.difficulty-10
                    else
                        chance = k.difficulty
                    end
                    if math.random(1, (90 + (getCustomSkill(cid, 50500) / 10))) > chance then
                        doPlayerAddItem(cid, k.item,1)
                        doSendMagicEffect(position, CONST_ME_HITBYFIRE)
                        doPlayerSendTextMessage(cid, 25, "You made ".. getItemInfo(k.item).article.." "..getItemInfo(k.item).name..".")
                        gain = (k.difficulty/10)
                        for i3=1, gain do
                            addCustomSkillTry(cid, "Alchemy", 50500)
                        end
                        if k.aid then
                            local getItem = getPlayerItemById(cid, true, k.item)
                            doItemSetAttribute(getItem.uid, "aid", k.aid)
                        end
                    else
                        doPlayerSendCancel(cid, "The mix went wrong.")
                        doCreatureAddHealth(cid, -getCreatureMaxHealth(cid)*0.01, CONST_ME_FIREAREA)
                        addCustomSkillTry(cid, "Alchemy", 50500)
                    end
                    if destroy == 'yes' then
                        doRemoveItem(container.uid)
                    end
                else
                    doPlayerSendCancel(cid, "There are no Ingredients or some are missing.")
                end                   
            else
                doPlayerSendCancel(cid, "You haven't learned this recipe yet or the container is empty.")
            end    
        else 
            doPlayerSendCancel(cid, "You must use a container and place the ingredients inside.")
        end    
        return true
    end
    ]]></movevent>
</mod>
Extra Details: When making potions, you need to make sure you place them in their respective order.
if destory is set to yes it will also remove the alchemy list and remove the container. EX. all the items in the picture with cracks next to them have the lists destroyed. you can only get the lists from quests.
Description: This MOD is contains all of the other scripts which allows the player to learn
recipes, learn alchemy, get their alchemy skill and read their ingredients book.
[Install [Alchemy MOD 0.3.6] = End]

Demonstration
AlchemyDemo.png


AlchemyDemo2.png

In here as you see the names of the items in their order on the
alchemy book, you have to put them in the same order inside the
alchemic kit to make the recipe work, also the recipe always has
to be in the front(first slot).
AlchemyDemo3.png


After you have the items in their order move the item to the example location(user can define on where to use this), to make
the mix happen, also any container type can be used for alchemy,
but only the Alchemic Kit reduces the difficulty of the mix by
10 points.

Example on how I set it up in my server:
examplealchemylayout.png


Well I hope this helps anyone and if any bugs or question just
ask and I'll do the best I can to help.
Note here is Whiskey's chart if you feel like you want to use it!
alchemy.png
 
Last edited:
innovative :)
can you make pictures words bigger?
 
You had to be fuckin' bored to do that images xD! Anyways gr8 job.
 
the: [alchemyskill.lua] can be shortened, i have no idea how you use "maths" and not use loops...
 
you mean the custom function (the first script in the post) that was not made by me and i don't know how to change it, or make it better. but it does what i want it to do so i works for that i guess.
 
#Chojrak - it was pretty fun to plan it out, and well, seeing the script itself... Sure was worth it. Thanks again 375311!
 
you mean the custom function (the first script in the post) that was not made by me and i don't know how to change it, or make it better. but it does what i want it to do so i works for that i guess.

Code:
local function burn(cid, item)
	local Cpos = getCreaturePosition(cid)
	local table = {
		[0] = {pos = {x = Cpos.x, y = Cpos.y-1, z = Cpos.z}},
		[1] = {pos = {x = Cpos.x, y = Cpos.y+1, z = Cpos.z}},
		[2] = {pos = {x = Cpos.x-1, y = Cpos.y, z = Cpos.z}},
		[3] = {pos = {x = Cpos.x+1, y = Cpos.y, z = Cpos.z}}
	}
	doSendMagicEffect(table[getCreatureLookDirection(cid)], 6)
	if item.itemid == 2217 then
		local storages = {41508, 41509}
		for i = 1, #storages do
			setPlayerStorageValue(cid, storages[i], 0)
		end
		for i = 50500, 50022 do
			setPlayerStorageValue(cid, i, 0)
		end
		doRemoveItem(item.uid)
		doPlayerSendTextMessage(cid, 25, "You have learned Alchemy, then the book burned to ashes after learning its Alchemic Secrets.")
	end
end
function onUse(cid, item, toPosition, fromPosition)
	return addEvent(burn, 300, cid, item)
end
 
Last edited:
none, i only showed that as an example that the switch needs to always be to the left of the container.
 
Use loops plz

Lua:
                doPlayerSetStorageValue(cid, 41508, 0)
                doPlayerSetStorageValue(cid, 41509, 0)
                doPlayerSetStorageValue(cid, 50500, 10)
                doPlayerSetStorageValue(cid, 50001, 0)
                doPlayerSetStorageValue(cid, 50002, 0)
                doPlayerSetStorageValue(cid, 50003, 0)
                doPlayerSetStorageValue(cid, 50004, 0)
                doPlayerSetStorageValue(cid, 50005, 0)
                doPlayerSetStorageValue(cid, 50006, 0)
                doPlayerSetStorageValue(cid, 50007, 0)
                doPlayerSetStorageValue(cid, 50008, 0)
                doPlayerSetStorageValue(cid, 50009, 0)
                doPlayerSetStorageValue(cid, 50010, 0)
                doPlayerSetStorageValue(cid, 50011, 0)
                doPlayerSetStorageValue(cid, 50012, 0)
                doPlayerSetStorageValue(cid, 50013, 0)
                doPlayerSetStorageValue(cid, 50014, 0)
                doPlayerSetStorageValue(cid, 50015, 0)
                doPlayerSetStorageValue(cid, 50016, 0)
                doPlayerSetStorageValue(cid, 50017, 0)
                doPlayerSetStorageValue(cid, 50018, 0)
                doPlayerSetStorageValue(cid, 50019, 0)
                doPlayerSetStorageValue(cid, 50020, 0)
                doPlayerSetStorageValue(cid, 50021, 0)
                doPlayerSetStorageValue(cid, 50022, 0)

THis can be:
Lua:
for i = 41509, 50022 do
           doPlayerSetStorageValue(cid, i, 0)
end
 
Use loops plz

Lua:
                doPlayerSetStorageValue(cid, 41508, 0)
                doPlayerSetStorageValue(cid, 41509, 0)
                doPlayerSetStorageValue(cid, 50500, 10)
                doPlayerSetStorageValue(cid, 50001, 0)
                doPlayerSetStorageValue(cid, 50002, 0)
                doPlayerSetStorageValue(cid, 50003, 0)
                doPlayerSetStorageValue(cid, 50004, 0)
                doPlayerSetStorageValue(cid, 50005, 0)
                doPlayerSetStorageValue(cid, 50006, 0)
                doPlayerSetStorageValue(cid, 50007, 0)
                doPlayerSetStorageValue(cid, 50008, 0)
                doPlayerSetStorageValue(cid, 50009, 0)
                doPlayerSetStorageValue(cid, 50010, 0)
                doPlayerSetStorageValue(cid, 50011, 0)
                doPlayerSetStorageValue(cid, 50012, 0)
                doPlayerSetStorageValue(cid, 50013, 0)
                doPlayerSetStorageValue(cid, 50014, 0)
                doPlayerSetStorageValue(cid, 50015, 0)
                doPlayerSetStorageValue(cid, 50016, 0)
                doPlayerSetStorageValue(cid, 50017, 0)
                doPlayerSetStorageValue(cid, 50018, 0)
                doPlayerSetStorageValue(cid, 50019, 0)
                doPlayerSetStorageValue(cid, 50020, 0)
                doPlayerSetStorageValue(cid, 50021, 0)
                doPlayerSetStorageValue(cid, 50022, 0)

THis can be:
Lua:
for i = 41509, 50022 do
           doPlayerSetStorageValue(cid, i, 0)
end
>>876695
>>876695
>>876695
 
@ Existance
oh! nice, that's way shorter than the normal one. well anyways I'm still new at this and there is a lot about LUA language that I don't know, but I'm learning and ill use that script as reference, also do you know any page that can explain every code and language details about lua? if so that will help me so much.
 
i got error
Code:
[Warning - Actions::registerEvent] Duplicate registered item id: 9825
[Error - LuaScriptInterface::loadFile] cannot open data/actions/scripts/potion e
ffects.lua: No such file or directory
[Warning - Event::loadScript] Cannot load script (data/actions/scripts/potion ef
fects.lua)
cannot open data/actions/scripts/potion effects.lua: No such file or directory
>> Loading chat channels
 
make sure the files are in the right place and that the names of the files are correct. that should fix it.
 
when i use skill book
Code:
[Error - Action Interface]
data/actions/scripts/skill_book.lua:onUse
Description:
data/actions/scripts/skill_book.lua:9: attempt to call global 'getCustomSkill' (
a nil value)
stack traceback:
        data/actions/scripts/skill_book.lua:9: in function <data/actions/scripts
/skill_book.lua:4>
 
you forgot to copy the custom function that goes in lib/functions.lua, if that's not there, then it wouldn't work, also this was tested on TFS 0.3.5 and it also should work in the tfs 0.3.6. well make sure you place the custom function which is the first script in the first post.
 
Back
Top