• 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 1x Guild bonus online

theduck

Member
Joined
Dec 6, 2018
Messages
246
Reaction score
20
Code:
function onLogin(cid)
    local g = getPlayerGuildId(cid)
    if g ~= 0 then
        local n = 1
        for _, pid in ipairs(getPlayersOnline()) do
            if getPlayerGuildId(pid) == g then
                n = n + 1
                if n == 5 then
                    doPlayerSetRate(pid, SKILL__LEVEL, 1.05)
doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')
                    break
                end
            end
        end
    end

    return true
end

I'm having problems with this script
: attempt to call global 'getPlayersOnline' (a nil value
 
Solution
Hello,
Try this one:
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        if #playerGuild:getMembersOnline() >= 5 then --get online members in the guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end
My onLogin function already pass the player userdata as variable, if your don't, just change back and use in line 2: local player = Player(cid) to access the...
Try this
Lua:
function onLogin(cid)
    local g = getPlayerGuildId(cid)
    if g ~= 0 then
        local n = 1
        for _, pid in ipairs(Game.getPlayers()) do
            if getPlayerGuildId(pid) == g then
                n = n + 1
                if n == 5 then
                    doPlayerSetRate(pid, SKILL__LEVEL, 1.05)
doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')
                    break
                end
            end
        end
    end

    return true
end
 
Try this
Lua:
function onLogin(cid)
    local g = getPlayerGuildId(cid)
    if g ~= 0 then
        local n = 1
        for _, pid in ipairs(Game.getPlayers()) do
            if getPlayerGuildId(pid) == g then
                n = n + 1
                if n == 5 then
                    doPlayerSetRate(pid, SKILL__LEVEL, 1.05)
doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')
                    break
                end
            end
        end
    end

    return true
end
attempt to call global 'doPlayerSetRate' (a nil value)
 
tfs 1.x doesn't have doPlayerSetRate, you will need to set a storage and on the player.lua OnGainExperience event add the storage check and exp multiplier
 
tfs 1.x doesn't have doPlayerSetRate, you will need to set a storage and on the player.lua OnGainExperience event add the storage check and exp multiplier
Yes! I was about to comment on this now the only problem that now he is giving storage to everyone even those who do not have guild
Code:
function onLogin(cid)
    local player = Player(cid)
    local g = getPlayerGuildId(cid)
    if g ~= 0 then
        local n = 1
        for _, pid in ipairs(Game.getPlayers()) do
            if getPlayerGuildId(pid) == g then
                n = n + 1
                if n == 2 then
                 player:setStorageValue(1577534,1)
     player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') 
                    break
                end
            end
        end
    end

    return true
end
 
Hello,
Try this one:
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        if #playerGuild:getMembersOnline() >= 5 then --get online members in the guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end
My onLogin function already pass the player userdata as variable, if your don't, just change back and use in line 2: local player = Player(cid) to access the player userdata.
 
Solution
Hello,
Try this one:
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        if #playerGuild:getMembersOnline() >= 5 then --get online members in the guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end
My onLogin function already pass the player userdata as variable, if your don't, just change back and use in line 2: local player = Player(cid) to access the player userdata.
Perfect! a doubt is it possible to check the ip?
 
Perfect! a doubt is it possible to check the ip?
Try this:
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        local GuildOnlineMembers = playerGuild:getMembersOnline() --get all online player in player guild
        local realOnlineMembers = {} --empty table to hold all players that is online and don't have same ip; tableStructure = {[ip] = {playerOnThisIp}}
        for i = 1, #GuildOnlineMembers do --for each player in online members
            local tempPlayer = GuildOnlineMembers[i] --get player userdata
            if not realOnlineMembers[tempPlayer:getIp()] then --if don't exist index with tempPlayer ip
                realOnlineMembers[tempPlayer:getIp()] = {tempPlayer} --create a index with tempPlayer ip and store tempPlayer userdata as value
            else--if already exist tempPlayer IP as index
                table.insert(realOnlineMembers[tempPlayer:getIp()], tempPlayer) --insert player userdata in the IP index
            end
        end
       
        if #realOnlineMembers >= 5 then --get online ips in guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end

Not tested.
 
Try this:
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        local GuildOnlineMembers = playerGuild:getMembersOnline() --get all online player in player guild
        local realOnlineMembers = {} --empty table to hold all players that is online and don't have same ip; tableStructure = {[ip] = {playerOnThisIp}}
        for i = 1, #GuildOnlineMembers do --for each player in online members
            local tempPlayer = GuildOnlineMembers[i] --get player userdata
            if not realOnlineMembers[tempPlayer:getIp()] then --if don't exist index with tempPlayer ip
                realOnlineMembers[tempPlayer:getIp()] = {tempPlayer} --create a index with tempPlayer ip and store tempPlayer userdata as value
            else--if already exist tempPlayer IP as index
                table.insert(realOnlineMembers[tempPlayer:getIp()], tempPlayer) --insert player userdata in the IP index
            end
        end
      
        if #realOnlineMembers >= 5 then --get online ips in guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end

Not tested.
so test is not showing the bonus msg

but there is no error on the console
 
so test is not showing the bonus msg

but there is no error on the console
use debug.print to help find where the issues are. This lets you see what is being loaded and what isnt. So add like debug.print("Loaded player storage" or whatever in your code. It helps isolate issues more or less
 
use debug.print to help find where the issues are. This lets you see what is being loaded and what isnt. So add like debug.print("Loaded player storage" or whatever in your code. It helps isolate issues more or less
print is not a part of the debug library, it's a global function.


Use this, the # operator does not work on unordered tables.
Lua:
function table.size(t, deep)
    local size = 0
    for k, v in pairs(t) do
        size = size + 1
        if type(v) == 'table' and deep then
            size = size + table.size(v, deep)
        end
    end
    return size
end

function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        local GuildOnlineMembers = playerGuild:getMembersOnline() --get all online player in player guild
        local realOnlineMembers = {} --empty table to hold all players that is online and don't have same ip; tableStructure = {[ip] = {playerOnThisIp}}
        for i = 1, #GuildOnlineMembers do --for each player in online members
            local tempPlayer = GuildOnlineMembers[i] --get player userdata
            if not realOnlineMembers[tempPlayer:getIp()] then --if don't exist index with tempPlayer ip
                realOnlineMembers[tempPlayer:getIp()] = {tempPlayer} --create a index with tempPlayer ip and store tempPlayer userdata as value
            else--if already exist tempPlayer IP as index
                table.insert(realOnlineMembers[tempPlayer:getIp()], tempPlayer) --insert player userdata in the IP index
            end
        end
       
        if table.size(realOnlineMembers) >= 5 then --get online ips in guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end
 
print is not a part of the debug library, it's a global function.


Use this, the # operator does not work on unordered tables.
Lua:
function table.size(t, deep)
    local size = 0
    for k, v in pairs(t) do
        size = size + 1
        if type(v) == 'table' and deep then
            size = size + table.size(v, deep)
        end
    end
    return size
end

function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        local GuildOnlineMembers = playerGuild:getMembersOnline() --get all online player in player guild
        local realOnlineMembers = {} --empty table to hold all players that is online and don't have same ip; tableStructure = {[ip] = {playerOnThisIp}}
        for i = 1, #GuildOnlineMembers do --for each player in online members
            local tempPlayer = GuildOnlineMembers[i] --get player userdata
            if not realOnlineMembers[tempPlayer:getIp()] then --if don't exist index with tempPlayer ip
                realOnlineMembers[tempPlayer:getIp()] = {tempPlayer} --create a index with tempPlayer ip and store tempPlayer userdata as value
            else--if already exist tempPlayer IP as index
                table.insert(realOnlineMembers[tempPlayer:getIp()], tempPlayer) --insert player userdata in the IP index
            end
        end
      
        if table.size(realOnlineMembers) >= 5 then --get online ips in guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end
worked perfectly
thank you all!
 
Try this:
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        local GuildOnlineMembers = playerGuild:getMembersOnline() --get all online player in player guild
        local realOnlineMembers = {} --empty table to hold all players that is online and don't have same ip; tableStructure = {[ip] = {playerOnThisIp}}
        for i = 1, #GuildOnlineMembers do --for each player in online members
            local tempPlayer = GuildOnlineMembers[i] --get player userdata
            if not realOnlineMembers[tempPlayer:getIp()] then --if don't exist index with tempPlayer ip
                realOnlineMembers[tempPlayer:getIp()] = {tempPlayer} --create a index with tempPlayer ip and store tempPlayer userdata as value
            else--if already exist tempPlayer IP as index
                table.insert(realOnlineMembers[tempPlayer:getIp()], tempPlayer) --insert player userdata in the IP index
            end
        end
      
        if #realOnlineMembers >= 5 then --get online ips in guild, if more than 5
            player:setStorageValue(1577534,1) --give storage to player
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE , '[Boost]: You received 5% extra experience for being in a guild with more than five players online.') --send msg to player
        end
    end
    return true
end

Not tested.
can you help me installing this?
 
Lua:
player:setStorageValue(1577534,1) --give storage to player

so this storagevalue holds the formula for extra 5%exp right?
where is this storagevalue registered? is it meant to be in player.lua?
 
Back
Top