• 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.X+ [TFS 1.5] Attribute problems (onHealthChange & getMana)

Erna

Moraliskt Stöd
Joined
Oct 26, 2009
Messages
40
Reaction score
19
Location
Sweden
Using; tfs 1.5 together with the alkarius 1.3 and the attribute crafting system that is in the files are currently not up to date and need some code-fixing to work.
I've tried to google and the best help I've found was through puncker to add a few lines in compat (which hasn't helped me in the long run, sadly;

Lua:
function doTargetCombatHealth(...) return doTargetCombat(...) end
function doAreaCombatHealth(...) return doAreaCombat(...) end
function doTargetCombatMana(cid, target, min, max, effect) return doTargetCombat(cid, target, COMBAT_MANADRAIN, min, max, effect) end
function doAreaCombatMana(cid, pos, area, min, max, effect) return doAreaCombat(cid, COMBAT_MANADRAIN, pos, area, min, max, effect) end

The two errors I've found so far related to this crafting system can be seen below;

Code:
lua script error: [CreatureScript Interface]
data/scripts/others/stats.lua:onHealthChange
data/stats.lua:1583: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/stats.lua:1583: in function <data/stats.lua:1516


Code:
lua script error: [CreatureScript Interface]
data/scripts/others/stats.lua:onHealthChange
data/stats.lua:1583: attempt to call method 'getMana' a nil value
stack traceback:
[C]: in function 'getMana'
data/stats.lua:1583: in function <data/stats.lua:1516

This one below says "data/script/others/stats.lua and I do not even have the path "data/scripts/others/stats.lua" because the second stats.lua file is in the path "data/creaturescripts/others/stats.lua" so I added one then copy/pasted the lua file and that just ended with another nil value error

Pastebin below to my /data/stats.lua;
data/stats.lua - Pastebin.com (https://pastebin.com/r9epJtVy)

Code to my /data/creaturescripts/others/stats.lua;

Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    return stat_onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
end

function onManaChange(creature, attacker, manaChange, origin)
    return stat_onManaChange(creature, attacker, manaChange, origin)
end

function onPrepareDeath(creature, lastHitKiller, mostDamageKiller)
    return stat_onPrepareDeath(creature, lastHitKiller, mostDamageKiller)
end

function onKill(player, target, lastHit)
    return stat_onKill(player, target, lastHit)
end

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    return stat_onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
end

function onLogin(player)
    return stat_onLogin(player)
end


This is how the creaturescript.xml looks;


Code:
    <event type="login" name="statLogin" script="others/stats.lua"/>
    <event type="healthchange" name="statHP" script="others/stats.lua"/>
    <event type="manachange" name="statMP" script="others/stats.lua"/>
    <event type="preparedeath" name="statPVE" script="others/stats.lua"/>
    <event type="kill" name="statLoot" script="others/stats.lua"/>
    <event type="death" name="statDeath" script="others/stats.lua"/>

I hope I've made any sense, another long night with way too little sleep and way too much tryhard mode haha.

/Thanks in advance, Erna.
 
probably monster its related to this stats system too, so it trying to get mana from monster which it doesnt exsists.

add additional check
below 1519 line
Lua:
if not attacker:isPlayer() then return primaryDamage, primaryType, secondaryDamage, secondaryType end
 
probably monster its related to this stats system too, so it trying to get mana from monster which it doesnt exsists.

add additional check
below 1519 line
Lua:
if not attacker:isPlayer() then return primaryDamage, primaryType, secondaryDamage, secondaryType end
I tried both adding it below the old line
Lua:
    if not attacker then return primaryDamage, primaryType, secondaryDamage, secondaryType end
And also swapping the old line out but sadly, same error pops up (the first of the two I showed in the post)

I also notice that if I have both mana and life steal on the same wep, it doesn't attack at all (But no additional error occurs)

I attempted to remove the manaline for simplicity sake
Code:
if Player(cid):getMana() > 0 then
But that just causes another error completely, see this gyazo below;
Gyazo (https://gyazo.com/113b8e48d9ab1f0abd091bdb8347ee57)

I assume that perhaps nextusestaminatime has been swapped, wordingwise that is, but I've got no idea wheather or not it's related to my issues above or not, since it only appears when I remove the mana string.
 
Lua:
local mana = creature:getMana() or Player(creature):getMana()
if mana > 0 then

Dont see why you even need the or tbh
 
change line 1586
from:
Lua:
if Player(cid):getMana() > 0 then
to
Lua:
if Player(creature:getId()) and creature:getMana() > 0 then
Thanks!
After hitting a training monk for about 10 minutes no error occured in the log, which shows that string work since I couldn't even use the wep that had both hp and mana drain before! Also no errors when using them separatly! you're a gem! :)
Post automatically merged:

Lua:
local mana = creature:getMana() or Player(creature):getMana()
if mana > 0 then

Dont see why you even need the or tbh
The scripting wasn't done by me, I'm still too much of a scrub to be creating such things myself.
Hopefully in the future tho :)
So I've got no idea why they've put it that way, but I'm glad I finally got the errors to disappear haha :)
 
Last edited:
Back
Top