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

[TFS 1.3] [Revscriptsys] Free Lua scripting service - Post your requests! Let's learn it together!

Lua:
local foods = {
    [2362] = {5, "Crunch."}, -- carrot
    [2666] = {15, "Munch."}, -- meat
    [2667] = {12, "Munch."}, -- fish
    [2668] = {10, "Mmmm."}, -- salmon
    [2669] = {17, "Munch."}, -- northern pike
    [2670] = {4, "Gulp."}, -- shrimp
    [2671] = {30, "Chomp."}, -- ham
    [2672] = {60, "Chomp."}, -- dragon ham
    [2673] = {5, "Yum."}, -- pear
    [2674] = {6, "Yum."}, -- red apple
    [2675] = {13, "Yum."}, -- orange
    [2676] = {8, "Yum."}, -- banana
    [2677] = {1, "Yum."}, -- blueberry
    [2678] = {18, "Slurp."}, -- coconut
    [2679] = {1, "Yum."}, -- cherry
    [2680] = {2, "Yum."}, -- strawberry
    [2681] = {9, "Yum."}, -- grapes
    [2682] = {20, "Yum."}, -- melon
    [2683] = {17, "Munch."}, -- pumpkin
    [2684] = {5, "Crunch."}, -- carrot
    [2685] = {6, "Munch."}, -- tomato
    [2686] = {9, "Crunch."}, -- corncob
    [2687] = {2, "Crunch."}, -- cookie
    [2688] = {2, "Munch."}, -- candy cane
    [2689] = {10, "Crunch."}, -- bread
    [2690] = {3, "Crunch."}, -- roll
    [2691] = {8, "Crunch."}, -- brown bread
    [2695] = {6, "Gulp."}, -- egg
    [2696] = {9, "Smack."}, -- cheese
    [2787] = {9, "Munch."}, -- white mushroom
    [2788] = {4, "Munch."}, -- red mushroom
    [2789] = {22, "Munch."}, -- brown mushroom
    [2790] = {30, "Munch."}, -- orange mushroom
    [2791] = {9, "Munch."}, -- wood mushroom
    [2792] = {6, "Munch."}, -- dark mushroom
    [2793] = {12, "Munch."}, -- some mushrooms
    [2794] = {3, "Munch."}, -- some mushrooms
    [2795] = {36, "Munch."}, -- fire mushroom
    [2796] = {5, "Munch."}, -- green mushroom
    [5097] = {4, "Yum."}, -- mango
    [6125] = {8, "Gulp."}, -- tortoise egg
    [6278] = {10, "Mmmm."}, -- cake
    [6279] = {15, "Mmmm."}, -- decorated cake
    [6393] = {12, "Mmmm."}, -- valentine's cake
    [6394] = {15, "Mmmm."}, -- cream cake
    [6501] = {20, "Mmmm."}, -- gingerbread man
    [6541] = {6, "Gulp."}, -- coloured egg (yellow)
    [6542] = {6, "Gulp."}, -- coloured egg (red)
    [6543] = {6, "Gulp."}, -- coloured egg (blue)
    [6544] = {6, "Gulp."}, -- coloured egg (green)
    [6545] = {6, "Gulp."}, -- coloured egg (purple)
    [6569] = {1, "Mmmm."}, -- candy
    [6574] = {5, "Mmmm."}, -- bar of chocolate
    [7158] = {15, "Munch."}, -- rainbow trout
    [7159] = {13, "Munch."}, -- green perch
    [7372] = {2, "Yum."}, -- ice cream cone (crispy chocolate chips)
    [7373] = {2, "Yum."}, -- ice cream cone (velvet vanilla)
    [7374] = {2, "Yum."}, -- ice cream cone (sweet strawberry)
    [7375] = {2, "Yum."}, -- ice cream cone (chilly cherry)
    [7376] = {2, "Yum."}, -- ice cream cone (mellow melon)
    [7377] = {2, "Yum."}, -- ice cream cone (blue-barian)
    [7909] = {4, "Crunch."}, -- walnut
    [7910] = {4, "Crunch."}, -- peanut
    [7963] = {60, "Munch."}, -- marlin
    [8112] = {9, "Urgh."}, -- scarab cheese
    [8838] = {10, "Gulp."}, -- potato
    [8839] = {5, "Yum."}, -- plum
    [8840] = {1, "Yum."}, -- raspberry
    [8841] = {1, "Urgh."}, -- lemon
    [8842] = {7, "Munch."}, -- cucumber
    [8843] = {5, "Crunch."}, -- onion
    [8844] = {1, "Gulp."}, -- jalapeño pepper
    [8845] = {5, "Munch."}, -- beetroot
    [8847] = {11, "Yum."}, -- chocolate cake
    [9005] = {7, "Slurp."}, -- yummy gummy worm
    [9114] = {5, "Crunch."}, -- bulb of garlic
    [9996] = {0, "Slurp."}, -- banana chocolate shake
    [10454] = {0, "Your head begins to feel better."}, -- headache pill
    [11246] = {15, "Yum."}, -- rice ball
    [11370] = {3, "Urgh."}, -- terramite eggs
    [11429] = {10, "Mmmm."}, -- crocodile steak
    [12415] = {20, "Yum."}, -- pineapple
    [12416] = {10, "Munch."}, -- aubergine
    [12417] = {8, "Crunch."}, -- broccoli
    [12418] = {9, "Crunch."}, -- cauliflower
    [12637] = {55, "Gulp."}, -- ectoplasmic sushi
    [12638] = {18, "Yum."}, -- dragonfruit
    [12639] = {2, "Munch."}, -- peas
    [13297] = {20, "Crunch."}, -- haunch of boar
    [15405] = {55, "Munch."}, -- sandfish
    [15487] = {14, "Urgh."}, -- larvae
    [15488] = {15, "Munch."}, -- deepling filet
    [16014] = {60, "Mmmm."}, -- anniversary cake
    [18397] = {33, "Munch."}, -- mushroom pie
    [19737] = {10, "Urgh."}, -- insectoid eggs
    [20100] = {15, "Smack."}, -- soft cheese
    [20101] = {12, "Smack."} -- rat cheese
}

local autoFeed = CreatureEvent("AutoFeed")

function autoFeed.onThink(player, interval)
    local foundFood, removeFood
    for itemid, food in pairs(foods) do
        if player:getItemCount(itemid) > 0 then
            foundFood, removeFood = food, itemid
            break
        end
    end
    if not foundFood then
        return true
    end
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and math.floor(condition:getTicks() / 1000 + foundFood[1] * 12) < 1200 then
        player:feed(foundFood[1] * 12)
        player:say(foundFood[2], TALKTYPE_MONSTER_SAY)
        player:removeItem(removeFood, 1)
    end
    return true
end

autoFeed:register()

local login = CreatureEvent("RegisterAutoFeed")

function login.onLogin(player)
    player:registerEvent("AutoFeed")
    return true
end

login:register()
 
Last edited:
Lua:
local foodAmount = 15 * 12
local autoFeed = CreatureEvent("AutoFeed")

function autoFeed.onThink(player, interval)
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and math.floor(condition:getTicks() / 1000 + foodAmount) < 1200 then
        player:feed(foodAmount)
        player:say("Munch.", TALKTYPE_MONSTER_SAY)
    end
    return true
end

autoFeed:register()

local login = CreatureEvent("RegisterAutoFeed")

function login.onLogin(player)
    player:registerEvent("AutoFeed")
    return true
end

login:register()
Shouldn't you only be feeding if the player has food in their inventory?
Otherwise there's literally no point in having a script like this, when you could just make the food condition infinite.
 
how do I set an interval on GlobalEvent?
I'm trying to convert this by myself
and so far the code is:

Lua:
local effects = {
    {position = Position(1000, 1000, 7), effect = 75},
    {position = Position(991, 1000, 7), text = 'Trainers'},
    {position = Position(307, 254, 1), text = 'Event', effect = CONST_ME_GROUNDSHAKER},
}

local tileeffect = GlobalEvent("Tile Effect")

function tileeffect.onThink(interval)
    for i = 1, #effects do
        local settings = effects[i]
        local spectators = Game.getSpectators(settings.position, false, true, 7, 7, 5, 5)
        if #spectators > 0 then
            if settings.text then
                for i = 1, #spectators do
                    spectators[i]:say(settings.text, TALKTYPE_MONSTER_SAY, false, spectators[i], settings.position)
                end
            end
            if settings.effect then
                settings.position:sendMagicEffect(settings.effect)
            end
        end
    end
   return true
end

tileeffect:register()
 
how do I set an interval on GlobalEvent?
I'm trying to convert this by myself
and so far the code is:

Lua:
local effects = {
    {position = Position(1000, 1000, 7), effect = 75},
    {position = Position(991, 1000, 7), text = 'Trainers'},
    {position = Position(307, 254, 1), text = 'Event', effect = CONST_ME_GROUNDSHAKER},
}

local tileeffect = GlobalEvent("Tile Effect")

function tileeffect.onThink(interval)
    for i = 1, #effects do
        local settings = effects[i]
        local spectators = Game.getSpectators(settings.position, false, true, 7, 7, 5, 5)
        if #spectators > 0 then
            if settings.text then
                for i = 1, #spectators do
                    spectators[i]:say(settings.text, TALKTYPE_MONSTER_SAY, false, spectators[i], settings.position)
                end
            end
            if settings.effect then
                settings.position:sendMagicEffect(settings.effect)
            end
        end
    end
   return true
end

tileeffect:register()
that:
Lua:
tileeffect:interval(1000)
 
how do I set an interval on GlobalEvent?
I'm trying to convert this by myself
and so far the code is:

Lua:
local effects = {
    {position = Position(1000, 1000, 7), effect = 75},
    {position = Position(991, 1000, 7), text = 'Trainers'},
    {position = Position(307, 254, 1), text = 'Event', effect = CONST_ME_GROUNDSHAKER},
}

local tileeffect = GlobalEvent("Tile Effect")

function tileeffect.onThink(interval)
    for i = 1, #effects do
        local settings = effects[i]
        local spectators = Game.getSpectators(settings.position, false, true, 7, 7, 5, 5)
        if #spectators > 0 then
            if settings.text then
                for i = 1, #spectators do
                    spectators[i]:say(settings.text, TALKTYPE_MONSTER_SAY, false, spectators[i], settings.position)
                end
            end
            if settings.effect then
                settings.position:sendMagicEffect(settings.effect)
            end
        end
    end
   return true
end

tileeffect:register()
For future reference: https://github.com/otland/forgotten...333d4eca2441bc3/src/luascript.cpp#L2896-L2905
 
so I no longer need to add all the info on items.xml? just basic stuff?

for example: Tagralt Blade (https://tibia.fandom.com/wiki/Tagralt_Blade)

Lua:
-- Tagralt Blade
local tagraltBlade = Weapon(WEAPON_SWORD)
tagraltBlade:id(36449)
tagraltBlade:attack(7)
tagraltBlade:defense(34)
tagraltBlade:extraElement(46, COMBAT_EARTHDAMAGE)
tagraltBlade:level(250)
tagraltBlade:vocation("knight", true, true)
tagraltBlade:vocation("elite knight")
tagraltBlade:slotType("two-handed") -- is this correct?
tagraltBlade:register()

and on items.xml

XML:
    <item id="36449" article="a" name="tagralt blade">
        <attribute key="weight" value="8100" />
        <attribute key="skillSword" value="2" />
    </item>

seems like skill bonus is not added to source? @Evil Hero
 
so I no longer need to add all the info on items.xml? just basic stuff?

for example: Tagralt Blade (https://tibia.fandom.com/wiki/Tagralt_Blade)

Lua:
-- Tagralt Blade
local tagraltBlade = Weapon(WEAPON_SWORD)
tagraltBlade:id(36449)
tagraltBlade:attack(7)
tagraltBlade:defense(34)
tagraltBlade:extraElement(46, COMBAT_EARTHDAMAGE)
tagraltBlade:level(250)
tagraltBlade:vocation("knight", true, true)
tagraltBlade:vocation("elite knight")
tagraltBlade:slotType("two-handed") -- is this correct?
tagraltBlade:register()

and on items.xml

XML:
    <item id="36449" article="a" name="tagralt blade">
        <attribute key="weight" value="8100" />
        <attribute key="skillSword" value="2" />
    </item>

seems like skill bonus is not added to source? @Evil Hero
You're confusing weapons.xml with items.xml, Weapon is for a weapon that would normally go into weapons.xml & has support for scripts.
 
You're confusing weapons.xml with items.xml, Weapon is for a weapon that would normally go into weapons.xml & has support for scripts.

so is this the correct way?
Lua:
-- Tagralt Blade
local tagraltBlade = Weapon(WEAPON_SWORD)
tagraltBlade:id(36449)
tagraltBlade:level(250)
tagraltBlade:vocation("knight", true, true)
tagraltBlade:vocation("elite knight")
tagraltBlade:slotType("two-handed")
tagraltBlade:register()

XML:
    <item id="36449" article="a" name="tagralt blade">
        <attribute key="weight" value="8100" />
        <attribute key="defense" value="34" />
        <attribute key="attack" value="7" />
        <attribute key="skillSword" value="2" />
        <attribute key="weaponType" value="sword" />
        <attribute key="slotType" value="two-handed" />
        <attribute key="elementEarth" value="46" />
    </item>
 
so is this the correct way?
Lua:
-- Tagralt Blade
local tagraltBlade = Weapon(WEAPON_SWORD)
tagraltBlade:id(36449)
tagraltBlade:level(250)
tagraltBlade:vocation("knight", true, true)
tagraltBlade:vocation("elite knight")
tagraltBlade:slotType("two-handed")
tagraltBlade:register()

XML:
    <item id="36449" article="a" name="tagralt blade">
        <attribute key="weight" value="8100" />
        <attribute key="defense" value="34" />
        <attribute key="attack" value="7" />
        <attribute key="skillSword" value="2" />
        <attribute key="weaponType" value="sword" />
        <attribute key="slotType" value="two-handed" />
        <attribute key="elementEarth" value="46" />
    </item>
Yes.
 
so I no longer need to add all the info on items.xml? just basic stuff?

for example: Tagralt Blade (https://tibia.fandom.com/wiki/Tagralt_Blade)

Lua:
-- Tagralt Blade
local tagraltBlade = Weapon(WEAPON_SWORD)
tagraltBlade:id(36449)
tagraltBlade:attack(7)
tagraltBlade:defense(34)
tagraltBlade:extraElement(46, COMBAT_EARTHDAMAGE)
tagraltBlade:level(250)
tagraltBlade:vocation("knight", true, true)
tagraltBlade:vocation("elite knight")
tagraltBlade:slotType("two-handed") -- is this correct?
tagraltBlade:register()

and on items.xml

XML:
    <item id="36449" article="a" name="tagralt blade">
        <attribute key="weight" value="8100" />
        <attribute key="skillSword" value="2" />
    </item>

seems like skill bonus is not added to source? @Evil Hero
Yes skillSword is not implemented yet, this will take it's place once itemType gets a revamp and attributes as a metatable gets introduced (after 1.3 release)
You're confusing weapons.xml with items.xml, Weapon is for a weapon that would normally go into weapons.xml & has support for scripts.
Actually it's currently a mix of both, it's just missing everything which is related to attributes (absorb, skill, etc.)
You can basicly override attack from every weapon which is placed in items.xml etc. with it.
 
that:
Lua:
tileeffect:interval(1000)

its not working as intended I guess:

2019-08-21 02_49_04-Tibia - Puncker.jpg

even with a higher interval it still spam

@Evil Hero seems like the #example weapon is throwing an error on my console (attempt to call method 'wieldedUnproperly' (a nil value)) or maybe its just my tfs fault?

also some kind of request/question: is there a way to randomize monster outfit? for example, I 'ported' Hunter monster to revscriptsys and added math.random to randomize its colors, but they just set a random color for all hunters, and the color stay the same even if I restart tfs
 
Last edited by a moderator:
be sure to set the interval before logging the global event.
what do you mean? (sorry for the dumb question)
Lua:
local effects = {
    {position = Position(1000, 1000, 7), effect = 75},
    {position = Position(991, 1000, 7), text = 'Trainers'},
    {position = Position(307, 254, 1), text = 'Event', effect = CONST_ME_GROUNDSHAKER}
}

local tileeffect = GlobalEvent("Tile Effect")

function tileeffect.onThink(interval)
    for i = 1, #effects do
        local settings = effects[i]
        local spectators = Game.getSpectators(settings.position, false, true, 7, 7, 5, 5)
        if #spectators > 0 then
            if settings.text then
                for i = 1, #spectators do
                    spectators[i]:say(settings.text, TALKTYPE_MONSTER_SAY, false, spectators[i], settings.position)
                end
            end
            if settings.effect then
                settings.position:sendMagicEffect(settings.effect)
            end
        end
    end
   return true
end

tileeffect:interval(10000)
tileeffect:register()
 
what do you mean? (sorry for the dumb question)
Lua:
local effects = {
    {position = Position(1000, 1000, 7), effect = 75},
    {position = Position(991, 1000, 7), text = 'Trainers'},
    {position = Position(307, 254, 1), text = 'Event', effect = CONST_ME_GROUNDSHAKER}
}

local tileeffect = GlobalEvent("Tile Effect")

function tileeffect.onThink(interval)
    for i = 1, #effects do
        local settings = effects[i]
        local spectators = Game.getSpectators(settings.position, false, true, 7, 7, 5, 5)
        if #spectators > 0 then
            if settings.text then
                for i = 1, #spectators do
                    spectators[i]:say(settings.text, TALKTYPE_MONSTER_SAY, false, spectators[i], settings.position)
                end
            end
            if settings.effect then
                settings.position:sendMagicEffect(settings.effect)
            end
        end
    end
   return true
end

tileeffect:interval(10000)
tileeffect:register()
Works fine for me 🤔
Add print('onThink: '.. interval) to make sure it's executing at the right interval, if not then your sources are probably outdated.
 
He's using OTServBR, I just noticed they have a missing line, that's why it's not working
under line 16824 (luascript.cpp) paste this
C:
globalevent->setInterval(getNumber<uint32_t>(L, 2));
@Evil Puncker
 
is there an easy way to auto register actionIDs on the script? for example:

I have a moveevent that have 3 tables that uses different actionIDs, they may repeat or not:


(posted on pastebin because there is some weird error on the code tag right now)

edit:
also, how do we register the position of a script? like the antitrasher from this post

XML:
<movevent event="AddItem" pos="1110;994;8" script="trash_prevent.lua"/> <!-- {x = 1110, y = 994, z = 8} -->
Lua:
local item_exceptions = {2152, 2160, 5792, 5793, 5794, 5795, 5796, 5797}

function onAddItem(item, tile, pos)
    if not isInArray(item_exceptions, item.itemid) then
        doRemoveItem(item.uid)
    end
    return true
end
 
is there an easy way to auto register actionIDs on the script? for example:

I have a moveevent that have 3 tables that uses different actionIDs, they may repeat or not:


(posted on pastebin because there is some weird error on the code tag right now)

edit:
also, how do we register the position of a script? like the antitrasher from this post

XML:
<movevent event="AddItem" pos="1110;994;8" script="trash_prevent.lua"/> <!-- {x = 1110, y = 994, z = 8} -->
Lua:
local item_exceptions = {2152, 2160, 5792, 5793, 5794, 5795, 5796, 5797}

function onAddItem(item, tile, pos)
    if not isInArray(item_exceptions, item.itemid) then
        doRemoveItem(item.uid)
    end
    return true
end
1)
Lua:
for k,v in pairs(table) do
    tileStepIn2:aid(k)
end
repeat that with the other tables aswell.

2) I havn't added that yet it seems, open an issue on github so I don't forget about adding it.
 
I made a thing!

-- script

[TalkAction] God to Player/Player to God

-
Now you're chasing botters,
Now you're adventuring with your players.

-

Instructions:
• Needs account type 5 in database.
/creative to enter God mode.
• /survival to enter Player mode.

Original: TalkAction - /adm to turn GOD, / player to turn PLAYER (https://otland.net/threads/adm-to-turn-god-player-to-turn-player.262661/)

Lua:
-- data/scripts/(optional)talkactions
-- admplayer.lua

local creative = TalkAction("/creative")

function creative.onSay(player, words)
    if player:getAccountType() == 5 then
        local position = player:getPosition()
        player:setGroup(Group(3))
        position:sendMagicEffect(14)
        player:remove()
    end
    return false
end

creative:separator(" ")
creative:register()

local survival = TalkAction("/survival")

function survival.onSay(player, words)
    if player:getAccountType() == 5 then
        local position = player:getPosition()
        player:setGroup(Group(1))
        position:sendMagicEffect(13)
        player:remove()
    end
    return false
end

survival:register()
 
request this makesay command from mrsheen ot :p
 
Back
Top