找回密码
 点一下
查看: 3201|回复: 10

个人函数

[复制链接]
发表于 2008-8-28 14:45:45 | 显示全部楼层 |阅读模式
发布一些常用的函数,有自己做的,也有收集来的(主要还是自己做的,没有全部测试,有错误希望大家提出来)

欢迎各位继续添加
   
[codes=jass]globals
//创建游戏缓存GC
gamecache udg_GC
endglobals
//主题函数区
//转型函数(不断增加中)
function H2I takes handle h returns integer
      return h
      return 0
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
//漂浮文字(单位)    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 integer  length=StringLength(text)
      local texttag  gt_textgag=PointTextTag(text,0,0,r,g,b)
      call SetTextTagPosUnit(gt_textgag,u,100)
      set gt_textgag=null
endfunction
//复制一个单位组,产生一个新的.      CloneGroup(单位组)[会返回单位组]
function CloneGroup_Child takes group gt_group returns nothing
      call GroupAddUnit(gt_group,GetEnumUnit())
endfunction
function CloneGroup takes group from returns group
      local group gt_group=CreateGroup()
      local integer int=H2I(gt_group)
      if from==null then
            set gt_group=null
            return null
      endif
      call ForGroup(from,function CloneGroup_Child)
      set gt_group=null
      return I2G(int)
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
//游戏缓存相关
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 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)
endfunction
function 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 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))
endfunction
function SetUnit takes handle lable,string key,unit u returns nothing
      call StoreInteger(udg_GC,H2S(lable),key,H2I(u))
endfunction
function GetUnit takes handle lable,string key returns unit
      return GetStoredInteger(udg_GC,H2S(lable),key)
      return null
endfunction
function SetTimer takes handle lable,string key,timer u returns nothing
      call StoreInteger(udg_GC,H2S(lable),key,H2I(u))
endfunction
function GetTimer takes handle lable,string key returns timer
      return GetStoredInteger(udg_GC,H2S(lable),key)
      return null
endfunction
function SetItem takes handle lable,string key,item u returns nothing
      call StoreInteger(udg_GC,H2S(lable),key,H2I(u))
endfunction
function GetItem takes handle lable,string key returns item
      return GetStoredInteger(udg_GC,H2S(lable),key)
      return null
endfunction
function SetLightning takes handle lable,string key,lightning u returns nothing
      call StoreInteger(udg_GC,H2S(lable),key,H2I(u))
endfunction
function GetLightning takes handle lable,string key returns lightning
      return GetStoredInteger(udg_GC,H2S(lable),key)
      return null
endfunction
function SetEffect takes handle lable,string key,effect u returns nothing
      call StoreInteger(udg_GC,H2S(lable),key,H2I(u))
endfunction
function GetEffect takes handle lable,string key returns effect
      return GetStoredInteger(udg_GC,H2S(lable),key)
      return null
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
//让一个单位对另一个单位造成一个无视护甲,无视无敌,无视魔抗性的所谓神圣伤
//FullDamageUnit(施加伤害者,受伤害者,伤害值   实数)
function FullDamageUnit takes unit from,unit to,real damage returns nothing
      call UnitDamageTarget(from,to,damage,true,false,null,null,null)
endfunction
//返回两单位之间的距离    GetUnitDistance(单位,单位)返回实数
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
//等待   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 10% of 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(被击退单位,击退速度  实数,击退距离  实数,角度  实数,是否暂停单位  布尔值,特效)
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=I2S2(GetStoredInteger(udg_GC,H2S(tm),"spadd"))
    if (GetUnitX(u)+s*Cos(pt))<GetRectMaxX(bj_mapInitialPlayableArea)   then
        if  (GetUnitX(u)+s*Cos(pt))>GetRectMinX(bj_mapInitialPlayableArea)  then
             call SetUnitX(u,GetUnitX(u)+s*Cos(pt))
             endif
        endif
    if (GetUnitY(u)+s*Sin(pt))<GetRectMaxY(bj_mapInitialPlayableArea) and (GetUnitY(u)+s*Sin(pt))>GetRectMinY(bj_mapInitialPlayableArea)    then
        call SetUnitY(u,GetUnitY(u)+s*Sin(pt))
        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 StoreInteger(udg_GC,H2S(tm),"spadd",S2I2(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
//单位被抛出   UnitPoped(单位,高度,距离,角度,总时间,达最高点停顿时间)
function UnitPoped_Act takes nothing returns nothing
    local timer tm=GetExpiredTimer()
    local real passedtime=GetStoredReal(udg_GC,H2S(tm),"PassedTimer")
    call SetUnitX(I2U(GetStoredInteger(udg_GC,H2S(tm),"unit")),GetStoredReal(udg_GC,H2S(tm),"UnitX")+(GetStoredReal(udg_GC,H2S(tm),"space")*Cos(GetStoredReal(udg_GC,H2S(tm),"face"))*Cos((180*passedtime)/GetStoredReal(udg_GC,H2S(tm),"AllTimer"))))
    call SetUnitY(I2U(GetStoredInteger(udg_GC,H2S(tm),"unit")),GetStoredReal(udg_GC,H2S(tm),"UnitY")+(GetStoredReal(udg_GC,H2S(tm),"space")*Sin(GetStoredReal(udg_GC,H2S(tm),"face"))*Cos((180*passedtime)/GetStoredReal(udg_GC,H2S(tm),"AllTimer"))))
    call SetUnitFlyHeight(I2U(GetStoredInteger(udg_GC,H2S(tm),"unit")),GetStoredReal(udg_GC,H2S(tm),"hight")*Sin((180*passedtime)/GetStoredReal(udg_GC,H2S(tm),"AllTimer")),1000)
    call StoreReal(udg_GC,H2S(tm),"PassedTimer",passedtime+0.02)
endfunction
function UnitPoped takes unit u,real h,real s,real face,real t,real tt returns nothing
    local timer tm=CreateTimer()
    call StoreInteger(udg_GC,H2S(tm),"unit",H2I(u))
    call StoreReal(udg_GC,H2S(tm),"hight",h)
    call StoreReal(udg_GC,H2S(tm),"space",s)
    call StoreReal(udg_GC,H2S(tm),"face",face)
    call StoreReal(udg_GC,H2S(tm),"AllTimer",t)
    call StoreReal(udg_GC,H2S(tm),"PassedTimer",0)
    call StoreReal(udg_GC,H2S(tm),"UnitX",GetUnitX(u))
    call StoreReal(udg_GC,H2S(tm),"UnitY",GetUnitY(u))
    call TimerStart(tm,0.02,true,function UnitPoped_Act)
    call Wait(t/2)
    call PauseTimer(tm)
    call Wait(tt)
    call ResumeTimer(tm)
    call Wait(t/2)
    call FlushTable(tm)
    call PauseTimer(tm)
    call DestroyTimer(tm)
    set tm=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(创建单位的区域,单位玩家  非ID,单位种类   非ID,数量,目标X坐标,目标Y坐标,单位面向角度,命令   非ID)
function CreateUnitAndDoToPoint takes rect cr,player whichplayer,string 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=CreateUnitByName(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 player ply
    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        

[/codes]

评分

参与人数 1威望 +1 收起 理由
狡猾的兔子 + 1 很多实用函数。

查看全部评分

 楼主| 发表于 2008-8-28 15:03:07 | 显示全部楼层
实在是忘了怎么把它换成jass的显示形式,谁知道告诉我啊
回复

使用道具 举报

发表于 2008-8-28 15:04:47 | 显示全部楼层
[codes=jass][/codes]

这样
回复

使用道具 举报

发表于 2008-8-28 15:09:43 | 显示全部楼层
其实楼主把标签里面的code去掉就可以了
回复

使用道具 举报

 楼主| 发表于 2008-8-28 15:10:02 | 显示全部楼层
谢了
回复

使用道具 举报

 楼主| 发表于 2008-8-28 15:11:23 | 显示全部楼层
试过直接用[jass]和[\\jass]的没用
回复

使用道具 举报

发表于 2008-8-28 15:15:59 | 显示全部楼层
[jass]test code[/jass]

真的米有用么?
回复

使用道具 举报

发表于 2008-8-28 15:16:34 | 显示全部楼层
[jass]反斜杆…[/jass]
回复

使用道具 举报

发表于 2008-8-28 15:28:05 | 显示全部楼层
收下了,谢谢哦。
回复

使用道具 举报

发表于 2008-8-28 15:45:32 | 显示全部楼层
LSS的头像是用的秋之回忆的?。。
回复

使用道具 举报

发表于 2008-8-28 15:54:10 | 显示全部楼层
LS你怎么不说我的头像是 卓越之剑GE 的壁纸呢?
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-3 02:58 , Processed in 0.085575 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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