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

Lua help online guild bonus exp

miguelshta

Member
Joined
Mar 21, 2009
Messages
351
Solutions
1
Reaction score
13
Location
Toronto, Canada
hello i need help i want to add 20% extra experience to all guilds with more than > 5 players online and no double ip allowed using tfs 1.3
 
First
Data > Creaturescripts > Scripts" crie "ExpGuild.lua".
Lua:
function getGuildMembersOnline(GuildId)
local players,query = {},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " .. GuildId .. ");")
if (query:getID() ~= -1) then
repeat
table.insert(players,query:getDataString("name"))
until not query:next()
query:free()
end
return #players > 0 and players or false
end

function onLogin(cid)

    local guild_id = getPlayerGuildId(cid)
    local minimo = 2
    local max = 2
    local porcentagem = 2
    -----------------------------------------
    doPlayerSetExperienceRate(cid, 1)
    if guild_id == 0 then
        addEvent(doPlayerSendTextMessage, 200,cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Entre em uma guild para ter bonus de experiencia.")
        return true
    end
    
    if guild_id > 0 then
        local membros_online = table.maxn(getGuildMembersOnline(guild_id))
        local tabela_membros = getGuildMembersOnline(guild_id)
        
        --if #getPlayersByIp(getPlayerIp(cid)) >= max then
            --doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Players com Multi-Cliente nao contam para ganhar o bonus de experiencia.")
        --return true
        --end
        
        if membros_online <= minimo then
            addEvent(doPlayerSendTextMessage, 2000, cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Para ter bonus de experiencia precisa ter mais de "..minimo.." jogadores da guild online.\n Jogadores da Guild Online ["..membros_online.."]")
            return true
        end
    
        if membros_online > minimo then
            for var = 1, #tabela_membros do
                local nomes = getCreatureByName(tabela_membros[var])
                local XP = ((membros_online*porcentagem) / 100) + 1.00       
                doPlayerSetExperienceRate(nomes, XP)   
                addEvent(doPlayerSendTextMessage,1000,nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] A experiencia dos membros da guilda foi aumentada para +"..membros_online*porcentagem.."% - Membro "..getCreatureName(cid).." logou.")       
            end
            return true
        end
    end
end

Later Data > Creaturescripts > Scripts" crie "ExpGuild_out.lua"
Code:
function getGuildMembersOnline(GuildId)
local players = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerGuildId(pid) == tonumber(GuildId) then
table.insert(players, getPlayerName(pid))
end
end
return #players > 0 and players or false
end

function onLogout(cid)

    if getPlayerGuildId(cid) == 0 then
        return true
    else
        local guild_id = getPlayerGuildId(cid)
        local membros_online = table.maxn(getGuildMembersOnline(guild_id))
        local tabela_membros = getGuildMembersOnline(guild_id)
        local porcentagem = 2
        local minimo = 2
        -----------------------------------------       
        for var = 1, #tabela_membros do
            local nomes = getCreatureByName(tabela_membros[var])
            local membros_online = membros_online - 1
            
            if membros_online <= minimo then
                doPlayerSetExperienceRate(nomes, 1.0)   
                doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Nao tem mais o numero de players necessarios para ganhar o bonus de experiencia - Membro "..getCreatureName(cid).." deslogou.")
            end
            
            if membros_online > minimo then
                local XP = ((membros_online*porcentagem) / 100) + 1.00       
                doPlayerSetExperienceRate(nomes, XP)   
                doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] A experiencia dos membros da guilda foi ajustada para "..membros_online*porcentagem.."% - Membro "..getCreatureName(cid).." deslogou.")
            end
        end
        return true
    end
end

Finally
Data > Creaturescripts" em creaturescripts.xml adicione:
<event type="login" name="ExpGuild" event="script" value="exp_guild.lua"/>
<event type="logout" name="ExpGuild_out" event="script" value="exp_guild_out.lua"/>

Remeber add tag on login
registerCreatureEvent(cid, "ExpGuild")
registerCreatureEvent(cid, "ExpGuild_out")
 
First
Data > Creaturescripts > Scripts" crie "ExpGuild.lua".
Lua:
function getGuildMembersOnline(GuildId)
local players,query = {},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " .. GuildId .. ");")
if (query:getID() ~= -1) then
repeat
table.insert(players,query:getDataString("name"))
until not query:next()
query:free()
end
return #players > 0 and players or false
end

function onLogin(cid)

    local guild_id = getPlayerGuildId(cid)
    local minimo = 2
    local max = 2
    local porcentagem = 2
    -----------------------------------------
    doPlayerSetExperienceRate(cid, 1)
    if guild_id == 0 then
        addEvent(doPlayerSendTextMessage, 200,cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Entre em uma guild para ter bonus de experiencia.")
        return true
    end
   
    if guild_id > 0 then
        local membros_online = table.maxn(getGuildMembersOnline(guild_id))
        local tabela_membros = getGuildMembersOnline(guild_id)
       
        --if #getPlayersByIp(getPlayerIp(cid)) >= max then
            --doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Players com Multi-Cliente nao contam para ganhar o bonus de experiencia.")
        --return true
        --end
       
        if membros_online <= minimo then
            addEvent(doPlayerSendTextMessage, 2000, cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Para ter bonus de experiencia precisa ter mais de "..minimo.." jogadores da guild online.\n Jogadores da Guild Online ["..membros_online.."]")
            return true
        end
   
        if membros_online > minimo then
            for var = 1, #tabela_membros do
                local nomes = getCreatureByName(tabela_membros[var])
                local XP = ((membros_online*porcentagem) / 100) + 1.00      
                doPlayerSetExperienceRate(nomes, XP)  
                addEvent(doPlayerSendTextMessage,1000,nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] A experiencia dos membros da guilda foi aumentada para +"..membros_online*porcentagem.."% - Membro "..getCreatureName(cid).." logou.")      
            end
            return true
        end
    end
end

Later Data > Creaturescripts > Scripts" crie "ExpGuild_out.lua"
Code:
function getGuildMembersOnline(GuildId)
local players = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerGuildId(pid) == tonumber(GuildId) then
table.insert(players, getPlayerName(pid))
end
end
return #players > 0 and players or false
end

function onLogout(cid)

    if getPlayerGuildId(cid) == 0 then
        return true
    else
        local guild_id = getPlayerGuildId(cid)
        local membros_online = table.maxn(getGuildMembersOnline(guild_id))
        local tabela_membros = getGuildMembersOnline(guild_id)
        local porcentagem = 2
        local minimo = 2
        -----------------------------------------      
        for var = 1, #tabela_membros do
            local nomes = getCreatureByName(tabela_membros[var])
            local membros_online = membros_online - 1
           
            if membros_online <= minimo then
                doPlayerSetExperienceRate(nomes, 1.0)  
                doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Nao tem mais o numero de players necessarios para ganhar o bonus de experiencia - Membro "..getCreatureName(cid).." deslogou.")
            end
           
            if membros_online > minimo then
                local XP = ((membros_online*porcentagem) / 100) + 1.00      
                doPlayerSetExperienceRate(nomes, XP)  
                doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] A experiencia dos membros da guilda foi ajustada para "..membros_online*porcentagem.."% - Membro "..getCreatureName(cid).." deslogou.")
            end
        end
        return true
    end
end

Finally
Data > Creaturescripts" em creaturescripts.xml adicione:
<event type="login" name="ExpGuild" event="script" value="exp_guild.lua"/>
<event type="logout" name="ExpGuild_out" event="script" value="exp_guild_out.lua"/>

Remeber add tag on login
registerCreatureEvent(cid, "ExpGuild")
registerCreatureEvent(cid, "ExpGuild_out")
no console errors but nothing happens
 
Maybe remove the _ from exp_guild_out.lua like expguildout.lu this@miguelshta
<event type="login" name="ExpGuild" event="script" value="ExpGuild.lua"/>
<event type="logout" name="ExpGuild_out" event="script" value="ExpGuild_out.lua"/>
 
TFS 1.3 uses:
Lua:
<event type="login" name="ExpGuild" script="ExpGuild.lua"/>
<event type="logout" name="ExpGuild_out" script="ExpGuild_out.lua"/>

Without that part -> event = "script"
 
well now got this:

Bash:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/ExpGuild.lua:onLogin
data/creaturescripts/scripts/ExpGuild.lua:19: attempt to call global 'doPlayerSetExperienceRate' (a nil value)

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/ExpGuild_out.lua:onLogout
data/creaturescripts/scripts/ExpGuild_out.lua:3: attempt to call global 'getPlayersOnline' (a nil value)
 
Apparently, this script is for tfs 0.4, so you'll have to look for the replaced functions in your lib.

Example: As part of the exp, you will have to work in the folder data/events/scripts/players.lua (because here you can add a condition to change the exp won).

And so on, until you get the desired script.
 
Apparently, this script is for tfs 0.4, so you'll have to look for the replaced functions in your lib.

Example: As part of the exp, you will have to work in the folder data/events/scripts/players.lua (because here you can add a condition to change the exp won).

And so on, until you get the desired script.
i found this function in the web but i dont know how to install it it is for tfs 1.3

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
 
After adding this script to creaturescripts, you must open data / events / scripts / player.lua, then you must add the next line [below the function: function Player: onGainExperience(source, exp, rawExp)]:

Lua:
    if getGlobalStorageValue(1577534) == 1 then
        exp = exp * 1.05
    end
 
After adding this script to creaturescripts, you must open data / events / scripts / player.lua, then you must add the next line [below the function: function Player: onGainExperience(source, exp, rawExp)]:

Lua:
    if getGlobalStorageValue(1577534) == 1 then
        exp = exp * 1.05
    end
like this?

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
     if getGlobalStorageValue(1577534) == 1 then
        exp = exp * 100.05
    end
 
That's right, the only thing is the multiplication, which if it's 5% should be 1.05. Now, it is multiplying the xp by 100.
i put exp = exp * 0.95 but no changes on experience thats what i do
created script guildexp > data/creaturescripts/scripts/Expguild.lua
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        if #playerGuild:getMembersOnline() >= 2 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

also in creaturescripts.xml i put
XML:
<event type="login" name="ExpGuild" script="ExpGuild.lua"/>
register the event in my login
in player.lua

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
     if getGlobalStorageValue(1577534) == 1 then
        exp = exp * 0.95
    end
i got the message
Code:
You received 5% extra experience for being in a guild with more than five players online.
but no changes on my experience maybe calling a global storage instead of player storage?
 
i put exp = exp * 0.95 but no changes on experience thats what i do
created script guildexp > data/creaturescripts/scripts/Expguild.lua
Lua:
function onLogin(player)
    local playerGuild = player:getGuild() --get player guild
    if playerGuild then --if player have a guild
        if #playerGuild:getMembersOnline() >= 2 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

also in creaturescripts.xml i put
XML:
<event type="login" name="ExpGuild" script="ExpGuild.lua"/>
register the event in my login
in player.lua

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
     if getGlobalStorageValue(1577534) == 1 then
        exp = exp * 0.95
    end
i got the message
Code:
You received 5% extra experience for being in a guild with more than five players online.
but no changes on my experience maybe calling a global storage instead of player storage?
Ohh sory, try use this:
Lua:
if source:getStorageValue(1577534) == 1 then
 
Ohh sory, try use this:
Lua:
if source:getStorageValue(1577534) == 1 then
i put like this
Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
     if source:getStorageValue(1577534) == 1 then
        exp = exp * 0.95
    end
but still no changes on experience
 
if self:getStorageValue(1577534) == 1 then
worked good but my exp is less

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
     if self:getStorageValue(1577534) == 1 then
        exp = exp * 0.95
    end
maybe adding exp + base exp? how will be
 
Back
Top