Forum

> > CS2D > Scripts > random name from table...
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch random name from table...

14 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt random name from table...

loldlold123
User Off Offline

Zitieren
İ need table,

STEP1:
When your playerjob[id]=1
add player's name to table
STEP2:
math.random table values
parse("hudtxt2 "..id.." "..random 1 name from table.."")
STEP3:
when player leave from game,remove his name from table if his name there in table.


i need this system

alt Re: random name from table...

TimeQuesT
User Off Offline

Zitieren
Why you don't script it by yourself!?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
table = {};

function vAddPlayer()
for id=1,32 do
if (player(id,"exists")) then
table[id] = player(id,"name");
else
table[id] = nil;
end
end
end

function vSelectPlayer()
iRand = math.random(1,32);
if (table[iRand]!=nil) then
--code for hud
else
vSelectPlayer();  //be warned if there is no player on the server it can crash ;)
end
end

alt Re: random name from table...

Flacko
User Off Offline

Zitieren
You could use player(0,'table') instead of guessing ids so you don't have to check all that stuff

And
Zitat
parse("hudtxt2 "..id.." "..random 1 name from table.."")

wtf...

alt Re: random name from table...

TimeQuesT
User Off Offline

Zitieren
Check the amount of players on the server before recalling the function

@Flacko -->
I just use a good followable way (if you don't care about the length of you script you can use my way, else Flackos ;))

alt Re: random name from table...

Kel9290
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
awesometable={}
-- step 1
if playerjob[id]==1 then
	table.insert(awesometable,id)
	print(id.." inserted.")
end
--step 2
	yeah=#player(0,"table")
	dat = math.random(1,yeah)
	print("random - "..dat)
	parse("something "..player(dat,"name").." <---")
--step 3
addhook("leave","epicleave")
function epicleave(id)
	table.remove(awesometable,id)
	print(id.." removed.")
end

btw, tablestutorial.
Spoiler >

alt Re: random name from table...

IWhoopedPythagoras
BANNED Off Offline

Zitieren
user Kel9290 hat geschrieben
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
awesometable={}
-- step 1
if playerjob[id]==1 then
	table.insert(awesometable,id)
	print(id.." inserted.")
end
--step 2
	yeah=#player(0,"table")
	dat = math.random(1,yeah)
	print("random - "..dat)
	parse("something "..player(dat,"name").." <---")
--step 3
addhook("leave","epicleave")
function epicleave(id)
	table.remove(awesometable,id)
	print(id.." removed.")
end

btw, tablestutorial.
Spoiler >



This is so wrong.


1
2
3
4
5
--step2
yeah = player(0,"table")
dat = yeah[math.random(1,#yeah)]
print("random - "..dat)
parse("something "..player(dat,"name").." <---")

You should read the tables tutorial yourself.

alt Re: random name from table...

Ultimate programmer
BANNED Off Offline

Zitieren
@TimeQuesT write scripts with Tabs!Scripts without tabs was made by loosers!Use special programs as Programmer's Notepad.

Random:
1
2
3
4
5
6
7
8
number=player(pl,"team")+pl*37...--add where all you want
randomcount=5 --example random:1,2,3,4,5
	while (number>randomcount) do
	number=number-randomcount
	end
	--it's mean number mod randomcount or
	--number%randomcount
answer=number

As function:
1
2
3
4
5
6
7
8
function random(number,randomcount)
	while (number>randomcount) do
	number=number-randomcount
	end
return number
end

some=random(player(pl,"team")+pl*37,5)

alt Re: random name from table...

EngiN33R
Moderator Off Offline

Zitieren
user IWhoopedPythagoras hat geschrieben
user Kel9290 hat geschrieben
-snip-


This is so wrong.


1
2
3
4
5
--step2
yeah = player(0,"table")
dat = yeah[math.random(1,#yeah)]
print("random - "..dat)
parse("something "..player(dat,"name").." <---")

You should read the tables tutorial yourself.


Okay, how is your code more right than his? What's wrong with his step 2?

alt Re: random name from table...

IWhoopedPythagoras
BANNED Off Offline

Zitieren
user EngiN33R hat geschrieben
user IWhoopedPythagoras hat geschrieben
user Kel9290 hat geschrieben
-snip-


This is so wrong.


1
2
3
4
5
--step2
yeah = player(0,"table")
dat = yeah[math.random(1,#yeah)]
print("random - "..dat)
parse("something "..player(dat,"name").." <---")

You should read the tables tutorial yourself.


Okay, how is your code more right than his? What's wrong with his step 2?


Because of the following.

the player(0,"table") will return a table like this:


yeah = {1=1,15=15,31=31}

assuming the players with id 1,15 and 31 are alive.

however #yeah will return 3...
math.random(1,3) will return a id between 1 and 3. but id 2 and 3 is not alive.

alt Re: random name from table...

EngiN33R
Moderator Off Offline

Zitieren
But player(0,"table") returns the following, if I'm not mistaken:

1
yeah = {[1]=1,[2]=15,[3]=31}

but not

1
yeah = {[1]=1,[15]=15,[31]=31}

No? If it does so indeed, then your code makes sense, but if it returns a table like you've written it (example #2 I provided) then your code won't work as well.

alt Re: random name from table...

IWhoopedPythagoras
BANNED Off Offline

Zitieren
You are right. But my code holds.
I checked it and the table is automatically filled.


So it's like

1
yeah = {[1] = 1,[2]=5,[3]=6}
When player with id 5 leaves it will be:

1
yeah = {[1] = 1, [2] = 6}

when someone joins, he gets the lowest available id.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht