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

Solved Help to set exp bonus guild members online

danbsten

New Member
Joined
Aug 3, 2015
Messages
53
Reaction score
1
I have this code, but i dont understand it so much, and i need suport to change it

I wanna make a script to 1 member online = 1% bonus exp
4 members online = 4% bonus exp

And if bonus:
Code:
    if bonus > 10 then
       bonus = 10
     end

any can help me?
exp_bonus.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 onLogin(cid)

   local guild_id = getPlayerGuildId(cid)
   local minimo = 2
   local max = 2
   local porcentagem = 2
   -----------------------------------------
   doPlayerSetExperienceRate(cid, 1)
   if guild_id <= 0 then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Join a guild to have experience bonus.")
     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 with Multi-Client does not have to earn bonus experience.")
     --return true
     --end
     
     if membros_online <= minimo then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] To get bonus experience must be over "..minimo.." players online guild.\nGuild of Players 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)   
       doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] The experience of the guild members was increased to +"..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." joined.")     
     end
     return true
     end
   
   end
   
   
   
   
   
end

exp_bonus_out
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)


     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
     -----------------------------------------     
if guild_id >= 1 then
     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] No longer does the number of players needed to earn bonus experience - Member "..getCreatureName(cid).." left.")
       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.."% - Member "..getCreatureName(cid).." left.")
       end
     end
end
return true
   
   
   
end
 
change in both exp_bonus.lua & exp_bonus_out
Code:
local minimo = 2
to
Code:
local minimo = 0


Now in exp_bonus.lua
replace this line
Code:
local XP = ((membros_online*porcentagem) / 100) + 1.00
with this
Code:
local XP = (membros_online / 100) + 1.00


Then in exp_bonus_out
replace this line
Code:
local XP = ((membros_online*porcentagem) / 100) + 1.00
with this
Code:
local XP = (membros_online / 100) + 1.00
 
change in both exp_bonus.lua & exp_bonus_out
Code:
local minimo = 2
to
Code:
local minimo = 0


Now in exp_bonus.lua
replace this line
Code:
local XP = ((membros_online*porcentagem) / 100) + 1.00
with this
Code:
local XP = (membros_online / 100) + 1.00


Then in exp_bonus_out
replace this line
Code:
local XP = ((membros_online*porcentagem) / 100) + 1.00
with this
Code:
local XP = (membros_online / 100) + 1.00

And to put limit (10%) ?

Code:
if bonus > 10 then
bonus = 10
end
 
Make in player.cpp something like float extraGuildExp. Then add method, that counts the online members of this player guild and just change the extraGuildExp depend of count of members online. Then just include it in the experience part, giving player exp :p
 
change this in both scripts from
Code:
local XP = (membros_online / 100) + 1.00

to
Code:
local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00

@gs1994
Not everything needs to be changed in the sources in order to be proficient, if that was the case we wouldn't be using lua to write scripts. :)
 
change this in both scripts from
Code:
local XP = (membros_online / 100) + 1.00

to
Code:
local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00

@gs1994
Not everything needs to be changed in the sources in order to be proficient, if that was the case we wouldn't be using lua to write scripts. :)

Thank YOU!
 
Back
Top