![]() |
|
Can't increase a local variable. - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: Can't increase a local variable. (/thread-1424.html) |
Can't increase a local variable. - tonibm19 - 03-30-2014 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?
RE: Can't increase a local variable. - NiLSPACE - 03-30-2014 I have a feeling that we don't have all the code because it says the error is on line 46 but it stops at 42, and since I have no idea how many lines the Initialize function has I have no idea where the error is. Also you can use the OnWorldTick(a_World, a_TimeDelta) instead of a ForEachWorld callback in each tick. RE: Can't increase a local variable. - tonibm19 - 03-30-2014 Fixed it. I was just not checking if player is in combat xDD. There is not all the code because I only posted necesary code, not the Initialize() function RE: Can't increase a local variable. - NiLSPACE - 03-30-2014 (03-30-2014, 05:34 AM)tonibm19 Wrote: .. I only posted necesary code, not the Initialize() function But that also means that we can't use the error code completely. It now said that the error is on line 46 so I started looking at line 46 but it stopped at 42. That means the only usefull thing we get from the error code is that it has something to do with numbers. |