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

这段触发怎么简化?

[复制链接]
发表于 2007-11-19 07:21:49 | 显示全部楼层 |阅读模式
[codes=jass]
function Master1B_Conditions takes nothing returns boolean
    if ( GetUnitAbilityLevel(GetAttackedUnitBJ(), 'BNba') > 0 )  then
    return true
    endif
    return false
endfunction

function Master1B_Actions takes nothing returns nothing
    local integer i = ( GetUnitAbilityLevel(udg_Master1, 'A04H') * 21 )
    local unit a3 = GetAttackedUnitBJ()
    local player pl = GetOwningPlayer(a3)
    local location p
    if ( GetUnitState(a3, UNIT_STATE_LIFE) >= I2R(i) ) then
    call SetUnitLifeBJ( a3, ( GetUnitState(a3, UNIT_STATE_LIFE) - I2R(i) ) )
    else
    set p = GetUnitLoc(GetAttackedUnitBJ())
    call KillUnit( a3 )
    call ReviveHeroLoc( a3, p , false )
    call SetUnitOwner( a3, Player(11), false )
    call UnitShareVision( a3, pl, true )
    endif
endfunction

function M1B_con takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetAttacker()) == 'NC14' ) ) then
        return false
    endif
    return true
endfunction

function M1B_act takes unit x returns nothing
    local unit x = GetAttackedUnitBJ()
    local trigger t
//    if  ( IsUnitInGroup(x, udg_G_beattack) == false )  then
//    call GroupAddUnit( udg_G_beattack, GetAttackedUnitBJ() )
//    endif
    set t = CreateTrigger()
//    if ( IsUnitInGroup( x , udg_G_beattack) == true )

    call TriggerRegisterUnitEvent(t, x, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition( t, Condition( function Master1B_Conditions ) )
    call TriggerAddAction( t, function Master1B_Actions )
//    endif
endfunction

//===========================================================================
function InitTrig_Master1B takes nothing returns nothing
    set gg_trg_Master1B = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(0), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(1), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(2), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(3), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(4), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(5), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(6), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Master1B, Player(7), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Master1B, Condition( function M1B_con ) )
    call TriggerAddAction( gg_trg_Master1B, function M1B_act )
endfunction



RTRT,怎么简化?

[/codes]
发表于 2007-11-19 09:26:21 | 显示全部楼层
[codes=jass]
function M1B_act takes unit x returns nothing
      local unit x = GetAttackedUnitBJ()
      local trigger t
//      if   ( IsUnitInGroup(x, udg_G_beattack) == false )   then
//      call GroupAddUnit( udg_G_beattack, GetAttackedUnitBJ() )
//      endif
      set t = CreateTrigger()
//      if ( IsUnitInGroup( x , udg_G_beattack) == true )

      call TriggerRegisterUnitEvent(t, x, EVENT_UNIT_DAMAGED)
      call TriggerAddCondition( t, Condition( function Master1B_Conditions ) )
      call TriggerAddAction( t, function Master1B_Actions )
//      endif
endfunction
[/codes]
错误就素这段拉~
回复

使用道具 举报

 楼主| 发表于 2007-11-19 12:13:17 | 显示全部楼层
我也觉得是
那段我是试验品。。。
但不知道怎么改好
回复

使用道具 举报

发表于 2007-11-19 12:13:36 | 显示全部楼层
你上面的GetAttackedUnitBJ()应该返回null
回复

使用道具 举报

 楼主| 发表于 2007-11-19 12:33:41 | 显示全部楼层
这样做很麻烦呐
怎么简化呢。。。
回复

使用道具 举报

发表于 2007-11-22 16:44:17 | 显示全部楼层
算鸟~ 给你个DD参考下吧~~
Lich的冻结之矢技能,攻击时一定几率冻结目标并造成伤害

[codes=jass]
function Lich_FrostAttack_End takes nothing returns nothing
    local integer tm = h2i(GetExpiredTimer())
    local integer trg = GetStoredInteger(udg_GC,I2S(tm),"Trigger")
    local integer tc = GetStoredInteger(udg_GC,I2S(tm),"TriggerCondition")
    local integer u = GetStoredInteger(udg_GC,I2S(tm),"Target")
    call FlushStoredInteger(udg_GC,I2S(u),"Lich_FrostAttack_Timer")
    call FlushStoredMission(udg_GC,I2S(tm))
    call TriggerRemoveCondition(i2tg(trg),i2tc(tc))
    call DestroyTrigger(i2tg(trg))
    call DestroyTimer(i2tm(tm))
endfunction

function Lich_FrostAttack_Cond takes nothing returns nothing
    local unit u = GetTriggerUnit()
    if GetUnitAbilityLevel(u,'B00I') > 0 then
        call UnitRemoveAbility(u,'B00I')
        set udg_TempUnit = GetEventDamageSource()
        call SetUnitFrost(u,0.25*(3+GetUnitAbilityLevel(udg_TempUnit,'A08L'))+0.3*GetWiz(udg_TempUnit))     //冻结并对目标造成伤害, 这里有几个是自定义函数
        call UnitDamageTarget(udg_TempUnit,u,30+10*GetUnitAbilityLevel(udg_TempUnit,'A08L'),true,true,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_COLD,WEAPON_TYPE_WHOKNOWS)
    endif
    set u = null
endfunction

function Lich_FrostAttack_Start takes nothing returns nothing
    local integer u = h2i(GetEventTargetUnit())
    local integer tm = GetStoredInteger(udg_GC,I2S(u),"Lich_FrostAttack_Timer")
    local trigger trg
    if tm == 0 then
        set tm = h2i(CreateTimer())
        set trg = CreateTrigger()
        call TriggerRegisterUnitEvent(trg,i2u(u),EVENT_UNIT_DAMAGED)
        call StoreInteger(udg_GC,I2S(tm),"TriggerCondition",h2i(TriggerAddCondition(trg, Condition(function Lich_FrostAttack_Cond))))
        call StoreInteger(udg_GC,I2S(tm),"Trigger",h2i(trg))
        call StoreInteger(udg_GC,I2S(tm),"Target",u)
        call StoreInteger(udg_GC,I2S(u),"Lich_FrostAttack_Timer",tm)
    endif
    call UnitAddAbility(GetTriggerUnit(),'A08N')
    call TimerStart(i2tm(tm),9,false,function Lich_FrostAttack_End)     //被攻击单位在9秒内不受到攻击则删除take damage触发相关,如果受到攻击则重置计时为9秒,这么做要比多次的添加/删除触发有效率的多
    set trg = null
endfunction

function Lich_FrostAttack takes nothing returns nothing     //一定几率攻击时发动效果
    local integer i = GetHeroInt(GetTriggerUnit(),true)
    if i >= GetRandomInt(1,500+2*i) then
          call Lich_FrostAttack_Start()
      else
          call UnitRemoveAbility(GetTriggerUnit(),'A08N')   //A08N是辅助用致命一击技能,用来获取攻击时的buff的
    endif
endfunction

function Lich_LearnSkill takes nothing returns nothing      //第一次学习技能时注册触发
    if GetLearnedSkillLevel()==1 and GetLearnedSkill() == 'A08L' then
        call SetPlayerAbilityAvailable(GetOwningPlayer(GetTriggerUnit()),'A08N',false)
        set udg_TempTrigger = CreateTrigger()
        call TriggerRegisterUnitEvent(udg_TempTrigger,GetTriggerUnit(),EVENT_UNIT_TARGET_IN_RANGE)
        call TriggerAddCondition(udg_TempTrigger, Condition(function Lich_FrostAttack))
    endif
endfunction

function Skill_Lich takes nothing returns nothing    //触发事件已在其它地方注册
    local integer p = GetPlayerId(GetOwningPlayer(udg_TempUnit))
    call TriggerAddCondition(trg_LearnSkill[p], Condition(function Lich_LearnSkill))
endfunction
[/codes]
回复

使用道具 举报

 楼主| 发表于 2007-11-22 19:43:09 | 显示全部楼层

谢谢老狼
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-24 19:02 , Processed in 0.118178 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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