找回密码
 点一下
查看: 2561|回复: 7

怎样写选取单位匹配条件的Jass语句

[复制链接]
发表于 2008-4-11 20:18:37 | 显示全部楼层 |阅读模式
RT``怎样写选取单位匹配条件的Jass语句....最好详细点
发表于 2008-4-11 20:35:43 | 显示全部楼层
以下是选取单位组常使用的函数,参数中有一个boolexpr参数类型,用来过滤选取的单位。
[jass]native GroupEnumUnitsInRange takes group whichGroup,real x,real y,real radius,boolexpr filter returns nothing
native GroupEnumUnitsInRangeOfLoc takes group whichGroup,location whichLocation,real radius,boolexpr filter returns nothing
native GroupEnumUnitsInRect takes group whichGroup,rect r,boolexpr filter returns nothing
native GroupEnumUnitsOfPlayer takes group whichGroup,player whichPlayer,boolexpr filter returns nothing
native GroupEnumUnitsOfType takes group whichGroup,string unitname,boolexpr filter returns nothing
native GroupEnumUnitsSelected takes group whichGroup,player whichPlayer,boolexpr filter returns nothing
[/jass]
创建一个boolexpr:
[jass]
native Condition takes code func returns conditionfunc
[/jass]
在归类上,boolexpr属于conditionfunc类型,其使用方法如下:
[jass]
function IsFitlerUnitAlive takes nothing returns boolean
    return GetUnitState( GetFitlerUnit(), UNIT_STATE_LIFE) >= 0.00
endfunction
function EnumAliveUnit takes nothing returns group
local group g = CreateGroup()
local boolexpr b = Condition( function IsFitlerUnitAlive )
call GroupEnumUnitsInRange( g, 0.00, 0.00, 9999999, b)
call DestroyBoolExpr(b)
set b = null
return g
endfunction
[/jass]
回复

使用道具 举报

 楼主| 发表于 2008-4-11 21:14:23 | 显示全部楼层
谢了哈    [s:124]
回复

使用道具 举报

 楼主| 发表于 2008-4-11 21:22:23 | 显示全部楼层
但是选出这些单位后的动作要写在哪里?.....
回复

使用道具 举报

发表于 2008-4-11 23:19:18 | 显示全部楼层
用ForGroup( group, code)
回复

使用道具 举报

 楼主| 发表于 2008-4-15 12:45:01 | 显示全部楼层
呼 终于学会了= =.......................
回复

使用道具 举报

发表于 2008-4-16 18:14:52 | 显示全部楼层
单位组动作的简化也是推荐写法:
例:
[jass]
globals
group udg_TempGroup=CreateGroup()    //全局公用临时变量
endglobals

function GroupFunc takes nothing returns nothing
    if xxx then
        do anything
    endif
endfunction

call GroupEnumUnitsInRange( udg_TempGroup, 0., 0, 1000, Condition( function GroupFunc))
[/jass]

udg_TempGroup其实只素个摆设而已,GroupFunc是return nothing的,也即永远返回false,不会有任何单位被加到udg_TempGroup,该代码的作用就是选取满足条件的单位作xx动作,相比较ForGroup要精简也要高效的多
回复

使用道具 举报

发表于 2008-4-17 19:09:00 | 显示全部楼层
老狼似乎很喜欢在过滤函数中写主体动作,之前是省了触发动作,现在又省了ForGroup,那么对有boolexpr参数的触发事件函数,是不是连触发条件也可以省了
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-23 02:25 , Processed in 0.033703 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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