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

Do something Every step

BulawOw

Soul of Shinobi
Joined
Sep 15, 2014
Messages
204
Solutions
8
Reaction score
62
So i want to make script that will take 1 mana for each step but i dont rly see any function for that (i only see onStepIn, and onStepOut) is it possible to make something like i want or i have to make new function in src ?
 
Solution
E
Latest tfs available
And i want to make so player will lose 1 mana each time player moves no matter what tile he step on
I have asked for this as well ages ago, you will have to edite sources yourself to add new function. I think it is not in the official repository because it can be quite intensive on your hardware

this is so easy actually:

add this to data/scripts:

LUA:
local moveevent = MoveEvent()

function moveevent.onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() then
        doTargetCombat(0, creature, COMBAT_MANADRAIN, 1, 1, effect)
    end
    return true
end

moveevent:id(724) -- add ID of tiles that should run this, separated by comma
moveevent:register()

2020-04-18 00_09_11-Tibia - Achei Izi.png
TFS version?
You want a script to hit you by "1" each time you step in specific tile? or each time you only move any where?
 
Latest tfs available
And i want to make so player will lose 1 mana each time player moves no matter what tile he step on
 
I have asked for this as well ages ago, you will have to edite sources yourself to add new function. I think it is not in the official repository because it can be quite intensive on your hardware
 
Latest tfs available
And i want to make so player will lose 1 mana each time player moves no matter what tile he step on
I have asked for this as well ages ago, you will have to edite sources yourself to add new function. I think it is not in the official repository because it can be quite intensive on your hardware

this is so easy actually:

add this to data/scripts:

LUA:
local moveevent = MoveEvent()

function moveevent.onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() then
        doTargetCombat(0, creature, COMBAT_MANADRAIN, 1, 1, effect)
    end
    return true
end

moveevent:id(724) -- add ID of tiles that should run this, separated by comma
moveevent:register()

2020-04-18 00_09_11-Tibia - Achei Izi.png
 
Solution
this is so easy actually:

add this to data/scripts:

LUA:
local moveevent = MoveEvent()

function moveevent.onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() then
        doTargetCombat(0, creature, COMBAT_MANADRAIN, 1, 1, effect)
    end
    return true
end

moveevent:id(724) -- add ID of tiles that should run this, separated by comma
moveevent:register()

View attachment 44422

thats specifying individual tiles but if it works, it works
 
this is so easy

No what the OP asked for though.
each time player moves no matter what tile he step on


I think it is not in the official repository because it can be quite intensive

Actually, it's already there internally, but if exposed by a Lua interface it's providing most people with a way to shoot themselves in the foot, which is what you're really getting at. It's giving the masses just enough rope to hang themselves. Functions bound to it have to be written with extreme care, and a mindset to always return, and to return as fast as possible. Given the state of the support forum, I can see why even presenting the patch needed here would be a terrible idea, so I'm not gonna do it.
 
Maybe inside player.cpp function void Player::onWalk(Direction& dir) or void Player::onCreatureMove(Creature* creature, const Tile* newTile, const Position& newPos, const Tile* oldTile, const Position& oldPos, bool teleport)
You can add line to change mana - this->changeMana(-1);. Didn't tested.
 
No what the OP asked for though.

it would be kinda easy if I had the knowledge to transform the following into a piece of code:

  • get all map item IDs
  • check only the ones that are :getGround()
  • do a:

LUA:
for k, v in pairs(ids) do
    tileStepIn:aid(k)
end

to register them 😄
 
it would be kinda easy if I had the knowledge to transform the following into a piece of code:
  • get all map item IDs

This would miss dynamically loaded maps.

What TFS really needs is libuv. Not Beast. 🤢 But I'm not ready to debate that one upstream yet.

LibUV is amazing, and why NodeJS is so popular. I love LibUV so much I write my shellscripts in Javascript now. It's just that awesome. And some Lua people think it's awesome too.

The ability to create emitters and listeners for arbitrarily named events is powerful. The ability to do it with self destructors? So beautiful, so elegant.
socket.once('scaffoldingEvent', (dataframe)=> { /* code here */ })

If TFS had it, your code could remain useful by calling it once on load, then listening for "onMapChange" and calling it again whenever that happens.

And anyone could still write their own dynamic map chunk loader, and not interfere with others and still interface with your code, they would just have to emit the "MapChange" event. This solves a great many chicken and egg problems. The only thing that would have to be static and unchanging is what data is passed to a given event name.

This would also work great for things like what OP wants, because you can make events explicitly non-blocking and immutable. So the server could emit "creatureStep" event and not care if some poorly written Lua script doesn't function properly, because it wasn't waiting on it anyway.
 
Last edited:

Similar threads

Back
Top