English Improved AddHook 2 icon

9 comments
22.07.13 01:16:54 am
like 5 like it!
2 kb, 89 Downloads
EnderCrypt
User
Offline Off
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
Code:
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
imageimage
edited 13×, last 12.09.15 11:23:47 pm
ok This file has been reviewed and approved by Infinite Rain (11.12.15 07:33:04 am)

Comments

9 comments
Goto Page
To the start Previous 1 Next To the start

Log in!

You need to log in to be able to write comments!Log in
31.07.13 09:57:05 pm
like I like it!
Up
NicolasProRGames
User
Offline Off
very god
31.07.13 06:49:47 pm
Up
DC
Admin
Offline Off
@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.
24.07.13 12:18:51 pm
like I like it!
Up
MikuAuahDark
User
Offline Off
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:
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?
24.07.13 09:35:19 am
Up
DC
Admin
Offline Off
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.
24.07.13 08:48:42 am
like I like it!
Up
mr_s
User
Offline Off
thanks, my hook wont add correctly now they will be added
22.07.13 11:15:34 am
like I like it!
Up
Avo
User
Offline Off
It is always better to use ... as arguments list if you edit a function. All in all, nicely done.
22.07.13 03:24:25 am
Up
EnderCrypt
User
Offline Off
@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)
22.07.13 03:06:54 am
like I like it!
Up
krabob
User
Offline Off
haha perfect timing. Just today I had a conflicting-hook problem that I didn't feel like fixing
22.07.13 02:45:08 am
Up
pbeloto
User
Offline Off
the Addhook2 lager??

you fps in immage is 18 ¬¬'

#Edit
Code:
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