Hey guys.
I thought this script deserves his own thread since it's kinda cool.
You can reward guilds with extra experience for a certain time.
Every guild can have different experience and time set.
Requested here: http://otland.net/f132/talkaction-add-more-exp-all-guild-members-forgotten-server-0-4-0-dev-129240/
How it will work:
You can use a command to set extra experince (in percent) for a certain time (in hours). You can also use the command to add that function to scripts (like events or quests).
The script will directly after using the command update the experience of all guild members. Also, if they login the experience will be set and a message informs them about the exp rate.
How to add: (mod version below)
1) Create a file in "libs" folder called "500-guildexp.lua".
2) Add this script in the created file: (You just need to set 1 storage)
3) Goto your config.lua and set "saveGlobalStorage" to true.
4) Goto creaturescripts/scripts/login.lua and add this piece of code:
5) Goto talkactions/talkactions.xml and add:
6) Goto talkactions/scripts and create "guildExp.lua" and add:
7) Now you can use the command or function..
Mod version:
1) Create a file called "guildexp.xml" in mods folder.
2) Add this code:
Example:
/ge <guildname>, extraExp, timeInMinutes
/ge Demolishers, 0.5, 300 <- Will give "Demolishers" 50% extra exp for 5 hours.
OR use the function in a script:
function addGuildExp(name, exp, time)
Example: (Important time is in seconds in that function)
addGuildExp("Demolishers", 0.5, 5*60*60) <- Same effect as using the comand example.
I thought this script deserves his own thread since it's kinda cool.
You can reward guilds with extra experience for a certain time.
Every guild can have different experience and time set.
Requested here: http://otland.net/f132/talkaction-add-more-exp-all-guild-members-forgotten-server-0-4-0-dev-129240/
How it will work:
You can use a command to set extra experince (in percent) for a certain time (in hours). You can also use the command to add that function to scripts (like events or quests).
The script will directly after using the command update the experience of all guild members. Also, if they login the experience will be set and a message informs them about the exp rate.
How to add: (mod version below)
1) Create a file in "libs" folder called "500-guildexp.lua".
2) Add this script in the created file: (You just need to set 1 storage)
Lua:
ge_storage = 45501
function loadGuildExp()
local ret = getStorage(ge_storage)
if type(ret) == "string" then
return loadstring("return " .. ret)()
end
return {}
end
function saveGuildExp(list)
local ret = "{"
for guild, conf in pairs(list) do
ret = ret .. "[" .. guild .. "] = {" .. table.concat(conf, ",") .. "},"
end
ret = ret .. "}"
doSetStorage(ge_storage, ret)
end
function addGuildExp(name, exp, time)
local id = getGuildId(name)
if not(id) then
return print("Guild Exp System: Guild '" .. name .. "' was not found. (add)")
end
local c = loadGuildExp()
c[id] = {exp, time+os.time()}
saveGuildExp(c)
updateGuildExp(id, exp, time+os.time())
end
function removeGuildExp(id)
local c = loadGuildExp()
c[id] = nil
saveGuildExp(c)
end
function setRate(cid, exp)
if not(isPlayer(cid)) then
return true
end
doPlayerSetRate(cid, SKILL__LEVEL, exp)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your guild's extra experience time ended.")
end
function addRate(cid, exp, time)
local ex = getPlayerRates(cid)[SKILL__LEVEL]
doPlayerSetRate(cid, SKILL__LEVEL, (ex+exp))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your guild received " .. exp * 100 .. "% extra experience.")
addEvent(setRate, (time-os.time())*1000, cid, ex)
end
function updateGuildExp(guild, exp, time)
for _, name in pairs(getOnlinePlayers()) do
local cid = getPlayerByName(name)
if guild == getPlayerGuildId(cid) then
addRate(cid, exp, time)
end
end
end
3) Goto your config.lua and set "saveGlobalStorage" to true.
Lua:
saveGlobalStorage = true
4) Goto creaturescripts/scripts/login.lua and add this piece of code:
Lua:
local gid = getPlayerGuildId(cid)
if gid ~= 0 then
local c = loadGuildExp()[gid]
if c then
if os.time() > c[2] then
removeGuildExp(gid)
else
addRate(cid, c[1], c[2])
end
end
end
5) Goto talkactions/talkactions.xml and add:
XML:
<talkaction log="yes" words="/ge" access="5" event="script" value="guildExp.lua"/>
6) Goto talkactions/scripts and create "guildExp.lua" and add:
Lua:
function onSay(cid, words, param, channel)
local split = param:explode(",")
local name, exp, time = split[1], tonumber(split[2]), tonumber(split[3])
if not(split[3]) then
return doPlayerSendCancel(cid, "The commands requires 3 parameters: guild name, experience and time")
end
if not(exp and time) then
print(exp .. time)
return doPlayerSendCancel(cid, "Numeric parameter required (experience and time in minutes).")
end
addGuildExp(split[1], exp, time*60)
return true
end
7) Now you can use the command or function..
Mod version:
1) Create a file called "guildexp.xml" in mods folder.
2) Add this code:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Guild Experience Reward" version="1.0" author="Summ" contact="otland.net" enabled="yes">
<config name="ge_config"><![CDATA[
ge_storage = 45501
function loadGuildExp()
local ret = getStorage(ge_storage)
if type(ret) == "string" then
return loadstring("return " .. ret)()
end
return {}
end
function saveGuildExp(list)
local ret = "{"
for guild, conf in pairs(list) do
ret = ret .. "[" .. guild .. "] = {" .. table.concat(conf, ",") .. "},"
end
ret = ret .. "}"
doSetStorage(ge_storage, ret)
end
function addGuildExp(name, exp, time)
local id = getGuildId(name)
if not(id) then
return print("Guild Exp System: Guild '" .. name .. "' was not found. (add)")
end
local c = loadGuildExp()
c[id] = {exp, time+os.time()}
saveGuildExp(c)
updateGuildExp(id, exp, time+os.time())
end
function removeGuildExp(id)
local c = loadGuildExp()
c[id] = nil
saveGuildExp(c)
end
function setRate(cid, exp)
if not(isPlayer(cid)) then
return true
end
doPlayerSetRate(cid, SKILL__LEVEL, exp)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your guild's extra experience time ended.")
end
function addRate(cid, exp, time)
local ex = getPlayerRates(cid)[SKILL__LEVEL]
doPlayerSetRate(cid, SKILL__LEVEL, (ex+exp))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your guild received " .. exp * 100 .. "% extra experience.")
addEvent(setRate, (time-os.time())*1000, cid, ex)
end
function updateGuildExp(guild, exp, time)
for _, cid in pairs(getPlayersOnline()) do
if guild == getPlayerGuildId(cid) then
addRate(cid, exp, time)
end
end
end
]]></config>
<talkaction log="yes" words="/ge" access="5" event="buffer"><![CDATA[
domodlib('ge_config')
local split = param:explode(",")
local name, exp, time = split[1], tonumber(split[2]), tonumber(split[3])
if not(split[3]) then
return doPlayerSendCancel(cid, "The commands requires 3 parameters: guild name, experience and time")
end
if not(exp and time) then
print(exp .. time)
return doPlayerSendCancel(cid, "Numeric parameter required (experience and time in minutes).")
end
addGuildExp(split[1], exp, time*60)
return true
]]></talkaction>
<event type="login" name="GuildExpLogin" event="buffer"><![CDATA[
domodlib('ge_config')
local gid = getPlayerGuildId(cid)
if gid ~= 0 then
local c = loadGuildExp()[gid]
if c then
if os.time() > c[2] then
removeGuildExp(gid)
else
addRate(cid, c[1], c[2])
end
end
end
]]></event>
</mod>
Example:
/ge <guildname>, extraExp, timeInMinutes
/ge Demolishers, 0.5, 300 <- Will give "Demolishers" 50% extra exp for 5 hours.
OR use the function in a script:
function addGuildExp(name, exp, time)
Example: (Important time is in seconds in that function)
addGuildExp("Demolishers", 0.5, 5*60*60) <- Same effect as using the comand example.
Last edited: