Can't increase a local variable.
#1
Hi, I'm trying to make CombatLog for MCServer and I have a problem.
CombatTime = 5


Time = 0
local seconds = {}
local IsOnCombat = {}

function OnTakeDamage(Receiver, TDI)
    if Receiver:IsPlayer() then
        Player = tolua.cast(Receiver,"cPlayer")
        IsOnCombat[Player:GetName()] = true
        seconds[Player:GetName()] = 0
        Player:SendMessage("You\'re on a combat, don\'t disconnect")
    end
end

function OnPlayerDestroyed(Player)
    if IsOnCombat[Player:GetName()] == true then
        Player:TakeDamage(dtPlugin, nil, 1000, 1000, 0)
        cRoot:Get():BroadcastChat(Player:GetName().." disconnected while being on a combat, buuuhhh, you suck")
    end
end

function OnTick(TimeDelta)
    if Time == 20 then
        local EachPlayer = function(Player)
            if seconds[Player:GetName()] == CombatTime then
                Player:SendMessage("You are no longer in combat")
            else
                seconds[Player:GetName()] = seconds[Player:GetName()] + 1
                print(seconds[Player:GetName()])
            end
        end
        local EachWorld = function(World)
            World:ForEachPlayer(EachPlayer)
        end
        cRoot:Get():ForEachWorld(EachWorld)
        Time = 0
    else
        Time = Time + 1
    end
end
I need to increase player combat time. The code should do it, but I get this error every second:
[20:28:04] LUA: 2 - Plugins/CombatLog/main.lua:46: attempt to perform arithmetic
on field '?' (a nil value)
Any idea why? How to fix it? Huh
Reply
Thanks given by:


Messages In This Thread
Can't increase a local variable. - by tonibm19 - 03-30-2014, 05:28 AM



Users browsing this thread: 1 Guest(s)