English Tricks in CS2D Scripting that you might not know.

49 replies
Goto Page
To the start Previous 1 2 3 Next To the start
Poll Poll
How many tricks have you already know?
Only registered users are allowed to vote
All of them
29.23% (19)
None of them
40.00% (26)
A few of them
30.77% (20)
65 votes cast
25.06.15 05:47:08 pm
Up
Ortimh
User
Offline Off
Creating your own iterator.
Code:
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
Code:
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.
I'm awesome ... and I really cookies
26.07.15 09:57:07 am
Up
The Gajos
BANNED
Offline Off
Name/Password generator in Lua.
Maybe it's not hard but useful
Code:
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)
27.07.15 11:49:52 am
Up
Avo
User
Offline Off
@user The Gajos: It generates a random string and saves it. What kind of trick is it?
27.07.15 03:49:53 pm
Up
MixTape
User
Offline Off
@user Ortimh: what is "iterator"? im newbie.
27.07.15 06:06:12 pm
Up
_Yank
User
Offline Off
@user MixTape: A function that loops through tables.

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


It would output:
1 - A
2 - B
3 - C
4 - D
28.07.15 02:27:10 am
Up
sqpp15
Super User
Offline Off
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.
28.07.15 04:32:53 am
Up
Lee
Moderator
Offline Off
You can always roll your own secure hash function though.

https://github.com/kikito/md5.lua
30.07.15 02:03:37 pm
Up
MikuAuahDark
User
Offline Off
@user The Gajos: You can use math.random to generate random number from 65 to 90 and transform it into character with string.char
Code:
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
Hello? Are you there, Tae Hanazono?
03.06.16 12:16:59 pm
Up
Ortimh
User
Offline Off
This one might really intrigue you, but some of you might know this.
Code:
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
Code:
1
2
true
true

well it's not actually. These are the values:
Code:
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.
I'm awesome ... and I really cookies
12.09.16 01:57:59 pm
Up
Livia
User
Offline Off
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.
edited 2×, last 15.09.16 11:48:30 pm
Software has no limits.
To the start Previous 1 2 3 Next To the start