simon3003 发表于 2009-7-25 13:30:21

get_user_frags怎么返回总是零?

我编了一个插件,能通过编译,但运行没效果,发现:
for (new i_player = 0; i_player < i_numplayers; i_player++)
{
   new i_deaths = get_user_deaths( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_deaths)
    new i_frags = get_user_frags( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_frags)
是上面出问题了,我把上面的语句放到每局开始时运行,每次屏幕上打印的都是零,怎么看这语句都没错啊,希望达达能帮帮我,万分感谢!

LittleKu 发表于 2009-7-25 14:19:38

你应该这样!new players, pnum
for (new i = 0; i < pnum; i++)
{
new id = players
new i_deaths = get_user_deaths(id)
new i_frags = get_user_frags(id)
client_print(id, print_chat, "this is a example, your kill %d, and death %d times", i_frags, i_deaths)

lnjkming 发表于 2009-7-25 16:53:46

写法不对,应该是
for (new i_player = 1; i_player < =32; i_player++)
{
    if (!is_user_connected(i)
      continue;
new i_deaths = get_user_deaths( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_deaths)
    new i_frags = get_user_frags( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_frags)

LittleKu 发表于 2009-7-25 17:40:53

3# lnjkming


有什么不对?哪里不对了!
你能解释一下哪个函数用错了吗?

lnjkming 发表于 2009-7-25 21:39:53

搞错,是这样,:dizzy:,呵呵
for (new i_player = 1; i_player < =32; i_player++)
{
    if (!is_user_connected(i_player)
      continue;
new i_deaths = get_user_deaths( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_deaths)
    new i_frags = get_user_frags( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_frags)

simon3003 发表于 2009-7-26 07:59:38

谢谢楼上的两位,我把代码装上去运行一下,回来报告结果!

simon3003 发表于 2009-7-26 08:13:26

用了lnjkming 的代码,编译无法通过,用了kk阿朗 ,编译能过,但运行显%D的地方还是0,这就奇怪了,这语句没毛病啊

lnjkming 发表于 2009-7-26 20:04:57

这样,刚上面的符号有误,:dizzy:

for (new i_player = 1; i_player <=32; i_player++)
{
    if (!is_user_connected(i_player))
      continue;
   new i_deaths = get_user_deaths( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_deaths)
    new i_frags = get_user_frags( i_player)
    client_print(i_player, print_chat, "*******%d*******!.",i_frags)
   
   
}

Rulzy 发表于 2009-7-27 21:56:53

遍历玩家使用循环从1开始,到maxplayers结束比较好,效果比较高。另外,最好不要在循环里定义变量。new i_deaths, i_frags
new maxplayers = get_maxplayers();
for (new i_player=1; i_player<=maxplayers; i_player++)
{
    if(!is_user_connected(i_player)) continue;
    i_deaths = get_user_deaths(i_player)
    client_print(i_player, print_chat, "*******%d*******!.", i_deaths)
    i_frags = get_user_frags( i_player)
    client_print(i_player, print_chat, "*******%d*******!.", i_frags)
}甚至可以定义一个全称变量 g_maxplayers, 在plugin_init中赋值 g_maxplayers = get_maxplayers();
然后在循环中从1至g_maxplayers,这样效率更高一些。

LittleKu 发表于 2009-7-27 22:46:56

本帖最后由 kk阿朗 于 2009-7-27 22:48 编辑

不好意思,少了个函数!
new players, pnum
get_players(players, pnum)
for (new i = 1; i < pnum; i++)
{
new id = players
new i_deaths = get_user_deaths(id)
new i_frags = get_user_frags(id)
client_print(id, print_chat, "this is a example, your kill %d, and death %d times", i_frags, i_deaths)
}还想顺便请教一下R版
上我这个跟你那究竟哪个会好一点?new i_deaths, i_frags
new maxplayers = get_maxplayers();
for (new i_player=1; i_player<=maxplayers; i_player++)
{
    if(!is_user_connected(i_player)) continue;
    i_deaths = get_user_deaths(i_player)
    client_print(i_player, print_chat, "*******%d*******!.", i_deaths)
    i_frags = get_user_frags( i_player)
    client_print(i_player, print_chat, "*******%d*******!.", i_frags)
}
页: [1] 2
查看完整版本: get_user_frags怎么返回总是零?