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

大家帮我看看这个函数是怎么了?

[复制链接]
发表于 2009-4-4 01:07:45 | 显示全部楼层 |阅读模式
刷怪的,具体思路我也晓得,也检查不出毛病。
但就是不刷怪....
第一个   地图开始1秒的时候
function SetUnitXY takes nothing returns nothing
    local integer i = GetStoredInteger(udg_Cache,"变量","i")
    call StoreInteger(udg_Cache,"变量","i", i+1) //累加变量 i
    call SetUnitUserData( GetEnumUnit(), i )  // 设置单位自定义值为i
    call StoreReal(udg_Cache,"刷新点","X"+I2S(i), GetUnitX(GetEnumUnit()))  //储存单位X轴
    call StoreReal(udg_Cache,"刷新点","Y"+I2S(i), GetUnitY(GetEnumUnit()))  //储存单位Y轴
endfunction

function Trig_Map_Actions takes nothing returns nothing
    local player p = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local group g = CreateGroup()
    call CreateUnit( p, 'n001', 1348.6, -4407.6, 61.1 )
    call CreateUnit( p, 'n001', 1274.2, -4466.6, 60.5 )
    call GroupEnumUnitsInRect(g,GetPlayableMapRect(),null)  //新建单位组(全地图内的所有单位)
    call ForGroup(g,function SetUnitXY) //选取单位组内单位做动SetUnitXY
    call DestroyGroup(g)  //删除单位组
    set g = null
    call DestroyTrigger( GetTriggeringTrigger() )  //删除当前触发
endfunction

//===========================================================================
function InitTrig_Map takes nothing returns nothing
    set gg_trg_Map = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Map, 1.00 )
    call TriggerAddAction( gg_trg_Map, function Trig_Map_Actions )
endfunction
第二个  刷怪的
function Trig_kill_Conditions takes nothing returns boolean
    local integer i = GetUnitFoodMade(GetTriggerUnit())  //获取单位提供人口
    local integer j = GetUnitUserData(GetTriggerUnit())  //获取单位自定义值
    local effect e = null
    local unit u = null
    local real x
    local real y
    if i > 0 and not IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) then
       //提供人口大于0 且  触发单位不是一个英雄
       set x = GetStoredReal(udg_Cache,"刷新点","X"+I2S(j)) //读取单位X轴
       set y = GetStoredReal(udg_Cache,"刷新点","Y"+I2S(j)) //读怪单位Y轴
       if IsUnitHidden(GetTriggerUnit()) then  //单位是显示的
          set u = CreateUnit(GetOwningPlayer(GetTriggerUnit()), GetUnitTypeId(GetTriggerUnit()), x, y, 180)
          //创建单位
          call SetUnitUserData( u, j ) //设置单位自定义值
          set e = AddSpecialEffectTarget("Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl",u,"origin")
          //创建特效在单位身上
          call DestroyEffect( e ) //删除特效
       else
          set u = CreateUnit(GetOwningPlayer(GetTriggerUnit()), GetUnitTypeId(GetTriggerUnit()), x, y, 180)
          call UnitApplyTimedLife( u, 'BHwe', i ) //设置单位生命计时器
          call SetUnitUserData( u, j )   //设置单位自定义值
          call ShowUnit( u,false ) //隐藏单位
       endif
    endif
    set e = null
发表于 2009-4-4 12:51:31 | 显示全部楼层
你这个触发写得真是囧...具体过程就不分析了.其实要想达到这样的效果,还有更简洁的方法.

估计你是单位提供人口数没有设置好...你可以加几个debug在触发里看看.
我把if i > 0 and not IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) then改成if i >= 0 and not IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) then, call UnitApplyTimedLife( u, 'BHwe', i ) 改成call UnitApplyTimedLife( u, 'BHwe', i+1 ) 之后一切正常,说明其他部分没有问题..
回复

使用道具 举报

 楼主| 发表于 2009-4-4 13:06:20 | 显示全部楼层
加几个debug在触发里?
怎么加?
回复

使用道具 举报

发表于 2009-4-4 14:04:59 | 显示全部楼层
比如说call BJDebugMsg(I2S(i)),这样,在测试的时候你就能知道函数运行时i的值是多少.
回复

使用道具 举报

 楼主| 发表于 2009-4-4 14:39:13 | 显示全部楼层
哦,这么个Debug哦

弱弱的问一下
仁兄不是说有更好的方法么?
可以透露一下么
回复

使用道具 举报

 楼主| 发表于 2009-4-4 22:30:36 | 显示全部楼层
引用第3楼cctvfive于2009-04-04 14:04发表的  :
比如说call BJDebugMsg(I2S(i)),这样,在测试的时候你就能知道函数运行时i的值是多少.
听了仁兄的建议我测试了一下
call BJDebugMsg(I2S(i))  返回i的值是10
call BJDebugMsg(I2S(j))  返回j的值是0
这说明j设置有问题么?
回复

使用道具 举报

发表于 2009-4-5 13:46:10 | 显示全部楼层
[jass]function SetUnitXY takes nothing returns boolean
    call StoreReal(udg_Cache,I2S(H2I(GetFilterUnit())),"X",GetUnitX(GetFilterUnit()))
    call StoreReal(udg_Cache,I2S(H2I(GetFilterUnit())),"Y",GetUnitY(GetFilterUnit()))
    return false
endfunction

function Trig_Test_Actions takes nothing returns nothing
    local group g = CreateGroup()         
    call CreateUnit(Player(12),'ewsp',500,500,270)
    call CreateUnit(Player(12),'ewsp',500,-500,270)
    call GroupEnumUnitsInRect(g,GetPlayableMapRect(),Condition(function SetUnitXY))
    call DestroyGroup(g)  
    set g = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Test, 1.00 )
    call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction

function Trig_Kill_Actions takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local player p=GetOwningPlayer(u)
    local integer typeid=GetUnitTypeId(u)
    local integer i=GetUnitFoodMade(u)
    local unit tempunit
    local real x
    local real y
    if i > 0 and not IsUnitType(u,UNIT_TYPE_HERO) then
      set x=GetStoredReal(udg_Cache,I2S(H2I(u)),"X") //读取单位X轴
      set y=GetStoredReal(udg_Cache,I2S(H2I(u)),"Y") //读怪单位Y轴
      call TriggerSleepAction(I2R(i))
      set tempunit=CreateUnit(p, typeid, x, y, 180)
      call StoreReal(udg_Cache,I2S(H2I(tempunit)),"X",GetUnitX(tempunit))
      call StoreReal(udg_Cache,I2S(H2I(tempunit)),"Y",GetUnitY(tempunit))
      call DestroyEffect(AddSpecialEffectTarget("Abilities\\\\Spells\\\\Undead\\\\RaiseSkeletonWarrior\\\\RaiseSkeleton.mdl",tempunit,"origin"))
    endif
    set u=null
    set p=null
    set tempunit=null
endfunction

//===========================================================================
function InitTrig_Kill takes nothing returns nothing
    set gg_trg_Kill = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Kill, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Kill, function Trig_Kill_Actions )
endfunction[/jass]
要是地图打不开的话,这是全部代码(不包括H2I函数和初始化缓存),你加到自己的图中试验一下,看看是不是你想要的效果.

For Test.w3x

18 KB, 下载次数: 10

回复

使用道具 举报

发表于 2009-4-7 12:14:44 | 显示全部楼层
这段代码MS是我写的,至于为什么不使用timer或等待计时而用隐藏单位的方法是有原因的,
1.用等待不精确,而且不适用长时间的等待
2.用计时器太复杂不适合要这系统的作者(需求者是个J肓)
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-5 23:38 , Processed in 0.115830 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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