Lua Remove CONDITION_INFIGHT

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
425
Best answers
13
Reaction score
69
some players report that they get infinite pzlocked, so I thought about it ...
but don't work =x
Lua:
function onThink(player)
   local fightCondition = player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)
   if fightCondition == nil then
    if fightCondition:getTicks(configManager.getNumber(configKeys.PZ_LOCKED) > 900000) then
        player:removeCondition(CONDITION_INFIGHT)
        print(math.floor(fightCondition:getTicks() / 1000))
    end
   end
   return true
end
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/removepk.lua:onThink
data/creaturescripts/scripts/custom/removepk.lua:4: attempt to index local 'fightCondition' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/removepk.lua:4: in function <data/creaturescripts/scripts/custom/removepk.lua:1>
 
OP
M

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
425
Best answers
13
Reaction score
69
Code:
if fightCondition then
I look for a solution(if exist) for it
Lua:
if fightCondition:getTicks(configManager.getNumber(configKeys.PZ_LOCKED) > 900000) then
 

Animera

* * * * *
Premium User
Joined
Dec 9, 2008
Messages
2,274
Best answers
2
Reaction score
429
Location
ANIMERA.ONLINE
Does
Code:
getTicks
Actually returns the amount of ticks that a condition has gone through? or just checking it's condition attributes?

If it is the first case it should work i guess?
Code:
if fightCondition:getTicks(configManager.getNumber(configKeys.PZ_LOCKED)) > 900000 then
What are you trying to achieve? What goes wrong? Any error logs?

Animera
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Joined
Mar 16, 2017
Messages
451
Best answers
41
Reaction score
271
Location
London
Code:
function onThink(player, interval)
    local fightCondition = player:getCondition(CONDITION_INFIGHT)
    if fightCondition then
        if player:getStorageValue(252525) >= configManager.getNumber(configKeys.PZ_LOCKED) then
            player:removeCondition(CONDITION_INFIGHT)
            player:setStorageValue(252525, 0)
        else
            player:setStorageValue(252525, player:getStorageValue(252525) + interval)
        end
    end
    return true
end
 
OP
M

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
425
Best answers
13
Reaction score
69
in this case show countdown of pz, or time
60
59
58
57
56
55
54
53
52
51
50
Does
Code:
getTicks
Actually returns the amount of ticks that a condition has gone through? or just checking it's condition attributes?
dont work =x
If it is the first case it should work i guess?
Code:
if fightCondition:getTicks(configManager.getNumber(configKeys.PZ_LOCKED)) > 900000 then
error
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/removepk.lua:onThink
data/creaturescripts/scripts/custom/removepk.lua:4: attempt to index local 'fightCondition' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/removepk.lua:4: in function <data/creaturescripts/scripts/custom/removepk.lua:1>
What are you trying to achieve? What goes wrong? Any error logs?

Animera
 

Animera

* * * * *
Premium User
Joined
Dec 9, 2008
Messages
2,274
Best answers
2
Reaction score
429
Location
ANIMERA.ONLINE
Cool! Didn't knew getTicks() returns the actual condition countdown! May be nice to play with too ;>

I fixed your script, and tested it works fine here at TFS 1.3

Code:
function onThink()
    local ppl = Game.getPlayers()
   
    for a = 1, #ppl do
        local player = ppl[a]
        local fightCondition = player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)
        if fightCondition then
            if fightCondition:getTicks() > 0 then
            player:sendCancelMessage("You can logout after " .. math.ceil(fightCondition:getTicks()  / 1000).. " second(s).")
            end
        end   
    end
   
return true
end
This should show up a'pz' countdown.

Your mistakes:
  • "configKeys.PZ_LOCKED" is used to return the pz lock time from your config file. Which is Ok, but it has nothing to do with the condition itself.. So if you want to compare the config value change 0 from my script.. getticks already knows what to return from the condition..
  • Globalevents (AFAIK) aren't connected to players you would need to iterate through every player online.

I know that there is some way to create scripts for all monsters onThink.. Wasn't there something like that for players too? (if somebody knows i forgot for now..)

Notes:
  • The fact that that you need to check up on every player every second makes it not performance friendly(HINT: try recursive loops, or increase the interval value in xml).
  • The script itself can be improved more but i guess you can continue now on your own :> ?

Animera
 
Top