Forum

> > CS2D > Scripts > Spawn two random items
Forums overviewCS2D overview Scripts overviewLog in to reply

English Spawn two random items

3 replies
To the start Previous 1 Next To the start

old Spawn two random items

Powermonger
User Off Offline

Quote
Hello scripters,

I have here another (simple) problem.
How can I return two random values?

Here's my script:

1
2
3
4
5
6
7
items={1,2,3,4,5,6,10,11,20,21,22,23,24,30,31,32,33,34,35,36,37,38,39,91,40,45,46,47,48,49,88,90,69,74,78,85,51,52,53,72,73,75,76,86,89,77,87,41,57,58,61,62,64,65,79,80,84}

addhook("spawn","zombie_spawn")
function zombie_spawn()
        weapons={items[math.random(1,57)],items[math.random(1,57)]}
        return weapons
end

Is there a way to pick two random values from one table to another (from "items" to "weapons") or can I do
1
return items[math.random(1,57)]
twice?

OR is there an easier way to do this which I don't know about?

Thanks in advance for your reply
mOnger

old Re: Spawn two random items

Starkkz
Moderator Off Offline

Quote
Yeah, twice.

1
2
3
4
5
function twoValues()
	return "a", "b"
end

myValueA, myValueB = twoValues()

or in numbers...
1
2
3
4
5
function threeNumbers()
	return 1, 2, 3
end

numberA, numberB, numberC = threeNumbers()

You can return as much as you want

Btw: In spawn hook you have to put it with comma also, CS2D doesn't search for tables in hooks as far as I know.

old Re: Spawn two random items

Powermonger
User Off Offline

Quote
Dam I should script at night...

If it was daytime I wouldn't have been this dum

But hey, thanks for your help.
I appreciate that you'll help tired idiots like me

I think I need to sleep now...

mOnger


edit: oh yea, this thread can be closed, for sure.

old Re: Spawn two random items

VADemon
User Off Offline

Quote
Starkz,
1
return items[math.random(1,#items)],items[math.random(1,#items)]
No functions or other shit...
PS: Can be slightly improved by locals

PS: You can create a function that returns as many values (weapons) as you want simply by using table.insert and for
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview