• 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] Potion / Rune lever, explained thoroughly.

Skylinx

Game Programmer
Joined
Nov 26, 2008
Messages
399
Reaction score
14
Location
TORONTO, CANADA
Hey guys, Mike here.
I remember having trouble with this before, and I know there is tons of scripts released, ETC. But I saw so many people having trouble with this.

How to make a potion / rune lever switch for [Item for GP]

Lets start off
Here is what you need:
Map editor
TFS/Roxor any server above 8.40 I suggest


From what I heard this code is by Keraxel, Pre-Credits to him.
I did not make the script.
Code:
-- by Keraxel // for otcentrum.pl
local config = {
effect = 39,
aolPrice = 4000
}
local prices = {
--[runeId] = {cost, charges, backpackColor, count},
--POTIONS--
[7618] = {800, 1, "red", 1}, --health potion
[7620] = {900, 1, "purple", 1}, --mana potion
[7588] = {1800, 1, "red", 1}, --strong health potion
[7589] = {1500, 1, "purple", 1}, --strong mana potion
[7591] = {3500, 1, "red", 1}, --great health potion
[7590] = {2200, 1, "purple", 1}, --great mana potion
[8472] = {3500, 1, "yellow", 1}, --great spirit potion
[8473] = {5800, 1, "red", 1}, --ultimate health potion
--RUNES--
[2273] = {8000, 5, "blue", 1}, --UH
[2268] = {10000, 5, "grey", 1}, --SD
[2313] = {2500, 5, "purple", 1}, --explosion
[2287] = {600, 10, "green", 1}, --light magic missile
[2311] = {2200, 10, "purple", 1}, --heavy magic missile
[2304] = {5000, 5, "red", 1}, --great fireball
[2302] = {1800, 5, "red", 1}, --fireball
[2260] = {100, 1, "grey", 1}, --blank rune
[2261] = {800, 3, "grey", 1}, --destroy field
[2316] = {7300, 1, "purple", 1}, --animate dead
[2262] = {6500, 2, "grey", 1}, --energy bomb
[2277] = {2200, 3, "blue", 1}, --energy field
[2269] = {2500, 5, "purple", 1}, --wild growth
[2274] = {3400, 4, "blue", 1}, --avalanche
[2271] = {2900, 5, "blue", 1}, --icile
[2308] = {2500, 5, "red", 1}, --soulfire
[2285] = {1200, 3, "green", 1}, --poison field
[2286] = {3200, 2, "green", 1}, --poison bomb
[2289] = {4000, 4, "green", 1}, --poison wall
[2290] = {1500, 1, "green", 1}, --convince creature
[2291] = {4000, 1, "green", 1}, --chameleon
[2292] = {2200, 10, "green", 1}, --stalagmite
[2288] = {2800, 4, "green", 1}, --stone shower
[2301] = {3000, 5, "red", 1}, --fire field
[2305] = {4400, 2, "red", 1}, --firebomb
[2303] = {4600, 4, "red", 1} --fire wall
}
-----
function onUse(cid, item, fromPosition, itemEx, toPosition)

local function backpackIdByName(name)
local backpacksId = {["green"]=1998, ["yellow"]=1999, ["red"]=2000, ["purple"]=2001, ["blue"]=2002, ["grey"]=2003, ["golden"]=2004}
    return backpacksId[name] or LUA_ERROR

end

local aid = item.actionid - 10000

    if aid == 2173 then
        if (doPlayerBuyItem(cid, 2173, 1, config.aolPrice, 1)) ~= LUA_ERROR then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You've bought an amulet of loss.")
            doSendMagicEffect(getCreaturePosition(cid), config.effect)
        else
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You don't have enough money. The price is "..config.aolPrice.." gold pieces.")
        end

    else

                if (doPlayerBuyItemContainer(cid, backpackIdByName(prices[aid][3]), aid, 1, prices[aid][1], prices[aid][2])) == LUA_NO_ERROR then
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You've bought a backpack of "..getItemNameById(aid)..".")
                    doSendMagicEffect(getCreaturePosition(cid), config.effect)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You don't have enough money. The price is "..prices[aid][1].." gold pieces.")
                end
    end
    return TRUE
end

This script is easy to understand, but its tricky. I will guaruntee it will work 100% if you follow my instructions.

1. Now what you want to do, is copy paste that script above into any text file, rename it leverRunes.lua (Or anything you want, must be .lua extension)

2. From there, instead of going straight to your action.xml, I suggest first doing below.

I suggest setting the action ID of the tile BELOW the lever, as 29050, or any random number, so no one pay pass and steal the rune. Or just build a wall.

3. Next open the script, you should see

Code:
--[runeId] = {cost, charges, backpackColor, count},
--RUNES--
[2273] = {8000, 5, "blue", 1}, -- UH
This means [2273] Is the Item id of the potion. The rest you may edit, but 2273 is an ultimate healing rune.

4. Next goto your map editor, and set the action ID of the lever as 12273. Why? Because the action ID of the lever is 10000+ ITEM ID, meaning the action ID of the lever would be 10000+2273 (the runes ID).
Heres what it should look like.


5. Now heres the important part, action.xml.
You dont only need ONE thing for action.xml, you need to state two things.
So put this into your action.xml


Code:
<action actionid="12273" script="leverRunes.lua"/> 
    <action itemid="2273" script="leverRunes.lua"/>
This tells the server, actionid of the lever 12273 goes to leverRunes.lua, as well as the ultimate healing rune.
You need to have both or it will not work.

6. Your done!, save everything and try using the lever!
All you have to do now, is set each lever to it's runes action ID, and copy paste and change the numbers in actions.xml.

Hope you liked my tutorial!
Sorry for the small images!
 
<action actionid="12273" script="leverRunes.lua"/>
<action itemid="2273" script="leverRunes.lua"/>

Will not work like that, the runes will be unusable, use this instead

<action actionid="12273" script="leverRunes.lua"/>
<action actionid="2273" script="leverRunes.lua"/>
 
Back
Top