Forum

> > CS2D > Scripts > Tricks in CS2D Scripting that you might not know.
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Tricks in CS2D Scripting that you might not know.

49 Antworten
Seite
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang

Umfrage Umfrage

How many tricks have you already know?

Nur registrierte Benutzer können abstimmen
All of them
29,23% (19)
None of them
40,00% (26)
A few of them
30,77% (20)
65 Stimmen abgegeben

alt Re: Tricks in CS2D Scripting that you might not know.

Dousea
User Off Offline

Zitieren
Creating your own iterator.
1
2
3
4
5
6
7
8
9
local function iterator(index, table)
	index = index + 1
	
	return table[index], index
end

function each(table)
	return iterator, 0, table
end
Now you can use it like
1
2
3
for id in each(player(0, "table")) do
	print(id)
end
Note: each function works like ipairs but it returns the value first.

alt Re: Tricks in CS2D Scripting that you might not know.

The Gajos
BANNED Off Offline

Zitieren
Name/Password generator in Lua.
Maybe it's not hard but useful
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
path = 'names.txt'
file = io.open(path,'w')

for i = 1,100 do
	local str = ''
	local maxx = 6
	for j = 1,maxx do
		local item = math.random(1,chars:len())
		str = str..chars:sub(item,item)
	end
	file:write(str..'\n')
end

file:close()
print('©000255000Names has been generated to '..path)

alt Re: Tricks in CS2D Scripting that you might not know.

Marcell
Super User Off Offline

Zitieren
user The Gajos: Maybe if user DC could integrate LuaJIT well, then MD5 module would be great to us to generate passwords or something like that. But since it was discarded we cannot do it.

Btw, may your generetor can be nice for understood things, but as a real password generator it's very bad. Sorry.

alt Re: Tricks in CS2D Scripting that you might not know.

MikuAuahDark
User Off Offline

Zitieren
@user The Gajos: You can use math.random to generate random number from 65 to 90 and transform it into character with string.char
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local path="names.txt"
local file=io.open(path,"w")
local maxx=6

-- Method 1 - Write directly
for i=1,100 do
	for j=1,maxx do
		file:write(string.char(math.random(65,90)))
	end
	file:write("\n")
end

-- Method 2 - table.concat
for i=1,100 do
	local t={}
	for j=1,maxx do
		t[j]=string.char(math.random(65,90))
	end
	file:write(table.concat(t,"").."\n")
end

file:close()
print("©000255000Names has been generated to "..path)

Replace 65 with 97 and 90 to 122 to generate lowercase character instead

alt Re: Tricks in CS2D Scripting that you might not know.

Dousea
User Off Offline

Zitieren
This one might really intrigue you, but some of you might know this.
1
2
3
4
5
6
7
8
9
10
11
local t = {
	v = true
}

function f(l)
	l.v = false
end

print(tostring(t.v))
f(t)
print(tostring(t.v))
So what are the 2 values that CS2D console will print?
Maybe you are expecting
1
2
true
true
well it's not actually. These are the values:
1
2
true
false
Yes, tables in Lua will send their address. You can modify a table's value within a function, within another file, within another module like ease. What can you do with this feature? Well a lot actually. I can't name you one. You might want to figure it out yourself.

alt Re: Tricks in CS2D Scripting that you might not know.

Livia
User Off Offline

Zitieren
You can register player click events by giving him landmines and returning 1 on buildattempt hook whenever he tries to place one. It only works for left click but it's completely silent unlike knife setups.

Edit:
You can also register click events with mouse locations by equipping the player a portal gun and doing some packet inspection on server side. Whenever player shoots the portal gun it will include the cursor location data. Didn't test satchel/grenades though.
2× editiert, zuletzt 15.09.16 23:48:30
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht