Forum

> > CS2D > Scripts > Hide text after command
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hide text after command

11 replies
To the start Previous 1 Next To the start

old Hide text after command

tos12345678
User Off Offline

Quote
Hi, i don't know why text - !help reveals itself with !help cmd

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

old Re: Hide text after command

Masea
Super User Off Offline

Quote
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

old Re: Hide text after command

Masea
Super User Off Offline

Quote
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:
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).

old Re: Hide text after command

Jenko63
User Off Offline

Quote
Try this

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

old Re: Hide text after command

Cure Pikachu
User Off Offline

Quote
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.

old Re: Hide text after command

DC
Admin Off Offline

Quote
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
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview