English Hide text after command

11 replies
Goto Page
To the start Previous 1 Next To the start
26.05.18 07:21:54 pm
Up
tos12345678
User
Offline Off
Hi, i don't know why text - !help reveals itself with !help cmd

Code:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("say","say_help")
function say_help(id,txt)
     if(txt=="!help") then
          msg2(id,"Commands:")
          msg2(id,"©100255100!asdasd - allasdas")
          msg2(id,"©100255100!asdas - asdasd")
          msg2(id,"©100255100!asdasd - sasd")
          msg2(id,"©100255100!asdasd - asdasdasdasd")
          msg2(id,"©100255100!iasdasdasd - casda")
          return 1
     end
end



I need a answer how to hide text !help after i enter this
because return is not working
26.05.18 07:52:10 pm
Up
Quattro
GAME BANNED
Offline Off
it works, must be some other part of your script interfering.
26.05.18 08:10:41 pm
Up
tos12345678
User
Offline Off
Can you tell me detail?
26.05.18 08:18:18 pm
Up
Multiple 'say hooks' may cause this problem
26.05.18 10:28:10 pm
Up
Masea
Super User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("say","say_help", 1)
function say_help(id,txt)
     if(txt=="!help") then
          msg2(id,"Commands:")
          msg2(id,"©100255100!asdasd - allasdas")
          msg2(id,"©100255100!asdas - asdasd")
          msg2(id,"©100255100!asdasd - sasd")
          msg2(id,"©100255100!asdasd - asdasdasdasd")
          msg2(id,"©100255100!iasdasdasd - casda")
          return 1
     end
end
Try this.
edited 1×, last 26.05.18 10:39:24 pm
Shit your pants: file cs2d Outlast II Mod (29) | Create your UI faster: CS2D UI Framework
26.05.18 11:12:02 pm
Up
tos12345678
User
Offline Off
yea, its work, but for only one say command
other cmds can be seen
edited 1×, last 27.05.18 08:37:09 pm
27.05.18 09:54:32 pm
Up
Masea
Super User
Offline Off
You mean "!help" is not the only command and there are more than that?

Well, let me guess, you probably created cs2d cmd say hooks for each command and this is what causes this situation.

Reduce the cs2d cmd say hooks to single and try to gather all the commands in it. This way we also will keep the spaciousness and intelligibility.

That'd be something like this:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("say","say_help")
function say_help(id,txt)
        if txt:sub(1,1) == "!" then
          local cmd = txt:sub(2)
          if cmd == "help" then

          elseif cmd == "admin" then

          elseif cmd == "kill" then

          end
          return 1
     end
end

Besides, we'll not need to use priority for hooks (not a big deal).
Shit your pants: file cs2d Outlast II Mod (29) | Create your UI faster: CS2D UI Framework
28.05.18 04:03:32 pm
Up
Jenko63
User
Offline Off
Try this

Code:
1
2
3
4
5
6
7
8
addhook("say","say0")
function say0(id,txt)
     if txt == "!help" then
          msg2(id,"Commands:")
          msg2(id,"\169100255100!test")
          return 1
     end
end
JENKO
28.05.18 04:27:07 pm
Up
tos12345678
User
Offline Off
It's fine,
But i wonder why its bug when there is more then one say hook
28.05.18 04:30:47 pm
Up
Talented Doge
User
Offline Off
Quote:
But i wonder why its bug when there is more then one say hook


[u=http://www.cs2d.com/help.php?luacmd=addhook]Priority[/u]
28.05.18 05:23:28 pm
Up
Cure Pikachu
User
Offline Off
sys/lua/info.txt has written:
Priority is only important if there is more than one function attached 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])!

Not a bug as much as it is a limitation of CS2D's Lua engine.
IMG:https://i.imgur.com/DeSeUxC.png
IMG:https://i.imgur.com/xpsyQRX.png
28.05.18 08:40:19 pm
Up
DC
Admin
Offline Off
Yes, it's not a bug. It's like that by design. Just think about it: If there are multiple say hooks CS2D simply does not know which return value it should use. There might be hooks which return 1 but also others with other return values. Which is the value which should change the behavior in the end? CS2D just can't decide automatically here.

You can tell CS2D which value to use by using the priority system.
But like user Masea said the easiest approach is to put everything into one single hook.

There are also other approaches to tackle this problem. E.g.
• add a say hook with priority -1 which sets a global variable
sayReturn = 0
(you can call the variable whatever you like this is just an example)
• add a say hook with priority 1 which just returns that global variable:
return sayReturn

• now in ALL other say hooks you do NOT specify a priority at all. This way they are executed after your -1 hook but before your 1 priority hook. Also you do not use return 1 but instead you set
sayReturn = 1


> Result: You can now add as many say hooks as you want and as soon as ANY of these hooks "returns 1" (sets sayReturn to 1), CS2D will not show the original say text anymore.

CS2D just provides a basic API to interact with the game. Sometimes it makes sense to build something on top of that to make your life easier
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
To the start Previous 1 Next To the start