|
既然百度贴吧魔兽争霸编辑器吧的大神们都喜欢弄1套自己的通用函数库 那我就收集整理1下吧
话说天灵萃梦和橙子貌似失踪了? N年不见人影了
1 图片弹幕函数(预读的)
- // -------------
- //real MOVEIMAGETIMER_TIMEOUT=0.04
- //! textmacro imageBulletsFunction takes NAME
- globals
- image array imageBullet_$NAME$_images
- timer imageBullet_$NAME$_timer
- integer imageBullet_$NAME$_Max=0
- integer imageBullet_$NAME$_imageMax=0
- integer array imageBullet_$NAME$_id
- unit array imageBullet_$NAME$_spellunit
- real array imageBullet_$NAME$_x
- real array imageBullet_$NAME$_y
- real array imageBullet_$NAME$_z
- real array imageBullet_$NAME$_speed_x
- real array imageBullet_$NAME$_speed_y
- real array imageBullet_$NAME$_distance
- real array imageBullet_$NAME$_speed
- string array imageBullet_$NAME$_effpath
- string array imageBullet_$NAME$_targeteffpath
- real array imageBullet_$NAME$_collision
- real array imageBullet_$NAME$_range
- integer udg_$NAME$_Max = 0
- integer array udg_$NAME$_Flu
- endglobals
- function Create_$NAME$_Id takes nothing returns integer
- set udg_$NAME$_Max = udg_$NAME$_Max + 1
- debug call BJDebugMsg("$NAME$_Max_ID="+I2S(udg_$NAME$_Max))
- if udg_$NAME$_Max>8190 then
- call BJDebugMsg("|cffff0000 CreateImageId_$NAME$_error: cannot create id (>8190)|r")
- return 0
- endif
- if udg_$NAME$_Flu[udg_$NAME$_Max == 0 then
- return udg_$NAME$_Max
- endif
- return udg_$NAME$_Flu[udg_$NAME$_Max
- endfunction
- function Remove_$NAME$_Id takes integer tid returns nothing
- set udg_$NAME$_Flu[udg_$NAME$_Max = tid
- set udg_$NAME$_Max = udg_$NAME$_Max - 1
- debug call BJDebugMsg("$NAME$_Max_ID="+I2S(udg_$NAME$_Max))
- endfunction
- function imageBullet_$NAME$_Preload takes nothing returns nothing
- local integer c=imageBullet_$NAME$_imageMax+IMAGE_BULLET_PRELOAD_AMOUNT
- debug call BJDebugMsg("Image_$NAME$ is preloading")
- if c>8190 then
- call BJDebugMsg("|cffff0000 Image_$NAME$_error: preload is failed|r")
- return
- endif
- loop
- set imageBullet_$NAME$_imageMax=imageBullet_$NAME$_imageMax+1
- exitwhen imageBullet_$NAME$_imageMax>c
- set imageBullet_$NAME$_images[imageBullet_$NAME$_imageMax=CreateImage(IMAGE_BULLETS_paths[$NAME$,IMAGE_BULLETS_size[$NAME$,IMAGE_BULLETS_size[$NAME$,IMAGE_BULLETS_size[$NAME$,0,0,0,0,0,0,2)
- call ShowImage(imageBullet_$NAME$_images[imageBullet_$NAME$_imageMax,false)
- call SetImageRenderAlways(imageBullet_$NAME$_images[imageBullet_$NAME$_imageMax,true)
- endloop
- set imageBullet_$NAME$_imageMax=imageBullet_$NAME$_imageMax-1
- endfunction
- function imageBullet_$NAME$_Delete takes integer id returns nothing
- call ShowImage(imageBullet_$NAME$_images[imageBullet_$NAME$_id[id,false)
- call Remove_$NAME$_Id(imageBullet_$NAME$_id[id)
- set imageBullet_$NAME$_id[id=imageBullet_$NAME$_id[imageBullet_$NAME$_Max
- set imageBullet_$NAME$_Max=imageBullet_$NAME$_Max-1
- endfunction
- function imageBullet_$NAME$_New takes unit spellunit,real x,real y,real z,real angle,real speed,real distance,string effpath,real collision,real range,string targeteffpath returns nothing
- local integer id
- set imageBullet_$NAME$_Max=imageBullet_$NAME$_Max+1
- set id=imageBullet_$NAME$_Max
- if id>imageBullet_$NAME$_imageMax then
- call imageBullet_$NAME$_Preload()
- endif
- set imageBullet_$NAME$_id[imageBullet_$NAME$_Max=Create_$NAME$_Id()
- set id=imageBullet_$NAME$_id[imageBullet_$NAME$_Max
- set imageBullet_$NAME$_spellunit[id=spellunit
- set imageBullet_$NAME$_x[id=x
- set imageBullet_$NAME$_y[id=y
- set imageBullet_$NAME$_z[id=z
- set speed=speed*MOVEIMAGETIMER_TIMEOUT
- set imageBullet_$NAME$_speed_x[id=speed*Cos(angle)
- set imageBullet_$NAME$_speed_y[id=speed*Sin(angle)
- set imageBullet_$NAME$_distance[id=distance
- set imageBullet_$NAME$_speed[id=speed
- set imageBullet_$NAME$_effpath[id=effpath
- set imageBullet_$NAME$_targeteffpath[id=targeteffpath
- set imageBullet_$NAME$_collision[id=collision
- set imageBullet_$NAME$_range[id=range
- call ShowImage(imageBullet_$NAME$_images[id,true)
- call SetImagePosition(imageBullet_$NAME$_images[id,x,y,z)
- endfunction
- function imageBullet_$NAME$_TimerAction takes nothing returns nothing
- local integer id
- local integer i
- local group g
- local unit u
- local boolean b
- local player p
- set i=imageBullet_$NAME$_Max
- loop
- exitwhen i<=0
- set id=imageBullet_$NAME$_id[i
- set b=false
- set p=GetOwningPlayer(imageBullet_$NAME$_spellunit[id)
- if imageBullet_$NAME$_effpath[id!=null then
- call DestroyEffect(AddSpecialEffect(imageBullet_$NAME$_effpath[id,imageBullet_$NAME$_x[id,imageBullet_$NAME$_y[id))
- endif
- set imageBullet_$NAME$_x[id=imageBullet_$NAME$_x[id+imageBullet_$NAME$_speed_x[id
- set imageBullet_$NAME$_y[id=imageBullet_$NAME$_y[id+imageBullet_$NAME$_speed_y[id
- if (imageBullet_$NAME$_x[id>MAP_MINX)and(imageBullet_$NAME$_y[id>MAP_MINY)and(imageBullet_$NAME$_x[id<MAP_MAXX)and(imageBullet_$NAME$_y[id<MAP_MAXY) then
- call SetImagePosition(imageBullet_$NAME$_images[id,imageBullet_$NAME$_x[id,imageBullet_$NAME$_y[id,imageBullet_$NAME$_z[id)
- else
- set b=true
- endif
- set imageBullet_$NAME$_distance[id=imageBullet_$NAME$_distance[id-imageBullet_$NAME$_speed[id
- if imageBullet_$NAME$_distance[id<=0 then
- set b=true
- set g=CreateGroup()
- call GroupEnumUnitsInRange(g,imageBullet_$NAME$_x[id,imageBullet_$NAME$_y[id,imageBullet_$NAME$_range[id,null)
- loop
- set u = FirstOfGroup(g)
- exitwhen u == null
- if (GetUnitState(u,UNIT_STATE_LIFE)>0 and IsUnitEnemy(u,p)) then
- // call Damage 此处为伤害动作
- endif
- call GroupRemoveUnit(g,u)
- endloop
- else
- set g=CreateGroup()
- call GroupEnumUnitsInRange(g,imageBullet_$NAME$_x[id,imageBullet_$NAME$_y[id,imageBullet_$NAME$_collision[id,null)
- loop
- set u = FirstOfGroup(g)
- exitwhen u == null
- if (GetUnitState(u,UNIT_STATE_LIFE)>0 and IsUnitEnemy(u,p)) or b then
- call GroupEnumUnitsInRange(g,imageBullet_$NAME$_x[id,imageBullet_$NAME$_y[id,imageBullet_$NAME$_range[id,null)
- loop
- set u = FirstOfGroup(g)
- exitwhen u == null
- if (GetUnitState(u,UNIT_STATE_LIFE)>0 and IsUnitEnemy(u,p)) then
- // call Damage 此处为伤害动作
- endif
- call GroupRemoveUnit(g,u)
- endloop
- set b=true
- exitwhen true
- endif
- call GroupRemoveUnit(g,u)
- endloop
- endif
- call DestroyGroup(g)
- set g = null
- if b then
- if imageBullet_$NAME$_targeteffpath[id!=null then
- call DestroyEffect(AddSpecialEffect(imageBullet_$NAME$_targeteffpath[id,imageBullet_$NAME$_x[id,imageBullet_$NAME$_y[id))
- endif
- call imageBullet_$NAME$_Delete(i)
- endif
- set i=i-1
- endloop
- endfunction
- function imageBullet_$NAME$_init takes nothing returns nothing
- set imageBullet_$NAME$_timer=CreateTimer()
- call TimerStart(imageBullet_$NAME$_timer,MOVEIMAGETIMER_TIMEOUT,true,function imageBullet_$NAME$_TimerAction)
- endfunction
- //! endtextmacro
- // -------------
- //! textmacro imageBulletsInit takes NAME,PATH,SIZE
- set IMAGE_BULLETS_paths[$NAME$="$PATH$"
- set IMAGE_BULLETS_size[$NAME$=$SIZE$
- call imageBullet_$NAME$_init()
- //! endtextmacro
- globals
- real MOVEIMAGETIMER_TIMEOUT=0.04
- integer IMAGE_BULLET_PRELOAD_AMOUNT=50 //每次预创建数量
- string array IMAGE_BULLETS_paths
- real array IMAGE_BULLETS_size
- real MAP_MINX=-15594 //地图范围
- real MAP_MINY=-15860
- real MAP_MAXX=15578
- real MAP_MAXY=15342
- endglobals
- //! runtextmacro imageBulletsFunction("1")
- // 参数为数字,做为下标
- function IMAGE_BULLET_init takes nothing returns nothing
- //! runtextmacro imageBulletsInit("1","Cast_BallGreen.BLP","32")
- // 设置 1号图片弹幕 图片为Cast_BallGreen.BLP, 大小为32x32x32
- endfunction
- // call imageBullet_1_New(spellunit,x,y,z,angle,speed,distance,effpath,collision,range,targeteffpath)
- // 发布弹幕的单位,坐标x,y,高度z,方向(弧度),速度,距离,路径特效(无则填null),碰撞半径,伤害范围,终点特效(无则填null)
- globals
- integer array MoveIndex
- real array MoveSpeed
- // real array MoveAngle
- real array MoveRange
- real array MoveDamageRange
- real array MoveDamage
- real array MoveDistance
- real array MoveCos
- real array MoveSin
- unit array MoveUnit
- unit array MoveDamageUnit
- boolean array MoveAllyRange
- boolean BarrierUnitSetsel
- integer SetselInt
- endglobals
- function PopUnit takes integer id returns nothing
- local integer i=MoveIndex[0]
- set MoveUnit[id]=MoveUnit[i]
- set MoveSpeed[id]=MoveSpeed[i]
- set MoveDistance[id]=MoveDistance[i]
- // set MoveAngle[id]=MoveAngle[i]
- set MoveCos[id]=MoveCos[i]
- set MoveSin[id]=MoveSin[i]
- set MoveAllyRange[id]=MoveAllyRange[i]
- set MoveDamageUnit[id]=MoveDamageUnit[i]
- set MoveDamageRange[id]=MoveDamageRange[i]
- set MoveRange[id]=MoveRange[i]
- set MoveDamage[id]=MoveDamage[i]
- set MoveUnit[i]=null
- set MoveIndex[0]=i-1//指针左移
- endfunction
- function MoveMode takes nothing returns nothing
- local integer i=MoveIndex[0]//获得栈里当前记录单位数
- local real x
- local real y
- local group g0
- local group g1
- local unit u
- local unit u1
- local unit mu
- local unit du
- loop
- exitwhen i == 0// 如果栈拥有 >0 个单位 就会从 高id往低id 的对栈里每个单位执行动作
- // call BJDebugMsg("a 遍历到了 i = "+I2S(i))
- // call BJDebugMsg("b i="+I2S(i)+" 判断距离是否到了 = "+R2S(MoveDistance[i]))
- set mu=MoveUnit[i]
- if MoveDistance[i]<0 then//如果移动距离到了 就杀死单位 记录销毁序号
- call KillUnit(mu)//就杀死单位
- // set MoveIndex[MoveIndex[0]]=i//记录销毁序号
- call PopUnit(i)
- // call BJDebugMsg("c end i="+I2S(i)+" 距离到了 杀死单位 i("+I2S(i)+")入栈 指针-1 = "+I2S(MoveIndex[0]))
- else//否则移动单位 同时判断是否碰撞单位 如果碰到就不移动
- set du=MoveDamageUnit[i]
- set x=GetUnitX(mu)+MoveCos[i]//获得位移坐标x
- set y=GetUnitY(mu)+MoveSin[i]//获得位移坐标y
- // call BJDebugMsg("c i="+I2S(i)+" 距离没到 准备移动单位("+R2S(GetUnitX(MoveUnit[i]))+","+R2S(GetUnitY(MoveUnit[i]))+") 到 ("+R2S(x)+","+Rsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
- set BarrierUnitSetsel=false//初始化布尔值变量
- set g0=CreateGroup()
- call GroupEnumUnitsInRange(g0,x,y,MoveRange[i],null)//选取坐标附近指定范围的所有单位检查条件是否匹配
- loop
- set u=FirstOfGroup(g0)
- exitwhen u == null
- if not(IsUnitType(u,UNIT_TYPE_DEAD)) and ((MoveAllyRange[i] and u != du and u != mu) or IsUnitEnemy(du,GetOwningPlayer(u))) and not(BarrierUnitSetsel) then
- set BarrierUnitSetsel=true//设置此判断变量真 然后伤害选取到的敌人
- if MoveDamageRange[i] == 0 then
- call UnitDamageTarget(du,u,MoveDamage[i],true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )
- elseif MoveDamageRange[i]<0 then
- call UnitDamagePoint(du,0,0-MoveDamageRange[i],GetUnitX(u),GetUnitY(u),MoveDamage[i],true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
- else
- set g1=CreateGroup()
- call GroupEnumUnitsInRange(g1,GetUnitX(u),GetUnitY(u),MoveDamageRange[i],null)
- loop
- set u1=FirstOfGroup(g1)
- exitwhen u1 == null
- if IsUnitType(u1,UNIT_TYPE_DEAD) == false and IsUnitEnemy(du,GetOwningPlayer(u1)) then
- call UnitDamageTarget(du,u1,MoveDamage[i],true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )
- endif
- call GroupRemoveUnit(g1,u1)
- endloop
- call DestroyGroup(g1)
- set g1=null
- endif
- call KillUnit(mu)//杀死弹幕单位
- call PopUnit(i)
- endif
- call GroupRemoveUnit(g0,u)
- endloop
- set du=null
- call DestroyGroup(g0)
- set g0=null
- // call BJDebugMsg("i 选取完")
- if not(BarrierUnitSetsel or IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY)) then//如果此为假 亦即没有选取到敌人单位
- call SetUnitX(mu,x)//移动单位到指定x坐标
- call SetUnitY(mu,y)//移动单位到指定y坐标
- // call BJDebugMsg("j end 没有碰到敌人")
- // else
- // call BJDebugMsg("j end 碰到敌人了")
- endif
- set MoveDistance[i]=MoveDistance[i]-MoveSpeed[i]//减少记录的距离 亦即记录剩下移动距离
- set mu=null
- endif
- set i=i-1
- endloop
- endfunction
- //call AddMoveMode(玩家,辅助单位id,伤害来源,初始x,初始y,移动角度,移动速度,最大距离,伤害范围,碰撞检查范围,伤害值)
- //角度 按角度制即 0-360
- //伤害来源 即最终伤害由谁给出
- //伤害范围 设置0 即只伤害目标 设置了正数 就能范围伤害(不伤害队友) 设置负数 伤害队友的范围伤害
- //碰撞检查范围 设置了正数 就碰到敌人才爆炸 设置负数 碰到队友也爆炸
- function AddMoveMode takes player p,integer uid,unit Damage,real x0,real y0,real r,real speed,real juli,real drange,real range,real damage returns nothing
- local integer i
- set MoveIndex[0]=MoveIndex[0]+1 //指针右移
- if MoveIndex[MoveIndex[0]] != 0 then //如果此位置记录销毁id
- set i=MoveIndex[MoveIndex[0]] //设置取得id=此被销毁id
- else //如果此位置没记录销毁id
- set i=MoveIndex[0] //设置取得id=指针位置
- endif
- set MoveUnit[i]=CreateUnit(p,uid,x0,y0,r)//创建单位 记录单位
- set r=bj_DEGTORAD*r //把角度制转 弧度制 (例:180转bj_PI)
- set MoveDamageUnit[i]=Damage
- if MoveDamageUnit[i] == null then
- set MoveDamageUnit[i]=MoveUnit[i]
- endif
- set MoveSpeed[i]=speed//记录速度
- set MoveDistance[i]=juli//记录最大距离
- // set MoveAngle[i]=r//记录移动角度
- set MoveAllyRange[i]=range<0
- set MoveDamageRange[i]=drange
- if MoveAllyRange[i] then
- set MoveRange[i]=0-range//记录碰撞检查范围
- else
- set MoveRange[i]=range//记录碰撞检查范围
- endif
- set MoveDamage[i]=damage//记录伤害值
- set MoveCos[i]=Cos(r)*MoveSpeed[i]
- set MoveSin[i]=Sin(r)*MoveSpeed[i]
- endfunction
- function InitMoveMode takes nothing returns nothing//初始化函数
- call TimerStart(CreateTimer(),.01,true,function MoveMode)//永久开启计时器
- endfunction
复制代码
调用方法:call AddMoveMode(玩家,辅助单位id,伤害来源,初始x,初始y,移动角度,移动速度,最大距离,伤害范围,碰撞检查范围,伤害值)
//角度 按角度制即 0-360
//伤害来源 即最终伤害由谁给出
//伤害范围 设置0 即只伤害目标 设置了正数 就能范围伤害(不伤害队友) 设置负数 伤害队友的范围伤害
//碰撞检查范围 设置了正数 就碰到敌人才爆炸 设置负数 碰到队友也爆炸
- 2.AngleBetweenAngles 角度差
- function AngleBetweenAnglesDEG takes real f1,real f2 returns real
- local real r=f1-f2
- if r<0. then
- if r<-180. then
- return 360.+r
- else
- return -r
- endif
- else
- if r<180. then
- return r
- else
- return 360.-r
- endif
- endif
- endfunction
- function AngleBetweenAnglesRAD takes real f1,real f2 returns real
- local real r=f1-f2
- if r<0. then
- if r<-bj_PI then
- return 6.28319+r
- else
- return -r
- endif
- else
- if r<bj_PI then
- return r
- else
- return 6.28319-r
- endif
- endif
- endfunction
- //------------------------
- 3.GetNearestUnitInRange 得到一定范围内距离某坐标最近的单位
- function DistanceBetweenCoords takes real Ax,real Ay,real Bx,real By returns real
- local real dx = Bx-Ax
- local real dy = By-Ay
- return SquareRoot(dx * dx + dy * dy)
- endfunction
- function GetNearestUnitInRangeA takes unit tu,unit u,real x,real y,real range,boolexpr filter returns unit
- local group g=CreateGroup()
- local real dis
- call GroupEnumUnitsInRange(g,x,y,range,filter)
- set u=FirstOfGroup(g)
- set tu=u
- loop
- exitwhen u==null
- set dis=DistanceBetweenCoords(GetUnitX(u),GetUnitY(u),x,y)
- if dis<range then
- set range=dis
- set tu=u
- endif
- call GroupRemoveUnit(g,u)
- set u=FirstOfGroup(g)
- endloop
- call DestroyGroup(g)
- set g=null
- return tu
- endfunction
- function GetNearestUnitInRange takes real x,real y,real range,boolexpr filter returns unit
- return GetNearestUnitInRangeA(null,null,x,y,range,filter)
- endfunction
复制代码
- 4.DistanceFromPointToLine 点到直线距离
- function DistanceFromPointToLine_PK takes real pointX, real pointY, real lineX, real lineY, real angle returns real
- //调用 DistanceFromPointToLine_PK(点坐标x,点坐标y,直线上一点坐标x,直线上一点坐标y,直线角度)
- //返回 任意一点到直线的距离 弧度制 -bj_PI ~ bj_PI
- local real lineA
- set lineA = Tan(angle)
- set lineA = (lineA*pointX-pointY-lineA*lineX+lineY)/SquareRoot(lineA*lineA+1)
- if lineA>=0 then
- return lineA
- else
- return -lineA
- endif
- endfunction
- function DistanceFromPointToLine takes real x0, real y0, real Aa, real Ba, real Ca returns real
- //任意一点(x,y)到直线(Ax+By+C=0)的距离
- set Aa = (x0*Aa+y0*Ba+Ca)/SquareRoot(Aa*Aa+Ba*Ba)
- if Aa>=0 then
- return Aa
- else
- return -Aa
- endif
- endfunction
- //==============================
- 5.GroupEnumUnitsInRectangle 选取任意角度矩形范围内单位组
- function IsInRectangle takes real cx,real cy,real x,real y,real l,real w,real angle returns boolean
- local real dis
- local real dx
- local real dy
- set l=l/2
- set w=w/2
- set dx=cx-x
- set dy=cy-y
- set dis=SquareRoot(dx*dx+dy*dy)
- set angle=Atan2(dy,dx)-angle
- set cx=x+dis*Cos(angle)
- set cy=y+dis*Sin(angle)
- return (cx>x-l and cx<x+l and cy>y-w and cy<y+w)
- endfunction
- globals
- real udg_GEUIRA_tempX
- real udg_GEUIRA_tempY
- real udg_GEUIRA_tempA
- real udg_GEUIRA_tempL
- real udg_GEUIRA_tempW
- endglobals
- function GroupEnumUnitsInRectangleFilter takes nothing returns boolean
- return IsInRectangle(GetUnitX(GetFilterUnit()),GetUnitY(GetFilterUnit()),udg_GEUIRA_tempX,udg_GEUIRA_tempY,udg_GEUIRA_tempL,udg_GEUIRA_tempW,udg_GEUIRA_tempA)
- endfunction
- function GroupEnumUnitsInRectangle takes group g,real x,real y,real l,real w,real angle returns nothing
- //点x,y为矩形中心
- set udg_GEUIRA_tempX=x
- set udg_GEUIRA_tempY=y
- set udg_GEUIRA_tempA=angle
- set udg_GEUIRA_tempL=l
- set udg_GEUIRA_tempW=w
- call GroupEnumUnitsInRange(g,x,y,SquareRoot(l*l+w*w)/2,Condition(function GroupEnumUnitsInRectangleFilter))
- endfunction
复制代码
- //=======================================================
- // 函数:CreateEffectEX(locA,locB,modelName,rmLocs)
- // @locA:施法单位点
- // @locB:施法区域点
- // @modelName:特效模型路径,路径中的""请使用"\"代替,进行特殊字符转义
- // @rmLocs:是否删除点
- //=======================================================
- function CreateEffectEX takes location locA,location locB,string modelName,boolean rmLocs returns nothing
- local real tempX = GetLocationX(locA)
- local real tempY = GetLocationX(locB)
- local real dis = DistanceBetweenPoints(locA,locB)
- local real angle = AngleBetweenPoints(locA,locB)
- local integer index = 0
- loop
- set tempX = tempX + 24*Cos(angle*bj_DEGTORAD)
- set tempY = tempY + 24*Sin(angle*bj_DEGTORAD)
- call DestroyEffect(AddSpecialEffect(modelName,tempX,tempY))
- set index = index + 1
- exitwhen index > dis/24
- endloop
- if rmLocs then
- call RemoveLocation(locA)
- call RemoveLocation(locB)
- endif
- endfunction
- 把下面函数贴在全局函数中,在触发中使用[ 自定义代码:call CreateEffectEX(locA,locB,modelName,rmLocs) ]调用这个函数就可以进行两点间任意特效创建了,特效的模型由自己指定。
复制代码 |
|