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

[SOLVE] [1.0] Players online loose X Hp per X min?

Eldin

Eldin Projects
Premium User
Joined
Jun 12, 2008
Messages
1,334
Reaction score
613
Location
Sweden
Greets!

Im currently working on a project where food will be more important then normal.
A disease spreads along the world and every player online at lvl 5 and above should loose 1 hitpoint per every 60 second.

Extra: (Should be able to fix it myself if I have the first)
Players at lvl 10 and above should loose. 2 hitpoints instead.

I believe this must be at onLogin or atleast CreatureScripts but im not sure.
Im using TFS 1.0

Thanks in Advance.

Kind Regards,
Eldin.
 
Code:
local t = {
    [{5, 10}] = 1,
    [{11, 999}] = 2
}

function onThink(interval)
    local players = Game.getPlayers()
    for i = 1, #players do
        local player = players[i]
        for k, v in pairs(t) do
            if player:getLevel() >= k[1] and player:getLevel() <= k[2] then
                player:addHealth(-v)
            end
        end
    end
    return true
end

- - - Edit - - -

Is the code okay now, Dalkon? :p
 
@Ninja, Game.getPlayers() stores userdata directly, not player ids.

Code:
local players = Game.getPlayer()
for i = 1, #players do
   local player = players[i]
   -- Do something
end

Edit: Please put the
Code:
local player = players[i]
outside the pairs loop.
 
Last edited:
Back
Top