Nome: Experiencia para Guild
Função: A pedidos de um membro do forum (TioSlash). Aqui está um script que ira adicionar uma porcentagem de Experiência por jogadores online.
Exemplo: Ao alcançar 5 jogadores da Guild Online, todos que estiverem online recebem 2% de xp adicional por jogador. Ou seja, um total de +10% de xp. Bom para servidores com bastante RPG, incentivando a cooperação.
Atualizações: Dia 17/08/2014
Versão: Testada somente na "10.31". (OTX Server - Galaxy)
Créditos:
Kazuza - (eu) Por ter criado.
TioSlash - Pela Ideia.
Vodkart - Por ter achado a função dele que retorna os jogadores da Guild ( sem ela com meu nivel de script não teria conseguido).
xWhiteWolf - Por uma ajudinha.
"Pasta Servidor > Data > Creaturescripts > Scripts" crie "ExpGuild.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
"Pasta Servidor > Data > Creaturescripts > Scripts" crie "ExpGuild_out.lua".
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
"Pasta Servidor > 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"/>
"Pasta Servidor > Data > Creaturescripts > Scripts" em login.lua adicione:
Lá em baixo, onde tem registerCreatureEvent ponha esses dois:
registerCreatureEvent(cid, "ExpGuild")
registerCreatureEvent(cid, "ExpGuild_out")
PS: Qualquer erro, postem. É muito importante. Como este é meu segundo script na vida. Pode ser que aconteça de dar erros. Eu testei pouco.