Forum

> > CS2D > Scripts > Color Say.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Color Say.

21 replies
Page
To the start Previous 1 2 Next To the start

old Color Say.

Blacko
User Off Offline

Quote
Hello everybody !
I search a little Script.
If a Player (With USGN in Script) say "@say Hello" the Hello is in Color with (Admin) but only when he say "@say".
Thanks you a lot !
iDios
us

old Re: Color Say.

Yasday
User Off Offline

Quote
Do it yourself to learn something, some tipps:
Use the "say" hook.
Use the string.sub function.
Use if txt:sub(1, 4) == "@say" then and use the msg function.

old Re: Color Say.

Starkkz
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Admin_Table = {}
RGBCLR = "255255255" -- Color for saying.

function table.find(tab,val)
	for k, v in pairs(tab) do
		if v == val then
			return k
		end
	end
	return false
end

addhook("say","onSay")
function onSay(id,txt)
	if txt == "rank" then
		return 0
	end
	if string.sub(txt,1,4) == "@say" then
		txt = string.sub(txt,6)
		if table.find(Admin_Table,player(id,"usgn")) then
			msg("©"..RGBCLR..player(id,"name").." (Admin): "..txt)
			return 1
		end
	end
end

In the admin table you have to put the USGN List, separed by comma.

Edit: forgot about the @say

old Re: Color Say.

Yasday
User Off Offline

Quote
Come on, Starkkz, people have to learn doing their shit alone and not letting someone else ( like you ) do it.
Even if it's easy and you don't need much time, people have to learn themself, or they will ask again and again...

old Re: Color Say.

Blacko
User Off Offline

Quote
Ok, thanks you Starkkz !
PS : Yasday, i'm not english, so it's too hard to learn...

old Re: Color Say.

Yasday
User Off Offline

Quote
Nope, this
Spoiler >

would do it aswell, but only for one person.

Edit:
It's not to hard to learn, I'm german, not english and I did learn it.
edited 1×, last 16.04.11 05:20:22 pm

old Re: Color Say.

Starkkz
Moderator Off Offline

Quote
Well, yasday. i'm having many free time. And nothing to do, i'm not on my house with my computer and i'm trying to help and lose some time.

old Re: Color Say.

Yates
Reviewer Off Offline

Quote
But what is string.sub?
Cant you just do
1
2
if (text == @say) then
msg("©255255255"..player(id,"name").." (Admin) "..txt)
I don't even know if this works, but it should do the same thing, right?
Edit: Ah wait, must be with usgn aswell for the admin.. Meh can't be arsed to do that. But this should work either way?

old Re: Color Say.

Yasday
User Off Offline

Quote
No, because txt contains the whole text, like if you say "@say Hi!" the txt variable will store the string-value "@say Hi!".
string.sub returns the string from the point(s) you want, like string.sub("hi", 2, 2) returns "i".
Edit:
http://www.lua.org/manual/5.1/manual.html#pdf-string.sub
Spoiler >
edited 1×, last 16.04.11 05:29:53 pm

old Re: Color Say.

Starkkz
Moderator Off Offline

Quote
well. string.sub returns a string into in other.. example:

"HELLO, MY NAME IS STARKKZ"
string.sub 1, 14 returns: "HELLO, MY NAME"
string.sub 16, 17 returns: "IS"
string.sub 19, 25 returns: "STARKKZ"
string.sub 1, 5 returns: "HELLO"

so thats useful to check the string..
with this method you can split strings too.. but i preefer string.gmatch

old Re: Color Say.

Yates
Reviewer Off Offline

Quote
Ahh, lol. Not thinking straight.
I understand why it would not work, but I have to learn more lua. Because I have no idea what you just said about string.sub

old Re: Color Say.

Dovahkin
User Off Offline

Quote
what about this?

1
2
3
4
5
6
addhook("say","what")
function what(id,txt)
if player(id,"name") then
msg("©255255255Citizen = "..player(id,"name").." : "..txt)
end
end

>try if work thanks!

old Re: Color Say.

Yates
Reviewer Off Offline

Quote
Your name is "sh!t" I guess..
You must put this © instead of the question mark in the lua.

old Re: Color Say.

cs2dthailand
User Off Offline

Quote
Yates has written
Your name is "sh!t" I guess..
You must put this © instead of the question mark in the lua.


Thanks for help,but now I have new problem...

That is:

LUA ERROR: sys/lua/test.lua:1: unexpected symbol near 'ï'

LOL,I'm not edited anything in that script.


Admin_Table = {}
RGBCLR = "255255255" -- Color for saying.

function table.find(tab,val)
for k, v in pairs(tab) do
if v == val then
return k
end
end
return false
end

addhook("say","onSay")
function onSay(id,txt)
if txt == "rank" then
return 0
end
if string.sub(txt,1,4) == "@say" then
txt = string.sub(txt,6)
if table.find(Admin_Table,player(id,"usgn")) then
msg("©"..RGBCLR..player(id,"name").." (Admin): "..txt)
return 1
end
end
end

old Re: Color Say.

DC
Admin Off Offline

Quote
save your Lua script in ASCII encoding.

old indent?

Dovahkin
User Off Offline

Quote
cs2dth can you please indent your code so we can understand.

old Re: Color Say.

Surplus
User Off Offline

Quote
@five

Whats indent? If its "tab" it, then:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Admin_Table = {}
RGBCLR = "255255255" -- Color for saying.

function table.find(tab,val)
	for k, v in pairs(tab) do
		if v == val then
	return k
    end
  end
 return false
end

addhook("say","onSay")
	function onSay(id,txt)
		if txt == "rank" then
	return 0
end

if string.sub(txt,1,4) == "@say" then
	txt = string.sub(txt,6)
		if table.find(Admin_Table,player(id,"usgn")) then
			msg("©"..RGBCLR..player(id,"name").." (Admin): "..txt)
		return 1
		end
	end
end
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview