Untitled

mail@pastecode.io avatar
unknown
xml
2 years ago
2.1 kB
2
Indexable
Never
<mod name="Lottery System" version="1.5" author="Prestige" contact="" enabled="yes">
	<config name="lottery_config"><![CDATA[
		config = {
			lottery_hour = "1 hour", 
			rewards_id = {5805, 5806, 5807, 11213, 10928}, 
			crystal_counts = 10,
		}
	]]></config>
	<globalevent name="lottery" interval="10" event="script"><![CDATA[
	domodlib('lottery_config')
	function onThink(interval, lastExecution)
		if (getWorldCreatures(0) == 0) then
			return true
		end

		local list = {}
		for i, tid in ipairs(getPlayersOnline()) do
			if (getPlayerAccess(tid) <= 3 and getPlayerStorageValue(tid, 0) >= 15) then
				list[i] = tid
			end
		end

		if (#list == 0) then
			return true
		end
 
		local winner = list[math.random(1, #list)]
		local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
 
		if(random_item == 11213) then
			local rm_fruits = config.crystal_counts * math.random(1,5)
			doPlayerAddItem(winner, random_item, rm_fruits)
			doBroadcastMessage("[Prestige Lottery] Winner: " .. getCreatureName(winner) .. ", Reward: " .. rm_fruits .. " " .. getItemNameById(random_item) .. "s. Congratulations!\n(Next lottery in " .. config.lottery_hour .. ")", 22)
			doPlayerSendTextMessage(winner, MESSAGE_STATUS_CONSOLE_BLUE, "(Lottery System) You win " .. rm_fruits .. " "..getItemNameById(random_item).."s.")
		else
			doBroadcastMessage("[Prestige Lottery] Winner: " .. getCreatureName(winner) .. ", Reward: " .. getItemNameById(random_item) .. ". Congratulations!\n(Next lottery in " .. config.lottery_hour .. ")", 22)
			doPlayerAddItem(winner, random_item, 1)
			doPlayerSendTextMessage(winner, MESSAGE_STATUS_CONSOLE_BLUE, "(Lottery System) You win "..getItemNameById(random_item)..".")
		end
		
		local param = 'Winner: ' .. getCreatureName(winner) .. ', Reward: ' .. getItemNameById(random_item) .. '. Congratulations! (Next lottery in 2 hours)'
		for _, creature in ipairs(getChannelUsers(11)) do
			doPlayerSendChannelMessage(creature, '[Prestige Lottery]', param, TALKTYPE_CHANNEL_O, 11)
		end
		return true
	end 
	]]></globalevent>
</mod>