English hudtxt2 (lua)

8 replies
Goto Page
To the start Previous 1 Next To the start
17.06.13 10:04:57 pm
Up
limonata
User
Offline Off
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:
Code:
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
18.06.13 05:27:18 am
Up
Blighted Song
User
Offline Off
Here is my revised code, it works fine on my machine.

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

Code:
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.
edited 3×, last 18.06.13 05:45:24 am
18.06.13 10:57:53 am
Up
UBMaster
BANNED
Offline Off
Problem:
Code:
1
parse('hudtxt2 '..k..' 0 "'..tx..'" 500 100 -1')

Edit:
Code:
1
parse('hudtxt2 '..k..' 1 "'..tx..'" 500 100 -1')
18.06.13 12:29:38 pm
Up
limonata
User
Offline Off
user UBMaster has written:
Problem:
Code:
1
parse('hudtxt2 '..k..' 0 "'..tx..'" 500 100 -1')

Edit:
Code:
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 ?
19.06.13 12:45:40 am
Up
Blighted Song
User
Offline Off
This is untested, but I think it should work.

Code:
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
19.06.13 12:57:38 am
Up
limonata
User
Offline Off
LUA ERROR: sys/lua/asd.lua:153: attempt to concatenate global 'memberText' (a nil value)
19.06.13 01:18:55 am
Up
Rainoth
Moderator
Offline Off
user limonata has written:
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.
19.06.13 04:20:57 am
Up
Blighted Song
User
Offline Off
I tested the code on my machine and all I got was a missed 'then' statement. The fixed code is as follows.

Code:
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.
19.06.13 02:28:59 pm
Up
limonata
User
Offline Off
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.
To the start Previous 1 Next To the start