• 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 Check player's resistances with LUA?

andu

Sold 649 scripts, 25 maps and 9 events!
Joined
Aug 7, 2009
Messages
969
Solutions
17
Reaction score
354
GitHub
olrios
Twitch
olrios
Lua or C++
TFS 1.2

How to check creature's elemental resistances via lua?
Ex. playerhave stone skin equipped, how to check how much death resi he have? etc
 
You cannot!
Well, to rephrase, you cannot do it in pure lua, it requires a source edit. You'd be looking to expose the abilities struct info to Lua through luascript.cpp. Here's an example of how it's used (this is located in Player::blockHit)
C++:
const int16_t& absorbPercent = it.abilities->absorbPercent[combatTypeToIndex(combatType)];
The it variable is the ItemType reference, .abilities accesses the abilities pointer and ->absorbPercent accesses the array of absorb index -> percent values (the key is the combat type, as you can see it uses combatTypeToIndex).
To do what you want, you'd need to create a new function for the ItemType class in luascript.cpp to take in a combat type and access itemtype abilities.absorbPercent with that index (assuming it.abilities exists before using it, otherwise you'll crash) and return that value.
 
Last edited:
I immediately edited my post, but my original answer was for your question asking specifically Lua-only, by which it is impossible.

You can read other files via lua. Making a script what will check for items.xml "if player" or ex. demon.xml if target is creature isn't something impossible. Also to reduce resource consumption it may work like a lib so it won't read over and over 1Mb+ file items.xml. It will load important parts only once and then script will read from memory.

Anyway scripting it via lua will take much more time then time I need to spend to learn how to make it via source edit. Also second method gives more experience.
 
You can read other files via lua. Making a script what will check for items.xml "if player" or ex. demon.xml if target is creature isn't something impossible. Also to reduce resource consumption it may work like a lib so it won't read over and over 1Mb+ file items.xml. It will load important parts only once and then script will read from memory.

Anyway scripting it via lua will take much more time then time I need to spend to learn how to make it via source edit. Also second method gives more experience.
Maybe I should've rephrased again, it's impossible without doing stupid things / workarounds.
I've already done what you're talking about as a portion of a bigger project, making abilities dynamic rather than static: Lua Function - [TFS 1.3] Item abilities via Lua (https://otland.net/threads/tfs-1-3-item-abilities-via-lua.260156/)
 
Back
Top