Tricks in CS2D Scripting that you might not know.
49 repliesAll of them | 29.23% (19) | |
None of them | 40.00% (26) | |
A few of them | 30.77% (20) |
65 votes cast
Creating your own iterator.
Now you can use it like
Note: each function works like ipairs but it returns the value first.
Code:
1
2
3
4
5
6
7
8
9
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
index = index + 1
return table[index], index
end
function each(table)
return iterator, 0, table
end
Now you can use it like
Code:
1
2
3
2
3
for id in each(player(0, "table")) do
print(id)
end
print(id)
end
Note: each function works like ipairs but it returns the value first.
I'm awesome ... and I really like cookies.
Name/Password generator in Lua.
Maybe it's not hard but useful
Maybe it's not hard but useful

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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)
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)
@
The Gajos: It generates a random string and saves it. What kind of trick is it?


Trust me, I'm an engineer |
DC approved
Super extra mod for CS2D (64), yeah!



@
MixTape: A function that loops through tables.
Example of ipairs iterator
It would output:
1 - A
2 - B
3 - C
4 - D

Example of ipairs iterator
Code:
1
2
3
4
2
3
4
tab = {"A", "B", "C", "D"}
for key, value in ipairs(tab) do
print(key.." - "..value)
end
for key, value in ipairs(tab) do
print(key.." - "..value)
end
It would output:
1 - A
2 - B
3 - C
4 - D


Btw, may your generetor can be nice for understood things, but as a real password generator it's very bad. Sorry.
CS2DArchive - Version Database www.CS2DArchive.com - WebHosting: www.BroHosting.eu
@
The Gajos: You can use math.random to generate random number from 65 to 90 and transform it into character with string.char
Replace 65 with 97 and 90 to 122 to generate lowercase character instead

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
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


This one might really intrigue you, but some of you might know this.
So what are the 2 values that CS2D console will print?
Maybe you are expecting
well it's not actually. These are the values:
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.
Code:
1
2
3
4
5
6
7
8
9
10
11
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))
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
Code:
1
2
2
true
true
true
well it's not actually. These are the values:
Code:
1
2
2
true
false
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.
I'm awesome ... and I really like cookies.
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.
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.
edited 2×, last 15.09.16 11:48:30 pm
Software has no limits.