找回密码
 点一下
查看: 683|回复: 1

Jass区人气不足所以来了,关于选取匹配单位的问题

[复制链接]
发表于 2012-9-11 15:42:20 | 显示全部楼层 |阅读模式
  1. function GroupFunc takes nothing returns nothing
  2.     if (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(bolt)) == true and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= 0.405) then
  3.         call KillUnit(GetFilterUnit())
  4.     endif
  5. endfunction
  6. function tb takes nothing returns nothing
  7.     local unit bolt = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()),"u001",GetUnitLoc(GetTriggerUnit()),0)
  8.     call GroupEnumUnitsInRange(udg_tempgroup,GetUnitX(caster),GetUnitY(caster),200,Condition(
  9. function GroupFunc))
  10. endfunction
复制代码
一直对于选取符合条件单位做动作不能理解,特别是判定是否为敌的时候对于局部变量的传递。

求帮助,最好能有代码能便于理解。谢谢
发表于 2012-9-11 16:43:58 | 显示全部楼层
[jass]
globals
         unit g_Unit = null
endglobals

function GroupFunc takes nothing returns nothing
    if (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(g_Unit)) == true and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= 0.405) then
        call KillUnit(GetFilterUnit())
    endif
endfunction

function tb takes nothing returns nothing
    local unit bolt = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()),"u001",GetUnitLoc(GetTriggerUnit()),0)
    set g_Unit = bolt
    call GroupEnumUnitsInRange(udg_tempgroup,GetUnitX(caster),GetUnitY(caster),200,Condition(function GroupFunc))
endfunction[/jass]
如果不想多弄个全局可以这么写:
[jass]
function GroupFunc takes nothing returns nothing
    if (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(bj_lastCreatedUnit)) == true and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= 0.405) then
        call KillUnit(GetFilterUnit())
    endif
endfunction

function tb takes nothing returns nothing
    local unit bolt = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()),"u001",GetUnitLoc(GetTriggerUnit()),0)
    set bj_lastCreatedUnit = bolt
    call GroupEnumUnitsInRange(udg_tempgroup,GetUnitX(caster),GetUnitY(caster),200,Condition(function GroupFunc))
endfunction[/jass]
当然如果这个bolt不需要在等待或计时器后仍旧能用话直接set g_Unit = CreateUnit( …… )

用哈希表的方法如下:
[jass]
globals
    hashtable g_HT = InitHashtable()
endglobals

function GroupFunc takes nothing returns nothing
    if (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(LoadUnitHandle(g_HT, StringHash("这里用唯一的字符串"), 0))) == true and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= 0.405) then
        call KillUnit(GetFilterUnit())
    endif
endfunction

function tb takes nothing returns nothing
    local unit bolt = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()),"u001",GetUnitLoc(GetTriggerUnit()),0)
    local integer pkey = StringHash("这里用唯一的字符串")
    call SaveUnitHandle( g_HT, pkey, 0, bolt )
    call GroupEnumUnitsInRange(udg_tempgroup,GetUnitX(caster),GetUnitY(caster),200,Condition(function GroupFunc))
    call RemoveSavedHandle( g_HT, pkey, 0 )
endfunction[/jass]


话说我不是在JASS区回复你了嘛。。。
还有标签不要用code,那个没高亮,用jass
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-7-3 09:21 , Processed in 0.080970 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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