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

Use moveuse.dat instead of actions & movements

I've done it for TFS, using an interpreter for the moveuse.dat, it's quite simple, although, I stopped using it simply because scripting in it is a pain in the butt, if RME had an implementation for this (map based scripting, aka; actions, like RPG Maker XP) would be much simpler, and I'm 100% sure that's how CipSoft does with their moveuse.dat
 
I've done it for TFS, using an interpreter for the moveuse.dat, it's quite simple, although, I stopped using it simply because scripting in it is a pain in the butt, if RME had an implementation for this (map based scripting, aka; actions, like RPG Maker XP) would be much simpler, and I'm 100% sure that's how CipSoft does with their moveuse.dat
Exactly, some work on RME is needed, I was aware of that. I'm looking to work the same way with npcs, much more easy than TFS, you can delete a lot of folders (actions, movements, etc...) and work focused on few files.
 
Using moveuse.dat is really stupid and i also have read ezz blog and i was already aware how it was stupid to remove the lua scripting system preventing any scripter of building custom systems/scripts.
The current tfs/opentibia system is really old and a bit stupid and its really bad when you need to build complex systems in lua. The condition -> action system from moveuse.dat is cool and helps a lot when you want to build simple scripts and it can also be improved with custom conditions and custom actions to build more complex scripts/systems.

What can be done is quit "simple": build a next generation moveuse.dat lua system to handle the conditions and actions and rework the actions.cpp and movements.cpp to pass the events to the lua system. I would also rework the creaturescript system but its another subject.

Ps: Using xml to register events/actions/movements is really stupid.
 
yeah, why not start using a big fucking file with all movements, actions and more in one big damn file so you have no idea where to look to fix a quest that has bugs at 3 layers.

So much better than a folder with different files for each quest/action..

No but really... it's just stupid storing everything in one file, it make it horrible working with
 
I prefer one file for actions/movements/quests. The way it works is easys. I don't want to mess with xml, lua, multiple storages, actionids, uniqueids.... It's a mess
Monster files are way better, npcs a lot easier to implement. Make a quest now involves to work on 10 files, map, mess with ids... When you are doing a long quest it's a hell (ape city quest, djinn quest...)

Cipsoft: something goes wrong, it's easy to fix. One lever that doesn't work? go to moveuse.dat and fix the line.

OTs: someting goes wrong...One lever doesn't work. Go to actions.xml, try to figure what is wrong (actionid, uniqueid...) go to .lua and make 10 tries to fix. Fix id or whatever on map... Still bugged. Check position of switch that leads to action or not. Become madness...
 
You can already make with lua a system to write a quest on single file which registers your actions, movements, creaturesescrips, event automatically.

I have all my different scripts and system written on their own file. Im not messing arounf with xmls and stuff, but i still have them in data because i havent changed anything in source.

If any of you ever going to improve the organisation of TFS let me know, i have already bretty good, practical and working version made with lua
 
if RME had an implementation for this (map based scripting, aka; actions, like RPG Maker XP)
That's pretty cool idea. And i think it's imaginable, at least for more simple scripts.

Using moveuse.dat is really stupid and i also have read ezz blog and i was already aware how it was stupid to remove the lua scripting system preventing any scripter of building custom systems/scripts.
The current tfs/opentibia system is really old and a bit stupid and its really bad when you need to build complex systems in lua. The condition -> action system from moveuse.dat is cool and helps a lot when you want to build simple scripts and it can also be improved with custom conditions and custom actions to build more complex scripts/systems.

What can be done is quit "simple": build a next generation moveuse.dat lua system to handle the conditions and actions and rework the actions.cpp and movements.cpp to pass the events to the lua system. I would also rework the creaturescript system but its another subject.

Ps: Using xml to register events/actions/movements is really stupid.
Completely agreed. It's lacking of more flexibility.

You can already make with lua a system to write a quest on single file which registers your actions, movements, creaturesescrips, event automatically.

I have all my different scripts and system written on their own file. Im not messing arounf with xmls and stuff, but i still have them in data because i havent changed anything in source.

If any of you ever going to improve the organisation of TFS let me know, i have already bretty good, practical and working version made with lua
So maybe you could just post it in Resources. Everyone intrested in it, would make a good use to your system.
And if not, it can just lay down there. Because why not.
 
You can already make with lua a system to write a quest on single file which registers your actions, movements, creaturesescrips, event automatically.

I have all my different scripts and system written on their own file. Im not messing arounf with xmls and stuff, but i still have them in data because i havent changed anything in source.

If any of you ever going to improve the organisation of TFS let me know, i have already bretty good, practical and working version made with lua
Can you post an example?
 
This the full central configuration guide table which on server startup is read and used to link functions or generate content.
I removed lot of custom stuff from it and left in some detail guides so its easier to grasp.
To some it can feel like wtf mess, but for me, I like having an option to configurate any aspect of game in a single config table.
It doesn't mean I have 1 huge configuration table (well I do), but there is like small central table per .lua file which is merged into 1 big one.

Im not sure how up to date this guide is, I often forget to update guides when I add new features do them.
Code:
--[[ centralT config guide
    constructions = {}                  config guide: actions > tables > constructions.lua
    area = {                            config guide: globalevents > tables > startup.lua
        regions = {STR}                 centralT names which generate areaCorners
    }                          
   
    registerEvent = {                   adds these events to monster when they are created to game
        [STR] = {                       "onThink", "onDeath", "onHealthChange"
            [STR] = {                   monstername
                STR,                    eventName
            }
        }
    }
    
    npcArea = {}                        config guide: npc > npcConfig.lua
    npcChat = {}                        config guide: npc > npcConfig.lua
    npcShop = {}                        config guide: npc > npcConfig.lua
   
    discover = {}                       config guide: movements > tables > area discover.lua
    monsterSpawns = {}                  config guide: creaturescrips > tables > respawn.lua
    deathArea = {}                      config guide: creaturescrips > tables > death area.lua
    modalWindows = {}                   config guide: creaturescrips > tables > modalWindows.lua
    randomLoot = {}                     config guide: actions > tables > randomLoot.lua
    itemRespawns = {}                   config guide: globalevents > TABLES > item respawnT.lua
    keys = {}                           config guide: missing | functions: keySystem() | example: quests > treasure hunt.lua
    monsters = {}                       config guide: monsters > monsters.lua
    monsterResistance = {}              config guide: creaturescrips > tables > monster resistances.lua
    monsterLoot = {}                    config guide: creaturescrips > tables > monster loot.lua
    monsterSpells = {}                  config guide: spells > monster_spells > configuration.lua
    hcRooms = {}                        config guide: creaturescrips > tables > hardcore room.lua
    bossRoom = {}                       config guide: creaturescrips > tables > boss rooms.lua
    items = {}                          config guide: items > itemTable.lua
   
    onLogin = {}                        config guide: actions > tables > actionSystemConfig.lua
    onMove = {}                         before action_onMove
    onMove2 = {}                        after action_onMove
    IDItems = {}                       
    IDItems_onLook = {}                  
    IDItems_onMove = {}                
    AIDItems = {}                      
    AIDItems_onLook = {}
    AIDItems_onMove = {}
    IDTiles_stepIn = {}
    IDTiles_stepOut = {}
    AIDTiles_stepIn = {}
    AIDTiles_stepOut = {}
   
    -automatic
    roomT = posT    all positions if upCorner and downCorner used
]]
This is my entire actions.xml
Yes there are some things still not included into actionSystem, but even still some of these things are linked to central system.
Mostly because this central thing is ~6 month old idea or so and haven't updated entire data folder around that yet.
The future idea is to remove all itemID's from actions and replace it with actionID's
So I that I have only 2 types of xml registrations: automatic between id to id and special cases.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <!-- AUTOMATIC REGISTRATION -->
        <action fromaid="2000"  toaid="2300"    script="AIDItems.lua"/>
       
    <!-- SPECIAL CASES -->
        <action actionid="1098"                 script="AIDItems.lua"/>
       
    <!-- TEMPORARY -->
        <action itemid="2272"                   script="TEMPORARY/dispelItem.lua"           allowfaruse="1"/>
        <action itemid="2282"                   script="TEMPORARY/mendItem.lua"             allowfaruse="1"/>
        <action itemid="7434"                   script="TEMPORARY/throwaxeItem.lua"         allowfaruse="1"/>
        <action itemid="7696"                   script="IDItems.lua"/>                  <!-- old spellScroll -->
       
    <!-- upgrade items -->
        <action itemid="2312"                   script="IDItems.lua"/>                  <!-- sight stone-->
        <action itemid="2264"                   script="IDItems.lua"/>                  <!-- defence stone-->
        <action itemid="2297"                   script="IDItems.lua"/>                  <!-- crit stone-->
        <action itemid="2290"                   script="IDItems.lua"/>                  <!-- movement speed stone-->
        <action itemid="2263"                   script="IDItems.lua"/>                  <!-- death Stone -->
        <action itemid="2271"                   script="IDItems.lua"/>                  <!-- energy Stone -->
        <action itemid="2265"                   script="IDItems.lua"/>                  <!-- armor (4)-->
        <action itemid="2267"                   script="IDItems.lua"/>                  <!-- armor (3)-->
        <action itemid="2266"                   script="IDItems.lua"/>                  <!-- critical block -->
        <action itemid="2286"                   script="IDItems.lua"/>                  <!-- skill Stone -->
        <action itemid="8305"                   script="Upgrades/gems.lua"/>            <!-- physical gem -->
        <action itemid="2147"                   script="Upgrades/gems.lua"/>            <!-- fire gem -->
        <action itemid="9970"                   script="Upgrades/gems.lua"/>            <!-- ice gem -->
        <action itemid="2146"                   script="Upgrades/gems.lua"/>            <!-- energy gem -->
        <action itemid="2150"                   script="Upgrades/gems.lua"/>            <!-- death gem -->
        <action itemid="2149"                   script="Upgrades/gems.lua"/>            <!-- earth gem -->
   
    <!-- WEAPONS -->
        <action itemid="13760"                  script="Weapons/immortal kamikaze.lua"  allowfaruse="1" />
        <action itemid="15647"                  script="Weapons/purifying mallet.lua"   allowfaruse="1" />
        <action itemid="15400"                  script="Weapons/yashinuken.lua"         allowfaruse="1" />
       
    <!-- containers -->
        <action itemid="13506"                  script="IDItems.lua"/>              <!-- herb bag -->
        <action itemid="18394"                  script="IDItems.lua"/>              <!-- gem bag -->
        <action itemid="18393"                  script="IDItems.lua"/>              <!-- seed bag -->
       
        <action itemid="3113"                   script="Containers/ghoul.lua"/>
        <action itemid="2591"                   script="Containers/depot.lua"/>
        <action itemid="1746"                   script="Containers/depot chest.lua"/>
        <action itemid="9076"                   script="Containers/token bag.lua"/>
        <action itemid="9775"                   script="Containers/gem pouch.lua"/>
   
    <!-- Teleports -->
        <action itemid="1590"                   script="IDItems.lua"/>              <!-- Jump on rails -->
        <action itemid="1591"                   script="IDItems.lua"/>              <!-- Jump on rails -->
        <action itemid="22124"                  script="IDItems.lua"/>              <!-- Jump on rails -->
        <action itemid="21874"                  script="IDItems.lua"/>              <!-- Jump on rails -->
        <action itemid="1386"                   script="IDItems.lua"/>              <!-- ladder up -->
        <action itemid="3678"                   script="IDItems.lua"/>              <!-- ladder up -->
        <action itemid="5543"                   script="IDItems.lua"/>              <!-- ladder up -->
        <action itemid="8786"                   script="IDItems.lua"/>              <!-- treestump -->
   
    <!-- Brewing & Cooking relates -->
        <action itemid="10031"                  script="IDItems.lua"/>              <!-- unfinishd potion -->
        <action itemid="2785"                   script="IDItems.lua"/>              <!-- berryBush -->
        <action fromid="2005"   toid="2006"     script="IDItems.lua"/>              <!-- fluidContainer_onUse -->
        <action fromid="2012"   toid="2014"     script="IDItems.lua"/>              <!-- fluidContainer_onUse -->
        <action itemid="12287"                  script="IDItems.lua"/>              <!-- empty bowl -->
        <action itemid="12289"                  script="IDItems.lua"/>              <!-- filled bowl -->
       
       
    <!-- other -->
        <action fromid="1634"   toid="1637"     script="IDItems.lua"/>              <!-- openable tables -->
        <action itemid="7935"                   script="IDItems.lua"/>              <!-- potion stand -->
        <action itemid="7934"                   script="IDItems.lua"/>              <!-- test tube -->
        <action itemid="2456"                   script="other/autoEquip.lua"/>      <!-- bow -->
        <action itemid="7367"                   script="other/autoEquip.lua"/>      <!-- regenerative spear -->
        <action itemid="2389"                   script="other/autoEquip.lua"/>      <!-- bonetip spear -->
        <action itemid="2148"                   script="other/changegold.lua"/>
        <action itemid="2152"                   script="other/changegold.lua"/>
        <action itemid="2160"                   script="other/changegold.lua"/>
        <action itemid="3871"                   script="IDItems.lua"/>              <!-- stack of logs -->
        <action itemid="2050"                   script="IDItems.lua"/>              <!-- lit the torch -->
        <action itemid="2051"                   script="IDItems.lua"/>              <!-- unlit torch -->
        <action itemid="5779"                   script="IDItems.lua"/>              <!-- stuck arrow -->
        <action itemid="5780"                   script="IDItems.lua"/>              <!-- stuck arrow -->
        <action itemid="5781"                   script="IDItems.lua"/>              <!-- stuck arrow -->
        <action itemid="5782"                   script="IDItems.lua"/>              <!-- stuck arrow -->
        <action itemid="5783"                   script="IDItems.lua"/>              <!-- stuck arrow -->
        <action itemid="5784"                   script="IDItems.lua"/>              <!-- stuck arrow -->
        <action itemid="5789"                   script="IDItems.lua"/>              <!-- stuck axe -->
        <action itemid="5790"                   script="IDItems.lua"/>              <!-- stuck axe -->
       
    <!-------Things what were here before ------------------------------------------>
        <action itemid="14405" function="market"/>
</actions>

This is one of the smallest central tables in use.
as you can see I direct actionID to a function and the function is written on the same file.
I don't don't have to open action.xml if the AID falls between 2000 - 2300
If its not in that range, then I think function doesn't activate and I need to register it in special cases or expand the AID numbers.
Its not a problem to register actionID's what you don't have in game yet.

Striked out files are not Whi World stuff
2lj14cl.jpg

This is how I write same concept features/quests/systems/etc on a single file.
I still have the events, actions, movements etc, but the idea is to have only 1 function for each of them which either generates code or uses function from another file.

Here is a function for actionID items.
Code:
function onUse(player, item, fromPos, itemEx, toPos, isHotkey)
local itemAID = item:getActionId()
local t = AIDItems[itemAID]
   
    if not itemEx or type(itemEx) == "table" then itemEx = checkForItemEx(itemEx, toPos) end
    if t then return executeActionSystem(player, item, t, itemEx, fromPos, toPos) end
end

function actionSystem_onMoveFunctions(player, item, fromPos, toPos, fromObject, toObject)
    for _, moveT in ipairs(onMoveT) do
        local returnValue = executeActionSystem(player, item, moveT, nil, fromPos, toPos, fromObject, toObject)
        if returnValue then return true end
    end
local actionT = AIDItems_onMove[item:getActionId()] or IDItems_onMove[item:getId()]
   
    if actionT then return executeActionSystem(player, item, actionT, nil, fromPos, toPos, fromObject, toObject) end
   
    for _, moveT in ipairs(onMoveT2) do
        local returnValue = executeActionSystem(player, item, moveT, nil, fromPos, toPos, fromObject, toObject)
        if returnValue then return true end
    end
end

Can you post an example?
Is this what you meant as an example?

he always post examples, almost all his codes posted in here are based on his script templates
Is it a bad thing or a good thing? I can stop if my ideas don't get trough or are useless for everyone else, but me.
 
If you guys wants to develop such a thing i would recommend the launch of a tfs 1.3 fork github repository to people work together on the prototype. With real code and examples such thing can come out of the paper/people minds, otherwise it will just be another discussion.

I had this working good on tfs 1.2:

Code:
--Use, IsType (Obj1,2948) -> Effect(Obj1,19)
Use(
    IsType(ACTIONVAR_OBJ1, 16112), "->", Effect(ACTIONVAR_OBJ1,CONST_ME_FERUMBRAS)
)

Use(
    IsType(ACTIONVAR_OBJ1, 2701), IsPosition(ACTIONVAR_OBJ1, 200, 444, 7), "->", Effect(ACTIONVAR_OBJ1,CONST_ME_FERUMBRAS)
)



--ACTIONVAR_OBJ1: the object being used

--two different bushs, the only thing that changes is the position
Use(
    IsType(ACTIONVAR_OBJ1, 2767), IsPosition(ACTIONVAR_OBJ1, 253, 415, 7), "->", Effect(ACTIONVAR_OBJ1, CONST_ME_ORCSHAMAN)
)

Use(
    IsType(ACTIONVAR_OBJ1, 2767), IsPosition(ACTIONVAR_OBJ1, 258, 419, 7), "->", Effect(ACTIONVAR_OBJ1, CONST_ME_THUNDER)
)

--own callback
local function onUseBush(vars, fromPosition, isHotkey)
    local blueberryCount = 3
   
    vars[ACTIONVAR_OBJ1]:transform(2786)
    vars[ACTIONVAR_OBJ1]:decay()
   
    for loop = 1, blueberryCount do
        Game.createItem(2677, 1, fromPosition)
    end
   
    return true
end

Use(
    IsType(ACTIONVAR_OBJ1, 2785), "->", onUseBush
)

The way its done in lua looks ugly but the idea is here(if conditions are meet, the actions will be executed).
 
A better way to describe the condition -> action system:

Code:
USE(
    CONDITION(
        IsType(ACTIONVAR_OBJ1, 2701),
        IsPosition(ACTIONVAR_OBJ1, 200, 444, 7)
    ),
    ACTION(
        Effect(ACTIONVAR_OBJ1,CONST_ME_FERUMBRAS)
    )
)

Age of empires 2 scripting system uses "facts"(conditions) and actions:
Rules are how you tell the computer when to change what. Here's the setup of a rule.

(defrule [this just says "Hey, this is the start of a rule!"]
(fact 1)
(fact 2)
...
(fact x)

=> [this symbol indicates the transition from facts to actions]
(action 1)
(action 2)
...
(action x))

Comunidade Steam :: Guia :: Scripting AI for: Age of Empires II
 
Lua:
dofile('data/actions/actionSystem.lua')

--USE, IsType (Obj1,2948) -> Effect(Obj1,19)

-- sound

USE(
    CONDITION(
        IsType(ACTIONVAR_OBJ1, 2070)
    ),
   
    ACTION(
        EffectAction(ACTIONVAR_OBJ1, CONST_ME_SOUND_GREEN)
    )
)

-- the only condition is the position
-- better than using an action id or unique id on a certain item in that position

USE(
    CONDITION(
        IsPosition(ACTIONVAR_OBJ1, 234, 420, 6)
    ),
   
    ACTION(
        EffectAction(ACTIONVAR_OBJ1, CONST_ME_FERUMBRAS)
    )
)

--bush

local function onUseBush(vars, fromPosition, isHotkey)
    local blueberryCount = 3
   
    vars[ACTIONVAR_OBJ1]:transform(2786)
    vars[ACTIONVAR_OBJ1]:decay()
   
    for loop = 1, blueberryCount do
        Game.createItem(2677, 1, fromPosition)
    end
   
    return true
end

USE(
    CONDITION(
        IsType(ACTIONVAR_OBJ1, 2785)
    ),
   
    ACTION(
        onUseBush
    )
)

-- teleports

local upFloorIds = {1386, 3678, 5543}

function onUseTeleport(vars, fromPosition, isHotkey)
    if table.contains(upFloorIds, vars[ACTIONVAR_OBJ1ID]) then
        fromPosition:moveUpstairs()
    else
        fromPosition.z = fromPosition.z + 1
    end
   
    local player = vars[ACTIONVAR_USER]

    if player:isPzLocked() and Tile(fromPosition):hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
        return true
    end

    player:teleportTo(fromPosition, false)
    return true
end

USE(
    CONDITION(
        IsType(ACTIONVAR_OBJ1, 430)
    ),
   
    ACTION(
        onUseTeleport
    )
)

-- doors

function onUseDoor(vars, fromPosition, isHotkey)
    local itemId = vars[ACTIONVAR_OBJ1ID]
    local player = vars[ACTIONVAR_USER]
    local item = vars[ACTIONVAR_OBJ1]
    local toPosition = fromPosition
   
    if table.contains(questDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(levelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Only the worthy may pass.")
        end
        return true
    elseif table.contains(keys, itemId) then
        if target.actionid > 0 then
            if item.actionid == target.actionid and doors[target.itemid] then
                target:transform(doors[target.itemid])
                return true
            end
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        return false
    end

    if table.contains(horizontalOpenDoors, itemId) or table.contains(verticalOpenDoors, itemId) then
        local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature ~= nil then
            toPosition.x = toPosition.x + 1
            local query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
            if query ~= RETURNVALUE_NOERROR then
                toPosition.x = toPosition.x - 1
                toPosition.y = toPosition.y + 1
                query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
            end

            if query ~= RETURNVALUE_NOERROR then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, query)
                return true
            end

            doorCreature:teleportTo(toPosition, true)
        end

        if not table.contains(openSpecialDoors, itemId) then
            item:transform(itemId - 1)
        end
        return true
    end

    if doors[itemId] then
        if item.actionid == 0 then
            item:transform(doors[itemId])
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        end
        return true
    end
   
    return false
end

for doorItemId, _ in pairs(doors) do
    USE(
        CONDITION(
            IsType(ACTIONVAR_OBJ1, doorItemId)
        ),
       
        ACTION(
            onUseDoor
        )
    )
end

for _, list in ipairs({horizontalOpenDoors, verticalOpenDoors}) do
    for _, doorItemId in ipairs(list) do
        USE(
            CONDITION(
                IsType(ACTIONVAR_OBJ1, doorItemId)
            ),
           
            ACTION(
                onUseDoor
            )
        )
    end
end

-- food

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
}

function onUseFood(vars, fromPosition, isHotkey)
    local itemId = vars[ACTIONVAR_OBJ1ID]
    local player = vars[ACTIONVAR_USER]
    local item = vars[ACTIONVAR_OBJ1]
    local toPosition = fromPosition
   
    local food = foods[itemId]
    if not food then
        return false
    end

    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and math.floor(condition:getTicks() / 1000 + (food[1] * 12)) >= 1200 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are full.")
    else
        player:feed(food[1] * 12)
        player:say(food[2], TALKTYPE_MONSTER_SAY)
        item:remove(1)
    end
   
    return true
end


for foodItemId, _ in pairs(foods) do
    USE(
        CONDITION(
            IsType(ACTIONVAR_OBJ1, foodItemId)
        ),
       
        ACTION(
            onUseFood
        )
    )
end

print('Actions reloaded!!!')

Better example here.

@tarantonio @2Rec @Ezzz @StreamSide @whitevo @OpenTibiaServer
 
Back
Top