搜索
查看: 1990|回复: 5

get_user_team会返回哪几个值,下面的代码老是index out of round

[复制链接]
发表于 2007-6-20 10:47:07 | 显示全部楼层 |阅读模式 来自 山东烟台
1 魔兽里面的skills.inl 76行
if ( Verify_Skill(id, RACE_BLOOD, SKILL1) ){                       
                new Float:randomnumber = random_float(0.0,1.0)
                new teamnumber = get_user_team(id)
                if (randomnumber <= p_pheonix[p_data[id][P_SKILL1]-1]){
                        p_data_b[id][PB_PHOENIXCASTER] = true
                        //这里应该加上点判断,我认为!
                        PhoenixFound[teamnumber-1]++
                }
        }
PhoenixFound[teamnumber-1]++这句,指不定什么时候就出个索引超出范围,是因为teamnumber没判断,还是id是否有效没判断?
 楼主| 发表于 2007-6-20 10:58:57 | 显示全部楼层 来自 山东烟台

回复: get_user_team会返回哪几个值,下面的代码老是index out of round

/* Get team directly from player's entity.
* 1 = terrorist
* 2 = counter-terrorist
* 3 = spectator
*/
enum CsTeams {
        CS_TEAM_UNASSIGNED = 0,
        CS_TEAM_T = 1,
        CS_TEAM_CT = 2,
        CS_TEAM_SPECTATOR = 3
};
这是定义的常数
回复

使用道具 举报

 楼主| 发表于 2007-6-20 11:40:52 | 显示全部楼层 来自 山东烟台

回复: get_user_team会返回哪几个值,下面的代码老是index out of round

常数定义了        new PhoenixFound[2]
是不是改成3会好,因为存在旁观者3
回复

使用道具 举报

发表于 2007-6-20 12:10:13 | 显示全部楼层 来自 福建漳州

回复: get_user_team会返回哪几个值,下面的代码老是index out of round

返回值应该在0~3之间吧,所以要定义一个带4个元素的数组,即PhoenixFound[4].
使用时就PhoenixFound[teamnumber]++就行了,不要再减1了。
回复

使用道具 举报

 楼主| 发表于 2007-6-23 15:26:40 | 显示全部楼层 来自 山东烟台

回复: get_user_team会返回哪几个值,下面的代码老是index out of round

实践后,-1是必须的,否则会出现无法复活队友的情况,大家如果也存在warcraft3ft.amxx 2.3.2报错,Runtime error 4(索引超限) 这个错误,只需要把定义的new PhoenixFound[2]改成new PhoenixFound[4],顺便再一次感谢rulzy版主的大力支持。
回复

使用道具 举报

 楼主| 发表于 2007-7-3 10:49:25 | 显示全部楼层 来自 山东烟台

回复: get_user_team会返回哪几个值,下面的代码老是index out of round

1 魔兽里面的skills.inl 76行
if ( Verify_Skill(id, RACE_BLOOD, SKILL1) ){
new Float:randomnumber = random_float(0.0,1.0)
new teamnumber = get_user_team(id)
if (randomnumber <= p_pheonix[p_data[id][P_SKILL1]-1]){
p_data_b[id][PB_PHOENIXCASTER] = true
//这里应该加上点判断,我认为!
//实际上确实应该加判断,否则索引改成4依然出错
if (!(teamnumber == 0)){
PhoenixFound[teamnumber-1]++
}
}
}
回复

使用道具 举报

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

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