• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Player gets randomly chosen

DestinationSer

@echo off
Joined
Mar 7, 2009
Messages
2,806
Solutions
1
Reaction score
676
I need this script
A player from the online list gets randomly chosen to get a reward of id 10573.
Every 60 minutes (1 hour)
Thanks
 
globalevents:

Code:
local config = {
    lottery_hour = "1 Hour",
    rewards_id = {10573},
    }
function onThink(interval, lastExecution)
	if(getWorldCreatures(0) == 0)then
		return true
	end
 
    local list = {10573}
    for i, tid in ipairs(getPlayersOnline()) do
		list[i] = tid
	end
 
	local winner = list[math.random(1, #list)]
	local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
 
	if(random_item == 10573) then
		doPlayerAddItem(winner, random_item, 1)
	end

	return true
end

Code:
<globalevent name="winner" interval="here the hour in interval numbers" event="script" value="script name.lua"/>

Good Luck.
 
Can you make it so it broadcasts the player name over who wonn the item?

This should work:
LUA:
local config = {
    rewards_id = {10573}
    }
function onThink(interval, lastExecution)
	if(getWorldCreatures(0) == 0)then
		return true
	end
 
    local list = {10573}
    for i, tid in ipairs(getPlayersOnline()) do
		list[i] = tid
	end
 
	local winner = list[math.random(1, #list)]
	local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
 
	if(random_item == 10573) then
		doPlayerAddItem(winner, random_item, 1)
                doBroadcastMessage('Congratz ' .. winner .. '. You just won an item.')
	end

	return true
end
 
Last edited:
globalevents:

Code:
local config = {
    lottery_hour = "1 Hour",
    rewards_id = {10573},
    }
function onThink(interval, lastExecution)
	if(getWorldCreatures(0) == 0)then
		return true
	end
 
    local list = {10573}
    for i, tid in ipairs(getPlayersOnline()) do
		list[i] = tid
	end
 
	local winner = list[math.random(1, #list)]
	local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
 
	if(random_item == 10573) then
		doPlayerAddItem(winner, random_item, 1)
	end

	return true
end

Code:
<globalevent name="winner" interval="here the hour in interval numbers" event="script" value="script name.lua"/>

Good Luck.

Can you explain why you have lottery_hour inside the config?
 
I never credit myself :O, I taken the event from my server datapack and there's no credits in the script. :P
 
Back
Top