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.

gotya2
GAME BANNED Off Offline

Zitieren
passing functions as parameter, known as higher order function in cs.

1
2
3
4
5
6
function binary_operation(operation_func, operand1, operand2)
        return operation_func(operand1, operand2)
end
function add(o1,o2) return o1+o2 end

print(binary_operation(add,3,4))

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

MikuAuahDark
User Off Offline

Zitieren
Im sorry that im reviving old thread, but here is a some LUA tips & tricks from me

CS2D Related:
> Spawn player without any weapons at all
1
2
3
4
5
6
7
8
condition=true
addhook("die","Miku_Hatsune")
function Miku_Hatsune(id)
	if conditional then
		local x,y=randomentity(player(id,"team")-1)
		parse("spawnplayer "..id.." "..(x*32+16).." "..(y*32+16))
	end
end

And some general LUA tricks:
> Getting LUA filename that call the function
Info: Because debug library still exist in CS2D, this LUA also can be used on Counter-Strike 2D. It just uses a debug.traceback() function
1
2
3
4
5
6
7
8
9
10
11
12
function GetCurrentLUAFilename()
	local traceback_string=debug.traceback():gsub("\t",""):sub(18)
	local index=0
	for line in traceback_string:gmatch("[^\n]+") do
		index=index+1
		if index==2 then
			local t=line:find(":")
			return line:sub(1,t-1)
		end
	end
end
print(GetCurrentLUAFilename()) -- Output "stdin" when you use it at interpreter. If it used on another file, then it output the LUA filename

> Creating a error
1
2
error("Your string here")
-- LUA ERROR: filename.lua:1: Your string here

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

FlooD
GAME BANNED Off Offline

Zitieren
user Lee hat geschrieben
Adding libraries written in C (such as network) to CS2D

Say you put the dlls into the lib folder

1
package.cpath = package.cpath.."./lib/?.dll;../lib/?.dll;../../lib/?.dll;../../../lib/?.dll"


has anyone ever used this (or a similar) technique to make something useful in cs2d?

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

Avo
User Off Offline

Zitieren
Some boolean "tricks".

Mehr >
5× editiert, zuletzt 20.11.13 20:05:15

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

gotya2
GAME BANNED Off Offline

Zitieren
user FlooD hat geschrieben
user Lee hat geschrieben
Adding libraries written in C (such as network) to CS2D

Say you put the dlls into the lib folder

1
package.cpath = package.cpath.."./lib/?.dll;../lib/?.dll;../../lib/?.dll;../../../lib/?.dll"


has anyone ever used this (or a similar) technique to make something useful in cs2d?


Inter server communication with sockets and
a high precision time function in linux.

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

Tobey
User Off Offline

Zitieren
user FlooD hat geschrieben
user Lee hat geschrieben
Adding libraries written in C (such as network) to CS2D

Say you put the dlls into the lib folder

1
package.cpath = package.cpath.."./lib/?.dll;../lib/?.dll;../../lib/?.dll;../../../lib/?.dll"


has anyone ever used this (or a similar) technique to make something useful in cs2d?


uPrate6 did, played around with it too.

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

MikuAuahDark
User Off Offline

Zitieren
> Deleting all selection of menu but make the menu remains.
Note: no menu effect seen at all.
1
2
3
menu(id,"Test,123,456")
-- Later. Delay about 5 seconds
menu(id,"")

> player(id,"weapon") and player(id,"weapontype") is same
Source: Lua Lag Compensation
1
print(player(id,"weapon")==player(id,"weapontype") and "Same" or "Not Same") -- Same

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

omg
User Off Offline

Zitieren
lol yeah, now that i know more about random numbers...that "truly" random number generator is absolute ass wipe. at least in c++, if you try to get reseeded numbers every time, the numbers will actually just be incrementing slowly instead of being random. this is worse than just seeding it once. you actually have to code this and run it to see what im talking about

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

Livia
User Off Offline

Zitieren
You can break out of nested loops with return.

1
2
3
4
5
6
7
8
9
10
11
12
prepare()
do
    for k,v in pairs(var1) do
        for k2,v2 in pairs(var2) do
            if v == v2 then
                match()
                return
            end
        end
     no_match()
end
continue()

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

Starkkz
Moderator Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local BinaryFormat = package.cpath:match("%p[\\|/]?%p(%a+)")
if BinaryFormat == "dll" then
	function os.name()
		return "Windows"
	end
elseif BinaryFormat == "so" then
	function os.name()
		return "Linux"
	end
elseif BinaryFormat == "dylib" then
	function os.name()
		return "MacOS"
	end
end
BinaryFormat = nil
Since everyone was using command line functions to know the operating system, I though it'd be better to post this easier way.

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

Lee
Moderator Off Offline

Zitieren
Tired of having undefined variables returning
nil
s everywhere? Are you suffering from spats of unfotunate speeling mistekes? Then you'll understand how annoying it is to track down one small typo within your goliath of a codebase. Seriously, that's probably the solution to about 30% of all of the questions that are asked in this forum.

I'm not here to debate language decisions; but if I were, I would definitely rank this as one of the most egregious issue with Lua. However, we can fix this!

1
2
3
setmetatable(
  _G,
  {__index = function (_, key) error("Undefined variable " .. key) end })

This line tells Lua to route all undefined global indexing (aka variable resolution for global variables, which is the fallback routine in case local variable resolution fails) through our own function (__index), which just raises an error.

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

Starkkz
Moderator Off Offline

Zitieren
You can spawn objects and know their ids.
1
2
3
4
5
6
7
function spawnobject(type, x, y, rot, mode, team, player)
	if type and x and y then
		rot, mode, team, player = rot or 0, mode or 0, team or 0, player or 0
		parse("spawnobject "..type.." "..x.." "..y.." "..rot.." "..mode.." "..team.." "..player)
		return objectat(x, y, type)
	end
end
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht