Forum

> > CS2D > Scripts > hudtxt2 (lua)
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch hudtxt2 (lua)

8 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt hudtxt2 (lua)

limonata
User Off Offline

Zitieren
Hi, please fix my mistake. Only members can use this command -> !msg <text> when any member join the game just he can see the that message.
For example:
I wrote: !msg guys come to sH for cw!
if any member join the game he can see the this message
if its not member he cant see. Thanks

My try:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Members = {50998}

addhook("say","_say")
function _say(id,txt)
	for _, u in ipairs(Members) do
	 	if player(id,"usgn") == u then
			for id = 1,#Members do
				if txt:sub(1,4) == "!msg" then
					local tx = txt:sub(6)
					parse('hudtxt2 '..id..' 0 "'..tx..'" 500 100 -1')
					return 1
				end
			end
		end
	end
end

alt Re: hudtxt2 (lua)

Blighted Song
User Off Offline

Zitieren
Here is my revised code, it works fine on my machine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Members = {50998}

addhook("say","_say")
function _say(id,txt)
     for i, j in ipairs(Members) do
           if player(id,"usgn") == j then
               for k = 1, #Members do
                    if txt:sub(1,4) == "!msg" then
                         local tx = txt:sub(6)
                         parse('hudtxt2 '..k..' 0 "'..tx..'" 500 100 -1')
                    end
               end
          end
     end
return 1
end

Not sure what your problem was, but I just changed your second 'id' to k and your '_' to i.

EDIT 1:

Hold up, saw your problem, you are using a normal for loop the second time, meaning you are not actually getting your members id. You need another loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Members = {50998}

addhook("say","_say")
function _say(id,txt)
	for i,j in ipairs(Members) do
		if player(id,"usgn") == j then
			if txt:sub(1,4) == "!msg" then
				for k = 1, 32 do
					for l, m in ipairs(Members) do
						if(player(k,"usgn") == m) then
							local tx = txt:sub(6)
							parse('hudtxt2 '..k..' 0 "'..tx..'" 500 100 -1')
						end
					end
				end
			end
		end
	end
return 1
end

That should send it to all the 'Members'.

EDIT 2:

You should also be returning at the end of the function, so that all the players get the text, not just the first one.

My code could be cleaner than this, but I think it should work.
3× editiert, zuletzt 18.06.13 05:45:24

alt Re: hudtxt2 (lua)

UBMaster
BANNED Off Offline

Zitieren
Problem:
1
parse('hudtxt2 '..k..' 0 "'..tx..'" 500 100 -1')
Edit:
1
parse('hudtxt2 '..k..' 1 "'..tx..'" 500 100 -1')

alt Re: hudtxt2 (lua)

limonata
User Off Offline

Zitieren
user UBMaster hat geschrieben
Problem:
1
parse('hudtxt2 '..k..' 0 "'..tx..'" 500 100 -1')
Edit:
1
parse('hudtxt2 '..k..' 1 "'..tx..'" 500 100 -1')


No, problem. It works fine.

But i need to update it. Because when a member joined the game he cant see the hud. It should be update into join jook. May you add it ?

alt Re: hudtxt2 (lua)

Blighted Song
User Off Offline

Zitieren
This is untested, but I think it should work.

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
27
28
29
30
Members = {50998}
memberText = ""
addhook("say","_say")
function _say(id,txt)
     for i,j in ipairs(Members) do
          if player(id,"usgn") == j then
               if txt:sub(1,4) == "!msg" then
		memberText = txt:sub(6)
                    for k = 1, 32 do
                         for l, m in ipairs(Members) do
                              if(player(k,"usgn") == m) then
                                   parse('hudtxt2 '..k..' 0 "'..memberText..'" 500 100 -1')
                              end
                         end
                    end
               end
          end
     end
return 1
end

addhook("join", "_join")
function _join(id)
for i,j in ipairs(Members) do
	if (player(id,"usgn") == j)
		parse('hudtxt2 '..id..' 0 "'..memberText..'" 500 100 -1')
	end
end

end

alt Re: hudtxt2 (lua)

limonata
User Off Offline

Zitieren
LUA ERROR: sys/lua/asd.lua:153: attempt to concatenate global 'memberText' (a nil value)

alt Re: hudtxt2 (lua)

Rainoth
Moderator Off Offline

Zitieren
user limonata hat geschrieben
LUA ERROR: sys/lua/asd.lua:153: attempt to concatenate global 'memberText' (a nil value)


Add "\" or "/" outside "'..memberText..'" not sure which one. Might help.

alt Re: hudtxt2 (lua)

Blighted Song
User Off Offline

Zitieren
I tested the code on my machine and all I got was a missed 'then' statement. The fixed code is as follows.

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
27
28
29
30
Members = {50998}
memberText = ""

addhook("say","_say")
function _say(id,txt)
     for i,j in ipairs(Members) do
          if player(id,"usgn") == j then
               if txt:sub(1,4) == "!msg" then
          memberText = txt:sub(6)
                    for k = 1, 32 do
                         for l, m in ipairs(Members) do
                              if(player(k,"usgn") == m) then
                                   parse('hudtxt2 '..k..' 0 "'..memberText..'" 500 100 -1')
                              end
                         end
                    end
               end
          end
     end
return 1
end

addhook("join", "_join")
function _join(id)
	for i,j in ipairs(Members) do
		 if (player(id,"usgn") == j) then
			  parse('hudtxt2 '..id..' 0 "'..memberText..'" 500 100 -1')
		 end
	end
end

The error you posted did not show when I ran it, if you modified my script then you need to post it. And from the looks of things you have more than just this running, I don't know if that is relevant or not but my script should work by its self.

alt Re: hudtxt2 (lua)

limonata
User Off Offline

Zitieren
No, it wont solve the problem. I already put the "then".

We didnt define the memberText in the join hook. This is the problem. It is nil. I will work on it. Thanks for your helps.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht