• 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 How to detect if a field was created by a player?

tylerdurden

New Member
Joined
Jan 10, 2022
Messages
17
Reaction score
1
Hello. So we all know the fields have been bugged in TFS since a very long time despite trying to fix them by Nekiro, Zbizu and others... Ive decided to fix them in lua but here comes the problem with field damage. Whenever a player or monster step on the field it always deal 20 damage and it is fine but there should be one exception: if a player step on a field created by other player, it should deal 10 damage and 8 times 5 damage (half). I dont know how to do it in lua, its probably not possible?
I think I would need to get the "attacker" somehow
Lua:
function onStepIn(creature, item, position, fromPosition)
 
    if creature:isPlayer() then
        doTargetCombat(0, creature, COMBAT_FIREDAMAGE, -20, -20, CONST_ME_FIREAREA, true, false, false)
     
        local condition1 = Condition(COMBAT_FIREDAMAGE )
        condition1:setParameter(CONDITION_PARAM_DELAYED, 1)
        condition1:addDamage(8, 8000, -10)
        creature:addCondition(condition1)
    end
 
    if creature:isMonster() then
        if creature:isImmune(CONDITION_FIRE) then
            creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        else
            doTargetCombat(0, creature, COMBAT_FIREDAMAGE, -20, -20, CONST_ME_FIREAREA, true, false, false)
            local condition2 = Condition(COMBAT_FIREDAMAGE )
            condition2:setParameter(CONDITION_PARAM_DELAYED, 1)
            condition2:addDamage(8, 8000, -10)
            creature:addCondition(condition2)
        end
    end
 
    return true
end
 
combat.cpp sets owner of items created by spells:
C++:
Item* item = Item::CreateItem(itemId);
if (caster) {
   item->setOwner(caster->getID());
}
You should be able to read owner:
Lua:
local ownerId = item:getAttribute(ITEM_ATTRIBUTE_OWNER)
if ownerId == 0 then
-- created by script / loaded from map
elseif Player(ownerId) then
-- by player
elseif Monster(ownerId) then
-- by monster
else
-- by monster that died or player that is offline
-- so owner cannot longer 'deal damage' to anyone = field should be treated as loaded from map
end

Since TFS went 12.x+ there is one important change in code:
C++:
void Player::setID() {
   if (id == 0) {
      // allowClones id assignment
      if (g_config.getBoolean(ConfigManager::ALLOW_CLONES)) {
         id = playerAutoID++;
         return;
      }

      // normal id assignment
      if (guid != 0) {
         id = playerAutoID + guid;         // <<<<<<<<<<<<<<<< HERE, it was same as for 'ALLOW_CLONES'
      }
   }
}
Player get SAME cid after relog. It's not longer unique and changed every relog, it's based on GUID.
That change is there, because Tibia 12+ client expects that players have same ID all time - backpack position saving is based on it.
That change gives one known problem with fields: use fire field rune, die, login again, someone walks into fire field -> you get skull in PZ.
 
Back
Top