搜索
查看: 1746|回复: 2

请教server_print的问题

[复制链接]
发表于 2008-4-25 14:33:05 | 显示全部楼层 |阅读模式 来自 中国–辽宁–沈阳
public client_disconnect(id)
{
if(!id || is_user_bot(id) || !(CAF_DISCONNECT & get_pcvar_num(g_cvarMode)))
  return

new szUserName[32];
get_user_name(id, szUserName, 31);

new iPlayers[32], iNum, i;
get_players(iPlayers, iNum, "c"); // skip_bots

new bool:bSound = get_pcvar_num(g_cvarSound) == 1
new x
new szMessage[164]

for(i=0; i<iNum; i++)
{
  x = iPlayers;
  
  if(!is_user_connected(x)) continue;
  
  if(bSound)
   client_cmd(x, "spk %s", g_szSoundFile);
  
  formatex(szMessage, 163, "^x04%s disconnected", szUserName);
  console_print(x, szMessage)//Sends a message to a player's console
  server_print(szMessage)//Prints a message to the server console
  
  message_begin(MSG_ONE, g_iMsgSayText, _, x);
  write_byte(id);
  write_string(szMessage);
  message_end();
}
}
为什么玩家disconnect的时候控制台会这样打印:
xx disconnected
xx disconnected
xx disconnected
xx disconnected
xx disconnected
xx disconnected
xx disconnected
xx disconnected
xx disconnected
也就是说一个人退出的时候在控制台打出了很多次而不是我期待的1行``
发表于 2008-4-25 20:56:06 | 显示全部楼层 来自 中国–江西–南昌

回复: 请教server_print的问题

你把 server_print 放在 for(i=0; i<iNum; i++) 循环中,当然会打出很多个啦
回复

使用道具 举报

 楼主| 发表于 2008-4-25 21:42:14 | 显示全部楼层 来自 中国–辽宁–沈阳

回复: 请教server_print的问题

哇 疏忽了!!忘了server_print是给控制台的消息,我还当给每个客户端一个呢...
感谢提醒啊!!! 我猪头了 哈哈
另外那个帖子也很感谢你的回答~~~~
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表