Files

> > CS2D > Lua Scripts > Improved AddHook 2
Files overviewCS2D overviewLua Scripts overview

English Improved AddHook 2 >

9 comments2 kb, 476 Downloads

old Improved AddHook 2

EnderCrypt
User Off Offline

addhook2 version 1.2

whats new in version 1.1?
Spoiler >


when do i need this?
Spoiler >


why do i need it?
Spoiler >


i designed this to solve conflicts caused when several say hooks was in use at the same time, causing return 1 not to work, if another lua returned 0 after, this would cause chat commands to apper in chat, even due a lua returned 1 properly, addhook2 does not only priorities return 1, it also ONLY adds 1 normal cs2d hook for each hook your lua adds, possibly improving the efficiency of the inbuilt cs2d addhook

add this line in server.lua
1
dofile("sys/lua/addhook2.lua")
assuming you placed the file in sys/lua

IMPORTANT: you must dofile this lua BEFORE all other luas in your sever.lua (you do this, by placing the dofile line BEFORE all other dofiles), you do NOT need to make any changes to your existing lua's
edited 13×, last 12.09.15 11:23:47 pm
Approved by Infinite Rain

Download Download

2 kb, 476 Downloads

Comments

9 comments
To the start Previous 1 Next To the start

Log in!

You need to log in to be able to write comments!Log in

old

DC
Admin Off Offline

@user MikuAuahDark: Then you didn't understand how priority works! Read cs2d lua cmd addhook.
Quote
Priority is only important if there is more than one function attachted to the same hook!
Default is 0, higher numbers = higher priority, lower numbers (also negative) = lower priority.
The attached function with the HIGHEST priority is the LAST function which will be executed.
Moreover CS2D will take the return value of this function (if there is any)!
In most cases you will just omit the priority parameter (yes, it is [optional])!

In short: It will still execute ALL hooked functions BUT it will take the return value of the function with the highest priority value.

old

MikuAuahDark
User Off Offline

I already make something like this before. Just check file archive.

Well, i give you like because this script just smaller than mine.

To, user DC: i don't know why but even using priority parameter, is still doing what im not expected. Example i use this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("say","temp",1)
function temp(id,txt)
	msg("\169000255000"..player(id,"name")..": "..txt)
	return 1
end

addhook("say","temporary",0)
function temporary(id,txt)
	if txt:sub(1,1)=="!" then
		msg2(id,"OK")
		return 1
	end
	return 0
end
I just expecting the "temp" function is not executed when im says "!" but it still execute "temp" function.
Do i have been doing something wrong? or priority parameter are doing it like that?
I like it!

old

DC
Admin Off Offline

Nice idea but it's better to simply use the priority parameter of the original cs2d lua cmd addhook command. That's why this parameter exists... Just use priority 1 for the hook which uses return to influence the game. No crazy Lua code required.

old

mr_s
User Off Offline

thanks, my hook wont add correctly now they will be added
I like it!

old

Avo
User Off Offline

It is always better to use ... as arguments list if you edit a function. All in all, nicely done.
I like it!

old

EnderCrypt
User Off Offline

@realBoys
not sure if this s how to reply... lol, but anyways,
io.open, with write mode, creates a file if it doesent exist, and, you said somheting about fps drop, thats not really possible, (with exception if you add like a 100 hooks xD, and that would only result in a spike lagg)

old

krabob
User Off Offline

haha perfect timing. Just today I had a conflicting-hook problem that I didn't feel like fixing
I like it!

old

pbeloto
User Off Offline

the Addhook2 lager??

you fps in immage is 18 ¬¬'

#Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function ah2.eval(code)
	file = io.open("sys/lua/eval.lua","w")
	if type(code) == "string" then
		file:write(code)
	end
	if type(code) == "table" then
		i = 0
		while (i < #code) do
			i = i + 1
			file:write(code[i])
		end
	end
	file:close()
	ret = dofile("sys/lua/eval.lua")
	os.remove("sys/lua/eval.lua")
	return ret
end

to that directory and do not have the file?
To the start Previous 1 Next To the start