魔兽地图编辑器吧 关注:65,544贴子:3,843,714
  • 8回复贴,共1

移动单位的函数|演示|模板类函数

只看楼主收藏回复

//用途:移动单位.. 可以代替所有每0.02秒移动单位的触发
//多次调用函数不冲突(就是可以多人使用)


//必须做的是地图初始化的时候,创建游戏缓存
//在触发器里设置一个变量 GC , 类型为游戏缓存
//然后设置 GC = 最后创建的游戏缓存


//函数调用方法:
//call MoveUnit(单位,实数,整数,实数,"字符串")
//参数类型:说明
//单位:要移动的单位whichUnit
//实数:要移动的方向angle
//整数:移动速度speed
//实数:持续时间time
//字符串:特效

//实例:
//    事件
//        单位 - 任意单位 发动技能效果
//    条件
//        (施放技能) 等于 月牙天冲 
//    动作
//        设置 l[0] = ((触发单位) 的位置)
//        设置 l[1] = (技能施放点)
//        设置 r = (l[0] 到 l[1] 的角度)
//        设置 u = (新建 ((触发单位) 的所有者) 的 月牙 在 l[0] 面向角度:r 度)
//        设置 e = Abilities\Spells\Undead\FrostNova\FrostNovaTarget.mdl
//        单位 - 设置 1.00 秒 水元素 类型的生命周期对 u
//        自定义代码: call MoveUnit(udg_u,udg_r,1500,1,udg_e)


//地图自定义脚本:


//必须函数h2i 如果地图里有就不用复制了
function h2i takes handle h returns integer
return h
return 0
endfunction

//同上
function i2u takes integer i returns unit
return i
return null
endfunction

//同上
function i2l takes integer i returns location
return i
return null
endfunction

//循环移动
function MoveUnit_actions takes nothing returns nothing
    local location array l
    local timer t = GetExpiredTimer()
    local unit ua = i2u(GetStoredInteger(udg_GC,"unit",I2S(h2i(t))))
    set l[0] = GetUnitLoc(ua)
    set l[1] = PolarProjectionBJ(l[0], I2R(GetStoredInteger(udg_GC,"speed",I2S(h2i(t)))), GetStoredReal(udg_GC,"angle",I2S(h2i(t))))
    call SetUnitPositionLoc( ua, l[1] )
    call AddSpecialEffectLocBJ( l[0], GetStoredString(udg_GC,"effect",I2S(h2i(t))) )
    call DestroyEffect( GetLastCreatedEffectBJ() )
    call RemoveLocation( l[0] )
    call RemoveLocation( l[1] )
    set l[0] = null
    set l[1] = null
    set t = null
    set ua = null
endfunction

//主体
function MoveUnit takes unit whichUnit , real angle , integer speed , real time , string effects returns nothing
    local timer t = CreateTimer()
    local integer i = speed/50
    call StoreInteger(udg_GC,"unit",I2S(h2i(t)),h2i(whichUnit))
    call StoreInteger(udg_GC,"speed",I2S(h2i(t)),i)
    call StoreReal(udg_GC,"angle",I2S(h2i(t)),angle)
    call StoreString(udg_GC,"effect",I2S(h2i(t)),effects)
    call TimerStart(t,0.02,true,function MoveUnit_actions)
    call PolledWait( time )
    call FlushStoredInteger(udg_GC,"unit",I2S(h2i(t)))
    call FlushStoredString(udg_GC,"effect",I2S(h2i(t)))
    call FlushStoredInteger(udg_GC,"speed",I2S(h2i(t)))
    call FlushStoredReal(udg_GC,"angle",I2S(h2i(t)))
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
endfunction


1楼2008-06-01 19:11回复
    示例地图:http://tieba.baidu.com/f?kz=393413666


    另外i2l这个函数用不到,可以删除掉..


    2楼2008-06-01 19:20
    回复
      2025-11-09 03:13:42
      广告
      不感兴趣
      开通SVIP免广告
      • 125.127.5.*
      楼上发的东西好复杂~~看不


      3楼2008-06-01 19:21
      回复
        好东西~


        4楼2008-06-01 19:28
        回复
          恩恩看不懂。。


          IP属地:日本5楼2008-06-01 20:22
          回复
            = =!原创申精


            6楼2008-06-01 20:52
            回复
              不懂。。


              IP属地:日本7楼2008-06-01 20:59
              回复
                为何不用坐标...
                我用j就全用坐标的..


                IP属地:福建8楼2008-06-01 21:18
                回复
                  2025-11-09 03:07:42
                  广告
                  不感兴趣
                  开通SVIP免广告
                  不懂。。


                  IP属地:日本9楼2008-06-01 21:19
                  回复