miguelshta
Member
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
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
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
no console errors but nothing happensFirst
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")
<event type="login" name="ExpGuild" script="ExpGuild.lua"/>
<event type="logout" name="ExpGuild_out" script="ExpGuild_out.lua"/>
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)
i found this function in the web but i dont know how to install it it is for tfs 1.3Apparently, 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.
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
if getGlobalStorageValue(1577534) == 1 then
exp = exp * 1.05
end
like this?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
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
i put exp = exp * 0.95 but no changes on experience thats what i doThat'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.
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
<event type="login" name="ExpGuild" script="ExpGuild.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
You received 5% extra experience for being in a guild with more than five players online.
Ohh sory, try use this: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
register the event in my loginXML:<event type="login" name="ExpGuild" script="ExpGuild.lua"/>
in player.lua
i got the messageLua: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
but no changes on my experience maybe calling a global storage instead of player storage?Code:You received 5% extra experience for being in a guild with more than five players online.
if source:getStorageValue(1577534) == 1 then
i put like thisOhh sory, try use this:Lua:if source:getStorageValue(1577534) == 1 then
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
still no errors but no changes on experiencetry Player:getStorage.. on line 5
worked good but my exp is lessif self:getStorageValue(1577534) == 1 then
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