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

CreatureEvent Guild Extra Experience Time [by Summ]

Summ

(\/)(;,,;)(\/) Y not?
Staff member
Global Moderator
Joined
Oct 15, 2008
Messages
4,152
Solutions
12
Reaction score
1,107
Location
Germany :O
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)
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:
1) You can use getPlayersOnline, to make fewer loops. It returns cid's directly instead of player names.

2) return loadstring("return " .. ret)() Why?

Except that, you could rewrite it to the mods, change command name to /ge (guild exp), and there will be even more awesomeness in your script. Anyway, well done! And take my post just as suggestion.

@edit
About second one, I just couldn't figure out what its purpose, but now I got it so its alright :p
 
Last edited:
@slawkens:
@1: Ye I always mistake between these 2 functions, the names should be changed. I though one function just returns the count of players and the other the cid, but when I tried it returned the names (so thats why I used the wrong)
@2: What should I use elsewise?
@mod: added, command changed

Thanks for suggestions
 
1 ° It is possible that by adding the additional exp that is sent to all connected players in the form of "Broadcast"?
2 ° Even when the time is coming to an end, this is advised.


Examples:
1 ° Guild "GuildName" has a bonus of "expadd" for "xxx" minutes.
2 ° We are "seconds" to make your exp bonus expires.
 
If I add it with the mod version do i still have to edit the config.lua with the following? ^^

Lua:
saveGlobalStorage = TRUE
 
yes, because all setting are saved in global event, database would be waste of resources

@Pretx
Test it, I only tested on 0.4, but it should work.
 
@Summ,

is possible to:
If guild have more than 6 members online all members will receive 5%+ exp until 6+ members be online


possible?
 
Back
Top