English Send message to spesific user group

3 replies
Goto Page
To the start Previous 1 Next To the start
Up
limonata
User
Offline Off
Hi, how i can sent message to a list of usgn id?

For example:

Code:
1
2
3
4
5
6
admins = {1,2,3}

function sendMsgToAdmins(){
     local adm_id = ??
     msg2(adm_id,"This msg is for admins only.")
}
03.04.16 10:23:40 pm
Up
VADemon
User
Offline Off
I'd start off with a different table (dictionary) to store admin USGNs in:
Code:
1
2
3
4
admins = {
   [50998] = true,
   [7844] = true
}

With this table you can easily check a USGN:
Code:
1
2
3
if admins[ player(id, "usgn") ] == true then
   msg(player(id, "name") .. " is an admin")
end


Full code iterates through existing players and checks their USGNs:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
admins = {
   [50998] = true,
   [7844] = true
}

function sendMsgToAdmins(messageText)
   local playerList = player(0, "table")

   for i = 1, #playerList do
      local id = playerList[i]
      
      if admins[ player(id, "usgn") ] == true then
          msg2(id, messageText)
      end
   end
end


Ultimately all you need to do is to call the function:
Code:
1
sendMsgToAdmins("Hello, Moto!")


UPDated: See user Hajt's post
edited 1×, last 04.04.16 03:07:53 pm
03.04.16 10:38:50 pm
Up
limonata
User
Offline Off
Thank you, worked fine. Also i got the logic.
03.04.16 11:08:59 pm
Up
Hajt
User
Offline Off
@user VADemon: You don't need to convert player(id,"usgn") to number, have a look at this:
Code:
1
print(type(player(id, "usgn")))   --> number
Yooo. We are playing mix matches 5on5 in evening hours on the server CS2D.TK | Mix/Match, you can join us, server password is match. Statistics, leaderboard can be found under the following link.
To the start Previous 1 Next To the start