Forum

> > CS2D > Scripts > Random timer and random give?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Random timer and random give?

14 replies
To the start Previous 1 Next To the start

old Random timer and random give?

ZaibatsuTEAM
User Off Offline

Quote
Probably a bad title, but anyway -
I want some help to make a timer that chooses times from 300,000 milliseconds to 3,600,000 millisecond. and whenever some random amount of time was chosen inbetween these values, you'll be given 5 to 500 "gems" (random amount inbetween that too)

My gems are called "yourgem" in the scripts.

Any help?

old Re: Random timer and random give?

VADemon
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function newGiveaway()
	local randomGiveawayTime = math.random(300000, 3600000)
	timer(randomGiveawayTime, "doGiveaway")
end
newGiveaway()	-- call the function as soon the server starts?

function doGiveaway()
	local playerList = player(0, "table")
	local targetPlayer = math.random(1, #playerList)
	
	newGiveaway()	-- launch next timer
	-- give muney here:
	msg2(targetPlayer, "You lucky dumbass!")
end
Should work.

old Ty!

ZaibatsuTEAM
User Off Offline

Quote
Thanks VADemon! Just what I needed

Edit: Uh, it actually does not start the function newGiveaway() on server start... I tried changing the values from (300000, 3600000)
to (3000, 5000) to see if it worked, but nothing - the message isn't shown. I did try and add addhook("second","newGiveaway") on top of everything.. but it started spamming the message
edited 1×, last 19.10.15 03:58:47 pm

old Re: Random timer and random give?

VADemon
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function newGiveaway()
     local randomGiveawayTime = math.random(3000, 3600)
     timer(randomGiveawayTime, "doGiveaway")
end
newGiveaway()     -- call the function as soon the server starts?

function doGiveaway()
     local playerList = player(0, "table")
     local targetPlayer = playerList[math.random(1, #playerList)] -- little fix here
     
     newGiveaway()     -- launch next timer
     -- give muney here:
     msg2(targetPlayer, "You lucky dumbass!")
end

old uhhh

ZaibatsuTEAM
User Off Offline

Quote
Still not starting on server start though so idk xd
That message should pop up inbetween 3000 to 3600 MS but it doesnt ;o

edit: it works on a new fresh cs2d server with no other scripts than just that... hmm
edited 1×, last 19.10.15 04:26:12 pm

old Re: Random timer and random give?

Gaios
Reviewer Off Offline

Quote
user ZaibatsuTEAM has written
it works on a new fresh cs2d server with no other scripts than just that... hmm

For me it should work even with other scripts. Don't have* anything that can damage another script.
edited 1×, last 19.10.15 04:52:50 pm

old ty

ZaibatsuTEAM
User Off Offline

Quote
ty rainoth, will check that

edit: nope i dont find any freetimers stuffs or anything with the same variables.... epic

Edit 2: It did work when i did the addhook("second","newGiveaway") but it started spamming the timer so more and more text started to spam the server. It's something with the startup thing that doesnt work.

Edit 3: LUA ERROR: sys/lua/autorun/1aawtf.lua:9: bad argument #2 to 'random' (interval is empty)

Edit 4: Trying with no scripts again. and now it doesnt work and gives me the error i provieded in edit 3.
edited 4×, last 19.10.15 06:04:59 pm

old Re: Random timer and random give?

VADemon
User Off Offline

Quote
In the autorun folder:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function newGiveaway()
     local randomGiveawayTime = math.random(3000, 3600)
     timer(randomGiveawayTime, "doGiveaway")
end
newGiveaway()     -- call the function as soon the server starts?

function doGiveaway()
     local playerList = player(0, "table")
     local targetPlayer = playerList[math.random(1, #playerList)]
     
     newGiveaway()     -- launch next timer
     -- give muney here:
     msg(os.date("%H:%M:%S") .. " ".. player(targetPlayer, "name") .." (" .. targetPlayer ..") won the lottery!")
end

UPD: https://youtu.be/nZ6hNzqo5Ig

old okay uh

ZaibatsuTEAM
User Off Offline

Quote
So I just figured out that the script works only on listen server but doesn't work on dedicated... uhmm xd

because on dedicated it gives me the same error *still*

old Re: Random timer and random give?

VADemon
User Off Offline

Quote
Yea, the player list is empty when the server is empty, makes sense

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function newGiveaway()
     local randomGiveawayTime = math.random(3000, 3600)
     timer(randomGiveawayTime, "doGiveaway")
end
newGiveaway()     -- call the function as soon the server starts?

function doGiveaway()
	newGiveaway()     -- launch next timer
	
	local playerList = player(0, "table")
	
	if #playerList <= 2 then	-- less than N players/bots online?
		return -- do not raffle
	end
	
	local targetPlayer = playerList[math.random(1, #playerList)]
		
     -- give muney here:
     msg(os.date("%H:%M:%S") .. " ".. player(targetPlayer, "name") .." (" .. targetPlayer ..") won the lottery!")
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview