• 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+ condition_infight

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
Hi, I want to print something to the console when the player is clicking on the item while being beaten up by monsters - that means the player will have that condition called INFIGHT. I did something like this, but it doesn't print anything

Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)

    if player:getCondition(CONDITION_INFIGHT) then
       print("in FIGHT")
       return player:sendCancelMessage("You may not teleport during or immediately after a fight!")
    end

    return true
end
 
do you have it registered in actions.xml?
add a print outside of the if statement to check if it's being run at all
 
do you have it registered in actions.xml?
add a print outside of the if statement to check if it's being run at all

Yes, its registered. This is the script I have used now:

Lua:
print("outside")

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)

    print("inside")
   
    if player:getCondition(CONDITION_INFIGHT) then
        print("in FIGHT")
        player:sendCancelMessage("You may not teleport during or immediately after a fight!")
        return false
    end

    return true
end

after typing /reload actions I get this

QdDiU2s.png


Executed twice for some reason.

and after I press with my mouse on the item, its going to print 'inside' in the console
 
Yes, its registered. This is the script I have used now:

Lua:
print("outside")

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)

    print("inside")
  
    if player:getCondition(CONDITION_INFIGHT) then
        print("in FIGHT")
        player:sendCancelMessage("You may not teleport during or immediately after a fight!")
        return false
    end

    return true
end

after typing /reload actions I get this

QdDiU2s.png


Executed twice for some reason.

and after I press with my mouse on the item, its going to print 'inside' in the console
Lua:
print("outside")
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("inside")
    if player:getCondition(CONDITION_INFIGHT) then
        print("in FIGHT")
        player:sendCancelMessage("You may not teleport during or immediately after a fight!")
        return false
    end
    return true
end
 
If you are using tfs 1.2+ use player instead of cid in onUse function.

it's 1.0 so I have to use cid

Lua:
print("outside")
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("inside")
    if player:getCondition(CONDITION_INFIGHT) then
        print("in FIGHT")
        player:sendCancelMessage("You may not teleport during or immediately after a fight!")
        return false
    end
    return true
end

with the 'player' instead of cid I get an error. but the same thing happens here. I even switched the ID's in the xml file to use it with different item

XML:
<action itemid="7636" script="myItem.lua"/>
 
Fixed, just add CONDITIONID_DEFAULT because otherwise by default it's set to CONDITIONID_COMBAT which won't work with CONDITION_INFIGHT:

Lua:
    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then 
        print("in FIGHT")
        player:sendCancelMessage("You may not teleport during or immediately after a fight!")
        return false
    end
 
Back
Top