找回密码
 点一下
查看: 1221|回复: 6

获取地上满足条件物品的代码问题

[复制链接]
发表于 2009-9-24 15:42:17 | 显示全部楼层 |阅读模式
在地上放了一推物品
分别属于不同的玩家
不同玩家物品有不同的等级
自己写了个函数
但是发现没有用
哪个环节出错了??
[jass]
function GetUnitEquipF takes nothing returns nothing
    set bj_itemRandomCurrentPick=GetFilterItem()
endfunction
function GetUnitEquipC takes nothing returns boolean
    if(GetItemPlayer(GetEnumItem())!=Player(bj_forLoopAIndex) ) then
        return false
    endif
    if(GetItemType(GetFilterItem())!=ConvertItemType(bj_forLoopBIndex)) then
        return false
    endif
    return true  
endfunction
function GetUnitEquip takes unit u,integer i returns item
    local rect r=Rect(-512,-512,512,512)
    local boolexpr b=Condition(function GetUnitEquipC)
    set bj_forLoopAIndex = GetPlayerId(GetOwningPlayer(u))
    set bj_forLoopBIndex = i
    set bj_itemRandomCurrentPick=null
    call EnumItemsInRect(r,b, function GetUnitEquipF)
    call DestroyBoolExpr(b)
    call RemoveRect(r)
    set b=null
    set r=null
    return bj_itemRandomCurrentPick   
endfunction
[/jass]
发表于 2009-9-24 15:43:59 | 显示全部楼层
你可以先用触发来实现,然后转成jass后再作修改和优化,恩
回复

使用道具 举报

 楼主| 发表于 2009-9-25 17:59:35 | 显示全部楼层
引用第1楼zhuzeitou于2009-09-24 15:43发表的  :
你可以先用触发来实现,然后转成jass后再作修改和优化,恩

自己写了个函数
但是发现没有用
哪个环节出错了??
[jass]
function GetUnitEquipF takes nothing returns nothing
    set bj_itemRandomCurrentPick=GetFilterItem()
endfunction
function GetUnitEquipC takes nothing returns boolean
    if(GetItemPlayer(GetEnumItem())!=Player(bj_forLoopAIndex) ) then
        return false
    endif
    if(GetItemType(GetFilterItem())==ConvertItemType(bj_forLoopBIndex)) then
        return false
    endif
    return true  
endfunction
function GetUnitEquip takes unit u,integer i returns item
    local rect r=Rect(-512,-512,512,512)
    local boolexpr b=Condition(function GetUnitEquipC)
    set bj_forLoopAIndex = GetPlayerId(GetOwningPlayer(u))
    set bj_forLoopBIndex = i
    set bj_itemRandomCurrentPick=null
    call EnumItemsInRect(r,b, function GetUnitEquipF)
    call DestroyBoolExpr(b)
    call RemoveRect(r)
    set b=null
    set r=null
    return bj_itemRandomCurrentPick   
endfunction
[/jass]
回复

使用道具 举报

发表于 2009-9-25 18:19:36 | 显示全部楼层
…………把GetUnitEquipF中的
GetFilterItem()
改成
GetEnumItem()
也不好好看看到底是选取条件还是选取动作就瞎放GetFilter/Enum…………
EnumItem最后的code执行的是选取动作函数。
也就是说,在这个code里应该用GetEnumItem捕捉物品………………
而在Condition里的code使用GetFilterXXX是正确的。
回复

使用道具 举报

 楼主| 发表于 2009-9-25 19:03:22 | 显示全部楼层
多谢了
还问下下
把判断写在条件里和写在动作里哪个好些
[jass]
function GetUnitEquipF takes nothing returns nothing
    if(GetItemPlayer(GetEnumItem())!=Player(bj_forLoopAIndex) ) then
        return
    endif
    if(GetItemType(GetEnumItem())!=ConvertItemType(bj_forLoopBIndex)) then
        return
    endif
    set bj_itemRandomCurrentPick=GetEnumItem()
endfunction
function GetUnitEquip takes unit u,integer i returns item
    local rect r=Rect(-512,-512,512,512)
    set bj_forLoopAIndex = GetPlayerId(GetOwningPlayer(u))
    set bj_forLoopBIndex = i
    set bj_itemRandomCurrentPick=null
    call EnumItemsInRect(r,null, function GetUnitEquipF)
    call RemoveRect(r)
    set r=null
    return bj_itemRandomCurrentPick   
endfunction
[/jass]
回复

使用道具 举报

发表于 2009-9-25 19:45:35 | 显示全部楼层
写在动作里
回复

使用道具 举报

发表于 2009-9-25 19:56:51 | 显示全部楼层
………………LS啊……………………这个………………
为什么啊…………
干吗写在动作里。
看情况,要是觉得条件方便就写条件里,动作方便就写动作里。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-7-22 04:18 , Processed in 0.029913 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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