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

Differentiate CONDITION_INFIGHT?

Fischturd

Member
Joined
Jan 30, 2023
Messages
26
Reaction score
5
GitHub
Fischturd
Hello, is there a way to differentiate the condition_infight?

Take this script for example;
Lua:
local teleportScroll = Action()

function teleportScroll.onUse(player, item, fromPos, target, toPos, isHotkey)
    if player:hasCondition(CONDITION_INFIGHT) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can't teleport in combat.")
        return false
    end
    
    local playerPos = player:getPosition()
    local tile = Tile(playerPos)
    local town = player:getTown()
    local templePos = town and town:getTemplePosition() or Town(1):getTemplePosition()
    playerPos:sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(templePos)
    templePos:sendMagicEffect(CONST_ME_TELEPORT)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Welcome home adventurer!")
    item:transform(item:getId(), item:getCharges() -1)
    return true
end

teleportScroll:id(6119)
teleportScroll:register()

If I want to differentiate combat vs monsters and players, are you able to?

So example;
I want to be able to use the teleport scroll if you are in combat with a monster

however

If you attack a player or player attacks you, you cannot teleport then

How do you achieve that?
 
Lua:
local teleportScroll = Action()

function teleportScroll.onUse(player, item, fromPos, target, toPos, isHotkey)
    local isInCombat = false

    local targetCreature = Creature(target)
    if targetCreature then
        if targetCreature:isPlayer() then
            -- Player vs. Player combat
            isInCombat = player:isPzLocked() or player:getSkull() ~= SKULL_NONE or targetCreature:isPzLocked() or targetCreature:getSkull() ~= SKULL_NONE
        else
            isInCombat = player:isInCombat()
        end
    end
    
    if isInCombat then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can't teleport while in combat.")
        return false
    end
    
    local playerPos = player:getPosition()
    local tile = Tile(playerPos)
    local town = player:getTown()
    local templePos = town and town:getTemplePosition() or Town(1):getTemplePosition()
    playerPos:sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(templePos)
    templePos:sendMagicEffect(CONST_ME_TELEPORT)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Welcome home, adventurer!")
    item:transform(item:getId(), item:getCharges() - 1)
    return true
end

teleportScroll:id(6119)
teleportScroll:register()
 
Lua:
local teleportScroll = Action()

function teleportScroll.onUse(player, item, fromPos, target, toPos, isHotkey)
    local isInCombat = false

    local targetCreature = Creature(target)
    if targetCreature then
        if targetCreature:isPlayer() then
            -- Player vs. Player combat
            isInCombat = player:isPzLocked() or player:getSkull() ~= SKULL_NONE or targetCreature:isPzLocked() or targetCreature:getSkull() ~= SKULL_NONE
        else
            isInCombat = player:isInCombat()
        end
    end
   
    if isInCombat then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can't teleport while in combat.")
        return false
    end
   
    local playerPos = player:getPosition()
    local tile = Tile(playerPos)
    local town = player:getTown()
    local templePos = town and town:getTemplePosition() or Town(1):getTemplePosition()
    playerPos:sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(templePos)
    templePos:sendMagicEffect(CONST_ME_TELEPORT)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Welcome home, adventurer!")
    item:transform(item:getId(), item:getCharges() - 1)
    return true
end

teleportScroll:id(6119)
teleportScroll:register()
Thank you for the fast response,
It did not seem to go into affect however

I have tried both ways, if you are skulled you can teleport.. also if you are getting attacked by player you still can teleport

Funny to see a skulled player teleport into PZ :D
I forgot to mention I am using TFS 1.4.2
 
Thank you for the fast response,
It did not seem to go into affect however

I have tried both ways, if you are skulled you can teleport.. also if you are getting attacked by player you still can teleport

Funny to see a skulled player teleport into PZ :D
I forgot to mention I am using TFS 1.4.2
Not sure with the current TFS, if you're able to distinguish that a player is attacking you (no pz lock, but in combat i.e running away from white skull that has attacked you)

However, this will stop an aggressive player from teleporting.
Lua:
local teleportScroll = Action()

function teleportScroll.onUse(player, item, fromPos, target, toPos, isHotkey)
    if player:hasCondition(CONDITION_INFIGHT) or player:isPzLocked() or player:getSkull() ~= SKULL_NONE then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can't teleport in combat.")
        return false
    end
    
    local playerPos = player:getPosition()
    local town = player:getTown()
    local templePos = town and town:getTemplePosition() or Town(1):getTemplePosition()
    playerPos:sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(templePos)
    templePos:sendMagicEffect(CONST_ME_TELEPORT)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Welcome home adventurer!")
    item:transform(item:getId(), item:getCharges() -1)
    return true
end

teleportScroll:id(6119)
teleportScroll:register()
 
Back
Top