找回密码
 点一下
查看: 3542|回复: 5

个人函数(修正和补充)

[复制链接]
发表于 2008-9-5 16:32:47 | 显示全部楼层 |阅读模式
个人函数(修正和补充)发布一些常用的函数,有自己做的,也有收集来的(主要还是自己做的,没有全部测试,有错误希望大家提出来)
这次主要是补充一些函数
欢迎各位继续添加
[codes=jass]globals
//创建游戏缓存GC
    gamecache udg_GC
//以下是为了减少游戏缓存的使用做的全局变量和攻击类函数的攻击系数和防御系数,有利于使用者利用
//攻击系数   
    real array              udg_AbilityAttackCoefficient
//防御系数
    real array              udg_AbilityRrcoveryCoefficient
//全局变量(只用于瞬间的计算)
    group array             udg_Instantaneous_group
    real array              udg_Instantaneous_real
    integer array           udg_Instantaneous_integer
    location array          udg_Instantaneous_piont
    unit array              udg_Instantaneous_unit
endglobals
function InitGlobals takes nothing returns nothing
    local integer i = 0
    set i = 0
    loop
        exitwhen (i > 12)
        set udg_AbilityAttackCoefficient = 1.00
        set i = i + 1
    endloop    set i = 0
    loop
        exitwhen (i > 12)
        set udg_AbilityRrcoveryCoefficient = 0
        set i = i + 1
    endloop    set i = 0
    loop
        exitwhen (i > 3)
        set udg_Instantaneous_group = CreateGroup()
        set i = i + 1
    endloop    set i = 0
    loop
        exitwhen (i > 3)
        set udg_Instantaneous_real = 0
        set i = i + 1
    endloop    set i = 0
    loop
        exitwhen (i > 3)
        set udg_Instantaneous_integer = 0
        set i = i + 1
    endloop
endfunction
//转型函数
function H2I takes handle h returns integer
      return h
      return 0
endfunction
function I2H takes integer h returns handle
      return h
      return null
endfunction
function H2S takes handle h returns string
      return I2S(H2I(h))
      return null
endfunction
function S2I2 takes string s returns integer
            return s
            return 0
endfunction
function I2S2 takes integer s returns string
            return s
            return null
endfunction
function I2U takes integer i returns unit
      return i
      return null
endfunction
function I2Tr takes integer i returns trigger
      return i
      return null
endfunction
function I2Tm takes integer i returns timer
      return i
      return null
endfunction
function I2It takes integer i returns item
      return i
      return null
endfunction
function I2Te takes integer i returns texttag
      return i
      return null
endfunction
function I2G takes integer i returns group
      return i
      return null
endfunction
function I2TC takes integer i returns triggercondition
      return i
      return null
endfunction
function I2TA takes integer i returns triggeraction
      return i
      return null
endfunction
function C2I takes code c returns integer
    return c
    return 0
endfunction
function B2S takes boolean c returns string
    return c
    return null
endfunction
//游戏缓存相关
function SetData takes string lable,string key,integer value returns nothing
      call StoreInteger(udg_GC,lable,key,value)
endfunction
function GetData takes string lable,string key returns integer
      return GetStoredInteger(udg_GC,lable,key)
endfunction
function SetHandle takes handle subject,string name,handle value returns nothing
      call StoreInteger(udg_GC,H2S(subject),"handle"+name,H2I(value))
endfunction
function GetHandle takes handle subject,string name returns handle
      return I2H(GetStoredInteger(udg_GC,H2S(subject),"handle"+name))
endfunction
function FlushTable takes handle lable returns nothing
      call FlushStoredMission(udg_GC,H2S(lable))
endfunction
function FlushKey takes handle lable,string key returns nothing
      call FlushStoredInteger(udg_GC,H2S(lable),key)
endfunctionfunction SetInt takes handle lable,string key,integer value returns nothing
      call StoreInteger(udg_GC,H2S(lable),key,value)
endfunction
function GetInt takes handle lable,string key returns integer
      return GetStoredInteger(udg_GC,H2S(lable),key)
endfunction
function SetReal takes handle lable,string key,real value returns nothing
      call StoreReal(udg_GC,H2S(lable),key,value)
endfunction
function GetReal takes handle lable,string key returns real
      return GetStoredReal(udg_GC,H2S(lable),key)
endfunction
function SetStr takes handle lable,string key,string value returns nothing
      call StoreInteger(udg_GC,H2S(lable),key,S2I2(value))
endfunction
function GetStr takes handle lable,string key returns string
      return I2S2(GetStoredInteger(udg_GC,H2S(lable),key))
endfunctionfunction SetUnit takes handle lable,string key,unit u returns nothing
      call StoreInteger(udg_GC,H2S(lable),"unit"+key,H2I(u))
endfunction
function GetUnit takes handle lable,string key returns unit
      return GetStoredInteger(udg_GC,H2S(lable),"unit"+key)
      return null
endfunction
function RecoredUnitPosition takes unit u returns nothing
    call SetReal( u, "UnitX", GetUnitX(u) )
    call SetReal( u, "UnitY", GetUnitY(u) )
endfunction
function SetTimer takes handle lable,string key,timer u returns nothing
      call StoreInteger(udg_GC,H2S(lable),"timer"+key,H2I(u))
endfunction
function GetTimer takes handle lable,string key returns timer
      return GetStoredInteger(udg_GC,H2S(lable),"timer"+key)
      return null
endfunctionfunction SetItem takes handle lable,string key,item u returns nothing
      call StoreInteger(udg_GC,H2S(lable),"item"+key,H2I(u))
endfunction
function GetItem takes handle lable,string key returns item
      return GetStoredInteger(udg_GC,H2S(lable),"item"+key)
      return null
endfunction
function SetLightning takes handle lable,string key,lightning u returns nothing
      call StoreInteger(udg_GC,H2S(lable),"lightning"+key,H2I(u))
endfunction
function GetLightning takes handle lable,string key returns lightning
      return GetStoredInteger(udg_GC,H2S(lable),"lightning"+key)
      return null
endfunction
function SetEffect takes handle lable,string key,effect u returns nothing
      call StoreInteger(udg_GC,H2S(lable),"effect"+key,H2I(u))
endfunction
function GetEffect takes handle lable,string key returns effect
      return GetStoredInteger(udg_GC,H2S(lable),"effect"+key)
      return null
endfunction
//其他支撑函数
function IsUnitMoved takes unit u returns boolean
    local real x = GetReal( u, "UnitX" )
    local real y = GetReal( u, "UnitY" )
    local boolean b = false
    if x == 0.00 and y == 0.00 then
        call RecoredUnitPosition( u )
    endif
    if GetUnitX(u) != x and GetUnitY(u) != y then
        set b = true
    endif
    return b
endfunction
function ShodowTransparencyActions takes nothing returns nothing
    local unit u = GetUnit(GetExpiredTimer(),"Unit" )
    local integer a = GetInt(GetExpiredTimer(),"Integer" )
    set a = a - 10
    call SetInt( GetExpiredTimer(), "Integer", a )
    call SetUnitVertexColor( u, 255,255,255, a )
    if a <= 50 or GetUnitState(u,UNIT_STATE_LIFE) <= 0 then
        call RemoveUnit( u )
        call FlushTable( GetExpiredTimer() )
        call DestroyTimer( GetExpiredTimer() )
    endif
    set u = null
endfunction
function ShodowTransparency takes unit u, integer initvar returns nothing
    local timer t = null
    if GetUnitState( u, UNIT_STATE_LIFE ) > 0 and initvar > 50 then
        set t = CreateTimer()
        call SetUnit( t, "Unit", u )
        call SetInt( t, "Integer", initvar )
        call TimerStart( t, TimerGetTimeout(GetExpiredTimer()), true, function ShodowTransparencyActions )
    endif
    set t = null
endfunction
function IsUseableX takes real x returns real
    if x <= GetRectMinX(bj_mapInitialPlayableArea) then
        return GetRectMinX(bj_mapInitialPlayableArea)
    elseif x >= GetRectMaxX(bj_mapInitialPlayableArea) then
        return GetRectMaxX(bj_mapInitialPlayableArea)
    endif
    return x
endfunction
function IsUseableY takes real y returns real
    if y <= GetRectMinY(bj_mapInitialPlayableArea) then
        return GetRectMinY(bj_mapInitialPlayableArea)
    elseif y >= GetRectMaxY(bj_mapInitialPlayableArea) then
        return GetRectMaxY(bj_mapInitialPlayableArea)
    endif
    return y
endfunction
function Debug takes string s returns nothing
    local integer a = 0
    loop
        call DisplayTimedTextToPlayer( Player(a), 0, 0, 60.00, s )
        set a = a + 1
        exitwhen a == 11
    endloop
    set a = 0
endfunction
//漂浮文字(单位)    UnitTextTag(单位,文字,红色0-255,绿色0-255,蓝色0-255)
function PointTextTag takes string text, real x, real y, integer red, integer green,integer blue returns texttag
      local texttag gt_textgag=CreateTextTag()
      local integer bi=H2I(gt_textgag)
      call SetTextTagText(gt_textgag, text, 0.023)
      call SetTextTagPos(gt_textgag, x, y, 0.0)
      call SetTextTagColor(gt_textgag, red, green, blue, 255)
      call SetTextTagVelocity(gt_textgag, 0, 0.03)
      call SetTextTagVisibility(gt_textgag, true)
      call SetTextTagFadepoint(gt_textgag, 2)
      call SetTextTagLifespan(gt_textgag, 3)
      call SetTextTagPermanent(gt_textgag, false)
      set gt_textgag=null
      return I2Te(bi)
endfunction
function UnitTextTag takes unit u,string text,integer r,integer g,integer b returns nothing
      local texttag  gt_textgag=PointTextTag(text,0,0,r,g,b)
      call SetTextTagPosUnit(gt_textgag,u,100)
      set gt_textgag=null
endfunction
//在单位组中选取随机单位,之后清除这个单位组    GroupPickRandomUnitFlush(单位组)[会返回单位]
function GroupPickRandomUnitFlush takes group g returns unit
      local integer index
      local integer gta_length=0
      local unit array gta_unit
      local unit gt_unit
      local integer int
      loop                              
            set gt_unit=FirstOfGroup(g)
            exitwhen gt_unit==null
            set gta_unit[gta_length]=gt_unit
            set gta_length=gta_length+1
            call GroupRemoveUnit(g,gt_unit)
      endloop
      set index=GetRandomInt(0,gta_length-1)
      call DestroyGroup(g)
      set int=H2I(gta_unit[index])
      set gt_unit=null
      set index=0
      loop
            set gta_unit[index]=null
            set index=index+1
            exitwhen index==gta_length
      endloop
      return I2U(int)
endfunction
//周期运行一个函数,不必创建自己创建计时器,直接调用这个函数就可以了
//想结束这个记时器,记时器的动作函数里面调用EndTimer      
//TimerRun(代码,实数  间隔时间,是否循环  布尔值)返回计时器
//EndTimer    无参数,消除到时间的计时器(包括缓存)
function TimerRun takes code func,real timeout,boolean periodic returns timer
      local timer gt_timer=CreateTimer()
      local integer int=H2I(gt_timer)
      call TimerStart(gt_timer,timeout,periodic,func)
      set gt_timer=null
      return I2Tm(int)
endfunction
function EndTimer takes nothing returns nothing
      local timer gt_timer=GetExpiredTimer()
      if gt_timer!=null then
            call PauseTimer(gt_timer)
            call FlushTable(gt_timer)
            call DestroyTimer(gt_timer)
      endif
      set gt_timer=null
endfunction
//在单位的头上,产生一个持续时间可以设置的特效    AddTimedEffectPosUnit(单位,附着位点,特效代码,持续时间)
function AddTimedEffectPosUnit_Child takes nothing returns nothing
      local timer gt_timer=GetExpiredTimer()
      local effect gt_effect=GetEffect(gt_timer,"effect_to_destroy")
      if gt_effect!=null then
            call DestroyEffect(gt_effect)
            endif
      call FlushStoredMission(udg_GC,H2S(gt_timer))
      call DestroyTimer(gt_timer)
      set gt_timer=null
      set gt_effect=null     
endfunction
function AddTimedEffectPosUnit takes unit u,string point,string modelname,real time returns nothing
      local timer gt_timer=TimerRun(function AddTimedEffectPosUnit_Child,time,false)
      local effect gt_effect=AddSpecialEffectTarget(modelname, u,point)
      call SetEffect(gt_timer,"effect_to_destroy",gt_effect)
      set gt_timer=null
      set gt_effect=null
endfunction
//等待   Wait(时间)已修正PolledWait函数的内存泄漏问题
//也可以直接用    TriggerSleepAction(等待时间)    来暂停动作
function Wait takes real duration returns nothing
    local timer t= CreateTimer()
    local real  timeRemaining    if (duration > 0) then
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0            // If we have a bit of time left, skip past 104534630f the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop        
    endif
    call PauseTimer(t)
    call DestroyTimer(t)
    set t=null
endfunction
//击退类   
//Mov(被击退单位,击退速度  实数,击退距离  实数,角度  实数,是否暂停单位  布尔值,特效路径【注意要用\\】)
//UnitMove(被击退单位 ,击退时间,每次移动时间,每次移动距离,角度)
function MovUnit takes nothing returns nothing
    local effect speaff
    local timer tm= GetExpiredTimer()
    local unit u = GetUnit(tm,"u")
    local real pt =GetStoredReal(udg_GC,H2S(tm),"pt")
    local real s =GetStoredReal(udg_GC,H2S(tm),"s")
    local string spadd=GetStoredString(udg_GC,H2S(tm),"spadd")
    if (GetUnitX(u)+s*Cos(pt*bj_DEGTORAD))<GetRectMaxX(bj_mapInitialPlayableArea)   then
        if  (GetUnitX(u)+s*Cos(pt*bj_DEGTORAD))>GetRectMinX(bj_mapInitialPlayableArea)  then
             call SetUnitX(u,GetUnitX(u)+s*Cos(pt*bj_DEGTORAD))
             endif
        endif
    if (GetUnitY(u)+s*Sin(pt*bj_DEGTORAD))<GetRectMaxY(bj_mapInitialPlayableArea) and (GetUnitY(u)+s*Sin(pt*bj_DEGTORAD))>GetRectMinY(bj_mapInitialPlayableArea)    then
        call SetUnitY(u,GetUnitY(u)+s*Sin(pt*bj_DEGTORAD))
        endif
    if spadd != null then
        set speaff=AddSpecialEffect(spadd,GetUnitX(u),GetUnitY(u))
        call DestroyEffect(speaff)
        set speaff = null
        endif
    set tm=null
    set u=null
    set spadd=null
endfunction
function Mov takes unit u,real v,real sc,real pt,boolean p,string spadd returns nothing
    local timer tm = TimerRun(function MovUnit,0.02,true)
    local real tim = (sc/v)
    local real s = (0.02*v)
    call SetUnit(tm,"u",u)
    call StoreReal(udg_GC,H2S(tm),"pt",pt)
    call StoreReal(udg_GC,H2S(tm),"s",s)
    call StoreString(udg_GC,H2S(tm),"spadd",spadd)
    if p==true then
        call PauseUnit(u,true)
    endif
    call TimerStart(tm,0.02,true,function MovUnit)
    call Wait(tim)
   
    if p==true then
        call PauseUnit(u,false)
    endif
    call FlushTable(tm)
    call PauseTimer(tm)
    call DestroyTimer(tm)
    set tm=null
endfunction
function Move_LOOP takes nothing returns nothing
      local timer t = GetExpiredTimer()
      local integer i=0
      local unit orderUnit=I2U(GetStoredInteger(udg_GC,I2S(H2I(t)),"orderUnit"))
      local real UnitLocX = GetStoredReal(udg_GC,I2S(H2I(t)),"X")
      local real UnitLocY = GetStoredReal(udg_GC,I2S(H2I(t)),"Y")
      local real tempLocX   
      local real tempLocY   
      local real angle = GetStoredReal(udg_GC,I2S(H2I(t)),"angle")
      local real dis = GetStoredReal(udg_GC,I2S(H2I(t)),"distance")
      local integer steps= GetStoredInteger(udg_GC,I2S(H2I(t)),"steps")
      local integer Max= GetStoredInteger(udg_GC,I2S(H2I(t)),"Max")
      if steps>0   then      
         set steps=steps-1
         call StoreInteger(udg_GC,I2S(H2I(t)),"steps",steps)               
         set tempLocX = UnitLocX + dis*Cos(angle*bj_DEGTORAD)*(Max-steps)
         set tempLocY = UnitLocY + dis*Sin(angle*bj_DEGTORAD)*(Max-steps)      
         if tempLocX > GetRectMaxX(bj_mapInitialPlayableArea) then
             set tempLocX = GetRectMaxX(bj_mapInitialPlayableArea)
         endif
         if tempLocX < GetRectMinX(bj_mapInitialPlayableArea) then
             set tempLocX = GetRectMinX(bj_mapInitialPlayableArea)
         endif
         if tempLocY > GetRectMaxY(bj_mapInitialPlayableArea) then
             set tempLocY = GetRectMaxY(bj_mapInitialPlayableArea)
         endif
         if tempLocY < GetRectMinY(bj_mapInitialPlayableArea) then
             set tempLocY = GetRectMinY(bj_mapInitialPlayableArea)
         endif                        
         call SetUnitX(orderUnit,tempLocX)
         call SetUnitY(orderUnit,tempLocY)      
      else
            set i=0         
            call FlushStoredMission(udg_GC,I2S(H2I(t)))
            call DestroyTimer(t)            
      endif
      set orderUnit=null
endfunctionfunction UnitMove takes unit orderUnit,real lasttime,real interval,real dis,real angle returns nothing
      local real UnitLocX = GetUnitX(orderUnit)
      local real UnitLocY = GetUnitY(orderUnit)   
      local timer t=CreateTimer()
      local integer steps=R2I(lasttime/interval)
      call StoreReal(udg_GC,I2S(H2I(t)),"X",UnitLocX)
      call StoreReal(udg_GC,I2S(H2I(t)),"Y",UnitLocY)
      call StoreInteger(udg_GC,I2S(H2I(t)),"steps",steps)
      call StoreInteger(udg_GC,I2S(H2I(t)),"Max",steps)
      call StoreReal(udg_GC,I2S(H2I(t)),"angle",angle)
      call StoreReal(udg_GC,I2S(H2I(t)),"distance",dis)
      call StoreInteger(udg_GC,I2S(H2I(t)),"orderUnit",H2I(orderUnit))
      call TimerStart(t,interval,true,function Move_LOOP)
      set t=null
endfunction
// 可以让指定的单位做抛物线移动,堪称精典(比如剑圣的跳砍就是抛物移动).
//ParabolaToMoveUnit(单位,高度,距离,速度,角度)
function ParabolaToMoveUnitActions takes nothing returns nothing
    local integer i = GetInt( GetExpiredTimer(), "Integer" )
    local real angle = GetReal( GetExpiredTimer(),"Angle" )
    local real m = GetReal( GetExpiredTimer(),"Speed" ) / 50
    local real a = GetReal( GetExpiredTimer(),"Distance" ) / 2
    local real b = GetReal( GetExpiredTimer(),"High" )
    local real A = b/(a*a)
    local real x
    local real y
    local unit u = GetUnit( GetExpiredTimer(),"Unit")
    local real tempx
    local real tempy
    set i = i + 1
    set x = m*i
    set y = -A*(x-a)*(x-a)+b
    set tempx = GetUnitX(u) + m * Cos(angle*bj_DEGTORAD)
    set tempy = GetUnitY(u) + m * Sin(angle*bj_DEGTORAD)
    call SetUnitX( u, IsUseableX(tempx) )
    call SetUnitY( u, IsUseableY(tempy) )
    call SetUnitFacing( u, angle )
    call SetUnitFlyHeight( u, y, 0.00 )
    call SetInt( GetExpiredTimer(), "Integer", i )
    if x>=(2*a) then
        call SetUnitFlyHeight( u, GetUnitDefaultFlyHeight(u), 0.00 )
        call FlushTable( GetExpiredTimer() )
        call DestroyTimer( GetExpiredTimer() )
        call FlushTable( u )
    endif
endfunctionfunction ParabolaToMoveUnit takes unit u,real high,real distance,real speed,real angel returns nothing
    local timer t = null
    if GetUnitState(u,UNIT_STATE_LIFE) > 0.00 and distance > 0.00 and speed > 0.00 then
        set t = CreateTimer()
        call UnitAddAbility( u,'Arav' )
        call UnitRemoveAbility( u,'Arav' )
        call SetReal( t, "Angle", angel )
        call SetReal( t, "High", high )
        call SetReal( t, "Distance", distance )
        call SetReal( t, "Speed", speed )
        call SetUnit( t ,"Unit",u )
        call TimerStart( t, 0.02, true, function ParabolaToMoveUnitActions )
        set bj_lastStartedTimer=t
    else
        call FlushTable(t)
        call DestroyTimer(t)
        call Debug( "Error!")
    endif
    set t = null
endfunction
// 可以创建N个单位旋转跟随指定单位
//TimerLoopRoundUnit(创建个数,创建单位种类,半径,围绕单位,总时间,每步时间间隔,速度)
function TimerLoopRoundUnitActions takes nothing returns nothing
    local unit array tempUnit
    local real array angle
    local integer i = 0
    local integer N = GetInt( GetExpiredTimer(),"Number" )
    local integer steps = GetInt( GetExpiredTimer(), "Integer" )
    local unit orderUnit=GetUnit(GetExpiredTimer(),"Unit")
    local real radius = GetReal( GetExpiredTimer(), "Radius" )
    local real S = GetReal( GetExpiredTimer(), "Speed" )
    if steps > 0 and GetUnitState(orderUnit,UNIT_STATE_LIFE) > 0.00 then     
        set steps = steps - 1
        call SetInt( GetExpiredTimer(), "Integer", steps )        
        loop
            exitwhen i > N
            set i = i + 1
            set tempUnit = GetUnit( GetExpiredTimer(), I2S(1000+i) )
            set angle = GetReal( GetExpiredTimer(), I2S(2000+i) )
            set angle = angle + S
            call SetUnitX( tempUnit , IsUseableX(GetUnitX(orderUnit) + radius*CosBJ(angle)) )
            call SetUnitY( tempUnit , IsUseableY(GetUnitY(orderUnit) + radius*SinBJ(angle)) )
            call SetReal( GetExpiredTimer(), I2S(2000+i),angle )
            set tempUnit=null
            set angle=0.00
        endloop
    else
        set i = 0
        loop
            set i = i + 1
            exitwhen i > N            
            call RemoveUnit( GetUnit( GetExpiredTimer(),I2S(1000+i)) )         
        endloop
        call FlushTable( GetExpiredTimer() )
        call DestroyTimer( GetExpiredTimer() )        
    endif
    set orderUnit=null
endfunction
function TimerLoopRoundUnit takes integer N,integer ewsp,real R,unit Hero,real T,real I,real S returns nothing
    local unit array tempUnit
    local timer t=CreateTimer()
    local real tempLocX  
    local real tempLocY
    local real array angle
    local integer i=0
    if GetUnitState(Hero,UNIT_STATE_LIFE) > 0.00 and N > 0 and ewsp != 0 then
        call SetInt( t, "Integer", R2I(T/I) )
        call SetInt( t, "Number",N )
        call SetReal( t, "Radius", R )
        call SetReal( t, "Speed", S )
        loop
            set i = i + 1
            exitwhen  i > N
            set tempLocX = GetUnitX(Hero) + R*Cos(2*i*bj_PI/N)      
            set tempLocY = GetUnitY(Hero) + R*Sin(2*i*bj_PI/N)
            set angle = 180*Atan2(GetUnitY(Hero) - tempLocY, GetUnitX(Hero) - tempLocX)/bj_PI
            set tempUnit=CreateUnit(GetOwningPlayer(Hero),ewsp,tempLocX,tempLocY,angle)
            call SetUnit( t, I2S(1000+i),tempUnit )
            call UnitGenerateAlarms( tempUnit, false )
            call SetReal( t, I2S(2000+i),angle )
            set tempUnit=null
        endloop
        call SetUnit( t,"Unit", Hero)
        call TimerStart(t,I,true,function TimerLoopRoundUnitActions)
        set bj_lastStartedTimer=t
    else
        loop
            set i = i + 1
            exitwhen i > N            
            call RemoveUnit( GetUnit( t,I2S(1000+i)) )         
        endloop
        call FlushTable( t )
        call DestroyTimer( t )
    endif
    set t = null
endfunction
// 开启之个功能,当单位移动时,可以创建幻影跟随单位.
//TimerShadowForUnit(跟随单位ID,跟随动作   字符串,跟随目标单位,幻影间隔时间,幻影总时间)
function StopTimerShadowForUnit takes timer t returns nothing
    call FlushTable( t )
    call DestroyTimer( t )
endfunctionfunction TimerShadowForUnitActions takes nothing returns nothing
    local unit u = GetUnit( GetExpiredTimer(), "Unit")
    local unit n = null
    if IsUnitMoved(u)==true then
        set n = CreateUnit( GetOwningPlayer(u),GetInt( GetExpiredTimer(), "Unit" ),GetReal( u, "UnitX" ),GetReal( u, "UnitY" ),GetUnitFacing(u))
        call ShodowTransparency( n, 160 )
        call SetUnitPathing( n, false )
        call PauseUnit( n, true )
        call SetUnitAnimation( n, GetStr( GetExpiredTimer(), "Index" ) )
        call SetUnitTimeScale( n, 0.618 )
        call UnitApplyTimedLife( n, 'BHwe', 5.00 )
        call SetUnitX( n, GetReal( u, "UnitX" ) )
        call SetUnitY( n, GetReal( u, "UnitY" ) )
        if GetUnitFlyHeight(u) != 0.00 then
            call UnitAddAbility(n, 'Arav' )
            call UnitRemoveAbility( n, 'Arav' )
            call SetUnitFlyHeight( n, GetUnitFlyHeight(u), 0.00 )
        endif
        call RecoredUnitPosition( u )
        set n = null
    endif
    if GetUnitState(u,UNIT_STATE_LIFE) == 0.00 or GetReal( GetExpiredTimer(), "Limit" ) >= GetReal( GetExpiredTimer(), "Real" ) then
        call StopTimerShadowForUnit( GetExpiredTimer() )
        call FlushTable(u)
    else
        call SetReal( GetExpiredTimer(), "Limit", GetReal( GetExpiredTimer(), "Limit" )+TimerGetTimeout(GetExpiredTimer()) )
    endif
    set u = null
    set n = null
endfunction
function TimerShadowForUnit takes integer id, string an, unit u, real ti, real lt returns nothing
    local timer t = null
    if  GetUnitState(u,UNIT_STATE_LIFE) > 0.00 and id != 0 and ti > 0.01 and lt >= ti then
        call RecoredUnitPosition( u )
        set t = CreateTimer()
        call SetInt( t, "Unit", id )
        call SetUnit( t, "Unit", u )
        call SetStr( t, "Index", an )
        call SetReal( t, "Real", lt )
        call SetTimer( u, "ShadowTimer", t )
        call TimerStart( t, ti, true, function TimerShadowForUnitActions )
        set bj_lastStartedTimer = t
    else
        call StopTimerShadowForUnit( t )
    endif
    set t = null
endfunction
//触发器注册与删除
//使用:local trigger trg=CreateTrigger;call 注册事件;call AddTrigger_Con_Act(trg,条件,事件)
//删除:call DestroyTrg(trg);set trg = null
function AddTrigger_Con_Act takes trigger trg,code con,code act returns nothing
    call StoreInteger(udg_GC,I2S(H2I(trg)),"condition",H2I(TriggerAddCondition(trg,Condition(con))))
    call StoreInteger(udg_GC,I2S(H2I(trg)),"action",H2I(TriggerAddAction(trg,act)))
endfunction
function DestroyTrg takes trigger trg returns nothing
    call TriggerRemoveCondition(trg,I2TC(GetStoredInteger(udg_GC,I2S(H2I(trg)),"condition")))
    call TriggerRemoveAction(trg,I2TA(GetStoredInteger(udg_GC,I2S(H2I(trg)),"action")))
    call FlushStoredMission(udg_GC,I2S(H2I(trg)))
    call DestroyTrigger(trg)
endfunction
//简化用函数区
//在一个规则区域内创建几个单位并发布命令
//创建几个单位对点发布命令(如果目标是区域中心,可以用区域内的点的坐标来发布命令)
//用法:CreateUnitAndDoToPoint(创建单位的区域,单位玩家 ,单位种类 ,数量,目标X坐标,目标Y坐标,单位面向角度,命令)
function CreateUnitAndDoToPoint takes rect cr,player whichplayer,integer unitname,integer unitnumber,real x,real y,real face,string order returns nothing
    local real crX=GetRectCenterX(cr)
    local real crY=GetRectCenterY(cr)
    local integer index=0
    local unit u
    loop
        exitwhen index>=unitnumber
        set u=CreateUnit(whichplayer,unitname,crX,crY,face)
        call IssuePointOrder(u,order,x,y)
        set index=index+1
    endloop
    set u=null
endfunction
//任意玩家输入信息做动作(可在一定时间后删除)(0为不删除)
//用法:CreateTriggerForEveryPlayer(输入的字串符,动作函数,是否完全匹配,触发器持续时间)(0为不删除)
function CreateTriggerForEveryPlayer takes string str,code func,boolean yon,real tim returns nothing
    local integer index=0
    local trigger array tg
    local triggeraction array tga     
    loop
        exitwhen index>=12
        set tg[index]=CreateTrigger()
        call TriggerRegisterPlayerChatEvent(tg[index],Player(index),str,yon)
        set tga[index]= TriggerAddAction(tg[index],func)
        set index=index+1
    endloop
    call Wait(tim)  
    set index=0
     loop
        exitwhen index>=12
        if tim != 0 then
             call TriggerRemoveAction(tg[index],tga[index])
             call DestroyTrigger(tg[index])
             endif
        set tg[index]=null
        set tga[index]=null
        set index=index+1
    endloop
endfunction
//返回距离  角度  
//GetUnitDistance(单位,单位)返回距离
//GetUnitPointDistance(单位,点,是否删除点   布尔值)返回距离
//GetPointDistance(点,点,是否删除点   布尔值)返回距离
//GetUnitAngle(单位,单位)返回角度
//GetUnitPointAngle(单位,点,是否删除点   布尔值)返回角度
//GetPointAngle(点,点,是否删除点   布尔值)返回角度
function GetUnitDistance takes unit a,unit b returns real
      local real dx = GetUnitX(a) - GetUnitX(b)
      local real dy = GetUnitY(a) - GetUnitY(b)
      return SquareRoot(dx * dx + dy * dy)
endfunction
function GetUnitPointDistance takes unit a,location b,boolean c returns real
      local real dx = GetUnitX(a) - GetLocationX(b)
      local real dy = GetUnitY(a) - GetLocationY(b)
      if c==true then
         call RemoveLocation(b)
         endif
      return SquareRoot(dx * dx + dy * dy)
endfunction
function GetPointDistance takes location a,location b,boolean c returns real
      local real dx = GetLocationX(a) - GetLocationX(b)
      local real dy = GetLocationY(a) - GetLocationY(b)
      if c==true then
         call RemoveLocation(a)
         call RemoveLocation(b)
         endif
      return SquareRoot(dx * dx + dy * dy)
endfunction
function GetUnitAngle takes unit a,unit b returns real
      local real dx = GetUnitX(a) - GetUnitX(b)
      local real dy = GetUnitY(a) - GetUnitY(b)
      return Atan(dy/dx)
endfunction
function GetUnitPointAngle takes unit a,location b,boolean c returns real
      local real dx = GetUnitX(a) - GetLocationX(b)
      local real dy = GetUnitY(a) - GetLocationY(b)
      if c==true then
         call RemoveLocation(b)
         endif
      return Atan(dy/dx)
endfunction
function GetPointAngle takes location a,location b,boolean c returns real
      local real dx = GetLocationX(a) - GetLocationX(b)
      local real dy = GetLocationY(a) - GetLocationY(b)
      if c==true then
         call RemoveLocation(a)
         call RemoveLocation(b)
         endif
      return Atan(dy/dx)
endfunction
[/codes]
 楼主| 发表于 2008-9-5 16:33:57 | 显示全部楼层
[codes=jass]
//攻击类函数    模式:输入整数   1.对全体,2.对敌人.3.对友军,4.友军50敌军100,5.敌军50友军100,6.友军恢复,7.全体恢复
//让一个单位对另一个单位造成一个无视护甲,无视无敌,无视魔抗性的所谓神圣伤
//FullDamageUnit(施加伤害者,受伤害者,技能,技能系数,伤害模式   整数)   单位对单位立即
//FullDamageGroup(施加伤害者,目标单位组,技能,技能系数,伤害模式   整数)   单位对单位组立即
//FullDamagePoint(施加伤害者,圆心点X,圆心点Y,范围,技能,技能系数,伤害模式   整数)    单位对圆形区域
//FullDamageUnitStanding(施加伤害者,受伤害者,持续时间,技能,系数,伤害模式  整数)    单位对单位持续伤害
//FullDamageRangeStanding(施加伤害者,持续时间,目标圆心X,目标圆心Y,范围,技能,系数,模式   整数)    单位对圆形区域持续伤害
function FullDamageUnit takes unit from,unit to,integer skill,real coefficient,integer mode returns nothing
      if mode==1 then
         call UnitDamageTarget(from,to,(coefficient* (1-udg_AbilityRrcoveryCoefficient[GetConvertedPlayerId(GetOwningPlayer(to))])*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ),true,false,null,null,null)
         elseif mode==2 and IsPlayerAlly(GetOwningPlayer(from), GetOwningPlayer(to)) == false then
         call UnitDamageTarget(from,to,( coefficient*(1-udg_AbilityRrcoveryCoefficient[GetConvertedPlayerId(GetOwningPlayer(to))])*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ),true,false,null,null,null)
         elseif mode==3 and IsPlayerAlly(GetOwningPlayer(from), GetOwningPlayer(to)) == true then
         call UnitDamageTarget(from,to,( coefficient*(1-udg_AbilityRrcoveryCoefficient[GetConvertedPlayerId(GetOwningPlayer(to))])*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ),true,false,null,null,null)
         elseif mode==4  then
         if   IsPlayerAlly(GetOwningPlayer(from), GetOwningPlayer(to)) == true then
              call UnitDamageTarget(from,to,( coefficient*0.5*(1-udg_AbilityRrcoveryCoefficient[GetConvertedPlayerId(GetOwningPlayer(to))])*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ),true,false,null,null,null)
              else
              call UnitDamageTarget(from,to,( coefficient*(1-udg_AbilityRrcoveryCoefficient[GetConvertedPlayerId(GetOwningPlayer(to))])*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ),true,false,null,null,null)
              endif
         elseif mode==5  then
         if   IsPlayerAlly(GetOwningPlayer(from), GetOwningPlayer(to)) == false then
              call UnitDamageTarget(from,to,(coefficient* 0.5*(1-udg_AbilityRrcoveryCoefficient[GetConvertedPlayerId(GetOwningPlayer(to))])*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ),true,false,null,null,null)
              else
              call UnitDamageTarget(from,to,(coefficient* (1-udg_AbilityRrcoveryCoefficient[GetConvertedPlayerId(GetOwningPlayer(to))])*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill))) *GetHeroInt(from, true)),true,false,null,null,null)
              endif
         elseif mode==6  and IsPlayerAlly(GetOwningPlayer(from), GetOwningPlayer(to)) == true then
              call SetUnitLifeBJ( to, ( GetUnitState(to, UNIT_STATE_LIFE) + (coefficient*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ) ) )
         elseif mode==7  then
              call SetUnitLifeBJ( to, ( GetUnitState(to, UNIT_STATE_LIFE) + (coefficient*udg_AbilityAttackCoefficient[GetConvertedPlayerId(GetOwningPlayer(from))]* (1+I2R(GetUnitAbilityLevel(from, skill)))*GetHeroInt(from, true) ) ) )
         endif
endfunction
function FullDamageGroupB takes nothing returns nothing
    call FullDamageUnit(udg_Instantaneous_unit[0], GetEnumUnit(),udg_Instantaneous_integer[0],udg_Instantaneous_real[0],udg_Instantaneous_integer[1])
endfunction
function FullDamageGroup takes unit from,group to,integer skill,real coefficient,integer mode returns nothing
    set udg_Instantaneous_unit[0]=from
    set udg_Instantaneous_integer[0]=skill
    set udg_Instantaneous_real[0]=coefficient
    set udg_Instantaneous_integer[1]=mode
    call ForGroup( to, function FullDamageGroupB )
endfunction
function FullDamageRange takes unit from,real x,real y,real range,integer skill,real coefficient,integer mode returns nothing
    local group g=CreateGroup()
    call GroupEnumUnitsInRange(g,x,y,range,null)
    call FullDamageGroup(from,g,skill,coefficient,mode)
    call DestroyGroup(g)
    set g=null
endfunction
function FullDamageUnitStanding takes unit from,unit to,real duration,integer skill,real coefficient,integer mode returns nothing
    local real index=0
    loop
       call FullDamageUnit(from,to,skill,(coefficient*(0.5/duration)),mode)
       call TriggerSleepAction(0.5)
       set index=index+0.5
       exitwhen index >= duration
       endloop
endfunction
function FullDamageRangeStanding takes unit from,real duration,real x,real y,real range,integer skill,real coefficient,integer mode returns nothing
    local real index=0
    loop
       call FullDamageRange(from,x,y,range,skill,(coefficient*(0.2/duration)),mode)
       call TriggerSleepAction(0.2)
       set index=index+0.2
       exitwhen index >= duration
       endloop
endfunction
//技能模板
[/codes]
回复

使用道具 举报

 楼主| 发表于 2008-9-5 16:41:27 | 显示全部楼层
忘了说了,有什么问题(比如哪里内存泄漏)我没看出来的请大家指出啊!!!!!
回复

使用道具 举报

发表于 2008-9-5 21:57:48 | 显示全部楼层
引用第2楼owt5008137于2008-09-05 16:41发表的  :
忘了说了,有什么问题(比如哪里内存泄漏)我没看出来的请大家指出啊!!!!!

最大的问题就是太长了,米耐心看完
回复

使用道具 举报

 楼主| 发表于 2008-9-7 09:08:39 | 显示全部楼层
就是为了方便看,我才把每个功能函数区域前都用中文注释了啊
回复

使用道具 举报

发表于 2008-9-7 10:56:02 | 显示全部楼层
往往都是看到一大堆代码就关闭页面了………………………………………………
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-12-22 20:14 , Processed in 0.241156 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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