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

Get Guild Members Online? {solved}

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,857
Reaction score
96
Location
Brazil
Example:
LUA:
if getguildmembersonline >= 5 then
doteleport...
If this guild have more than 5 members online they will get teleported
 
try
LUA:
function getOnlineGuildMembers(guildId)
    local guild = {}
    for _, cid in ipairs(getPlayersOnline()) do
        if getPlayerGuildId(cid) == guildId then
            table.insert(guild, cid)
        end
    end
    return guild
end

LUA:
if table.getn(getOnlineGuildMembers(guildId)) >= 5 then
 
Code:
	local n = 0
	for _, pid in ipairs(getPlayersOnline()) do
		if getPlayerGuildId(pid) == guildId then
			n = n + 1
			if n == 5 then
				-- your code here
				break
			end
		end
	end
this should be faster if you have lots of players, but only in cases where there's enough players
(not a function, variable guildId must be defined before)
 
Example: if guild "Riders" get more than 5 members online they will receibe 0.5% extra exp

Will it work?

LUA:
	local n = 0
	for _, pid in ipairs(getPlayersOnline()) do
		if getPlayerGuildId(pid) == guildId then
			n = n + 1
			if n == 5 then
				local ex = getPlayerRates(cid)[SKILL__LEVEL]
				doPlayerSetRate(cid, SKILL__LEVEL, (ex+0.05))
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received 5% extra experience for being in a guild.")
				break
			end
		end
	end
 
next time say you wanted something like this
LUA:
--
	local t = {}
	for _, pid in ipairs(getPlayersOnline()) do
		if getPlayerGuildId(pid) == guildId then
			table.insert(t, pid)
			if n == 5 then
				for i = 1, #t do
					doPlayerSetRate(t[i], SKILL__LEVEL, 1.05)
					doPlayerSendTextMessage(t[i], MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild.')
				end
				break
			end
		end
	end
you still need the guildId var
 
try
LUA:
function getOnlineGuildMembers(guildId)
    local guild = {}
    for _, cid in ipairs(getPlayersOnline()) do
        if getPlayerGuildId(cid) == guildId then
            table.insert(guild, cid)
        end
    end
    return guild
end

LUA:
if table.getn(getOnlineGuildMembers(guildId)) >= 5 then

Cyko, I made this, work?
LUA:
function onLogin(cid)

if table.getn(getOnlineGuildMembers(guildId)) >= 5 then
	doPlayerSetRate(cid, SKILL__LEVEL, (ex+0.05))
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received 5% extra experience for being in a guild with more than five players online.")
end
return true
end
 
LUA:
function onLogin(cid)
	local g = getPlayerGuildId(cid)
	if g ~= 0 then
		local n = 1
		for _, pid in ipairs(getPlayersOnline()) do
			if getPlayerGuildId(pid) == g then
				n = n + 1
				if n == 5 then
					doPlayerSetRate(cid, SKILL__LEVEL, 1.05)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')
					break
				end
			end
		end
	end

	return true
end
only this player will get bonus, others won't unless they all relog
 
wouldn't it copy townid etc from knight sample or similar when making new char?

because you said the script sets townid for all characters, or maybe your accountmanagement.php is broken?\
 
Thank you Cyko!

LUA:
function onLogin(cid)
	local g = getPlayerGuildId(cid)
	if g ~= 0 then
		local n = 1
		for _, pid in ipairs(getPlayersOnline()) do
			if getPlayerGuildId(pid) == g then
				n = n + 1
				if n == 5 then
					doPlayerSetRate(cid, SKILL__LEVEL, 1.05)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')
					break
				end
			end
		end
	end

	return true
end
only this player will get bonus, others won't unless they all relog

How to solve this?
 
Thank you Cyko!



How to solve this?

LUA:
doPlayerSetRate(cid, SKILL__LEVEL, 1.05)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')

Changing 'cid to 'pid'

Like this
LUA:
doPlayerSetRate(pid, SKILL__LEVEL, 1.05)
doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')
 
LUA:
doPlayerSetRate(cid, SKILL__LEVEL, 1.05)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')

Changing 'cid to 'pid'

Like this
LUA:
doPlayerSetRate(pid, SKILL__LEVEL, 1.05)
doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, 'You received 5% extra experience for being in a guild with more than five players online.')

Will they receive only if relog or it's solved?
 
Back
Top