找回密码
 点一下
查看: 2884|回复: 6

执行者NO.2的函数库

[复制链接]
发表于 2009-5-14 10:27:42 | 显示全部楼层 |阅读模式
前言:我的函数库基本是七凑八凑凑来的。。。参考了画中人,橙zi,剑魔等人的函数库以及血戳的一些虚无的协助才写出来的

[jass]//初始化这个系统
//function InitYuko takes nothing returns nothing
globals
      group                   group126
      sound                   sound126
      texttag                 texttag126
      timer                   timer126
      lightning               lightning126
      unit                    unit126      
      effect                  effect126
      trigger                 trigger126
      real                    msg_x=0.2
      real                    msg_y=0.05
      real                    msg_time=30
      gamecache               Amamiya
      handle    array         DataSystem
      trigger                 DStrigger
      boolean   array         IsUsing
      integer                 length = 5000
      integer                 head
      integer   array         stack               
      integer                 SL
endglobals
//Return Bug
function H2I takes handle h returns integer
    return h
    return GetRandomInt(126,621)
endfunction
function H2S takes handle h returns string
    return I2S(H2I(h))
endfunction
function H2L takes handle h returns location
    return h
    return null
endfunction
function S2I2 takes string s returns integer
    return s
    return GetRandomInt(126,621)
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 I2Trg 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
//Check X and Y
function CheckX takes real x returns real
    local real r=GetRectMinX(bj_mapInitialPlayableArea)+50
    if(x<r)then
        return r
    endif
    set r=GetRectMaxX(bj_mapInitialPlayableArea)-50
    if(x>r)then
        return r
    endif
    return x
endfunction
function CheckY takes real y returns real
    local real r=GetRectMinY(bj_mapInitialPlayableArea)+50
    if(y<r)then
        return r
    endif
    set r=GetRectMaxY(bj_mapInitialPlayableArea)-50
    if(y>r)then
        return r
    endif
    return y
endfunction
function SetX takes unit u,real distance,real facing returns nothing
    call SetUnitX( u, CheckX(GetUnitX(u) + distance*(Cos(facing)) *  bj_DEGTORAD ))
endfunction
function SetY takes unit u,real distance,real facing returns nothing
    call SetUnitY( u, CheckY(GetUnitY(u) + distance*(Sin(facing)) *  bj_DEGTORAD ))
endfunction
//RandomColor
function RandomColor takes string s returns string
    local string hex = "0123456789abcdef"
    local string color = null
    local string id = null
    local integer a = 0
    local integer b = 0
    loop
        set b = GetRandomInt(1,16)
        set id = SubString( hex, b - 1, b )
        set color = color + id
        set a = a + 1
        exitwhen a == 6
    endloop
    set id = null
    return "|cff" + color + s + "|r"
endfunction
//Messages
function Message takes string msg returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(),msg_x,msg_y,msg_time,msg)
endfunction
function RedMsg takes string msg returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(),msg_x,msg_y,msg_time,"|cffff0000"+msg)
endfunction
function GreenMsg takes string msg returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(),msg_x,msg_y,msg_time,"|cff00ff00"+msg)
endfunction
function YellowMsg takes string msg returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(),msg_x,msg_y,msg_time,"|cffffff00"+msg)
endfunction
function BlueMessage takes string msg returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(),msg_x,msg_y,msg_time,"|cff0000ff"+msg)
endfunction
function ErrorMsg takes player ForPlayer, string msg returns nothing
    if (GetLocalPlayer() == ForPlayer) then
    call ClearTextMessages()
    call DisplayTimedTextToPlayer( ForPlayer, 0.52, -1.00, 2.00, "|cffffcc00"+msg+"|r" )
    call PlaySound( "InterfaceError" )
    endif
endfunction
function RedGreenMsg takes string arg1,string arg2 returns nothing
    call Message("|cffff0000"+arg1+"|r|cff00ff00"+arg2)
endfunction
function RedYellowMsg takes string arg1,string arg2 returns nothing
    call Message("|cffff0000"+arg1+"|r|cffffff00"+arg2)
endfunction
function RedBlueMsg takes string arg1,string arg2 returns nothing
    call Message("|cffff0000"+arg1+"|r|cff0000ff"+arg2)
endfunction
function RedWhiteMsg takes string arg1,string arg2 returns nothing
    call Message("|cffff0000"+arg1+"|r"+arg2)
endfunction
function GreenWhiteMsg takes string arg1,string arg2 returns nothing
    call Message("|cff00ff00"+arg1+"|r"+arg2)
endfunction
function GreenYellowMsg takes string arg1,string arg2 returns nothing
    call Message("|cff00ff00"+arg1+"|r|cffffff00"+arg2)
endfunction
function WhiteRedMsg takes string arg1,string arg2 returns nothing
    call Message(arg1+"|cffff0000"+arg2)
endfunction
function WhiteYellowMsg takes string arg1,string arg2 returns nothing
    call Message(arg1+"|cffffff00"+arg2)
endfunction
function WhiteBlueMsg takes string arg1,string arg2 returns nothing
    call Message(arg1+"|cff0000ff"+arg2)
endfunction
function WhiteGreenMsg takes string arg1,string arg2 returns nothing
    call Message(arg1+"|cff00ff00"+arg2)
endfunction
//GameCache
function SetHandleInt takes handle h,string s,integer i returns nothing
    if i==0 then
        call FlushStoredInteger(Amamiya,H2S(h),s)
    else
        call StoreInteger(Amamiya,H2S(h),s,i)
    endif
endfunction
function SetHandleReal takes handle h,string s,real i returns nothing
    if i==0 then
        call FlushStoredReal(Amamiya,H2S(h),s)
    else
        call StoreReal(Amamiya,H2S(h),s,i)
    endif
endfunction
function SetHandleString takes handle h, string s, string z returns nothing
    if z==null then
        call FlushStoredString(Amamiya,H2S(h),s)
    else
        call StoreString(Amamiya, H2S(h), s, z)
    endif
endfunction
function SetHandleHandle takes handle h, string s, handle value returns nothing
    if value==null then
        call FlushStoredInteger(Amamiya,H2S(h),s)
    else
        call StoreInteger(Amamiya, H2S(h), s, H2I(value))
    endif
endfunction
function GetHandleInt takes handle h,string s returns integer
    return GetStoredInteger(Amamiya,H2S(h),s)
endfunction
function GetHandleReal takes handle h,string s returns real
    return GetStoredReal(Amamiya,H2S(h),s)
endfunction
function GetHandleString takes handle h,string s returns string
    return GetStoredString(Amamiya,H2S(h),s)
endfunction
function GetHandleUnit takes handle h, string s returns unit
    return GetStoredInteger(Amamiya, H2S(h), s)
    return null
endfunction
function GetHandleTimer takes handle h, string s returns timer
    return GetStoredInteger(Amamiya, H2S(h), s)
    return null
endfunction
function GetHandleGroup takes handle h, string s returns group
    return GetStoredInteger(Amamiya, H2S(h), s)
    return null
endfunction
function GetHandleEffect takes handle h, string s returns effect
    return GetStoredInteger(Amamiya, H2S(h), s)
    return null
endfunction
function FlushHandle takes handle h returns nothing
    call FlushStoredMission(Amamiya,H2S(h))
endfunction[/jass]
 楼主| 发表于 2009-5-14 10:28:31 | 显示全部楼层
[jass]//Function
function TimerRun takes code func,real timeout,boolean periodic returns timer
      set timer126=null
      set timer126=CreateTimer()
      call TimerStart(timer126,timeout,periodic,func)
      return timer126
endfunction
function EndTimer takes nothing returns nothing
      set timer126=GetExpiredTimer()
      if timer126!=null then
            call PauseTimer(timer126)
            call FlushHandle(timer126)
            call DestroyTimer(timer126)
      endif
endfunction
//TimedEffect
function AddTimedEffectPosUnit_Child takes nothing returns nothing
    set timer126=GetExpiredTimer()
    set effect126=GetHandleEffect(timer126,"effect_to_destroy")
    if effect126!=null then
    call DestroyEffect(effect126)
    endif
endfunction
function AddTimedEffectPosUnit takes unit u,string point,string modelname,real time returns nothing
    set timer126=TimerRun(function AddTimedEffectPosUnit_Child,time,false)
    set effect126=AddSpecialEffectTarget(modelname, u,point)
    call SetHandleInt(timer126,"effect_to_destroy",H2I(effect126))
endfunction
function GetBuffFrom takes nothing returns unit
    return unit126
endfunction
//WaitForBuff
function WaitForBuff_func takes nothing returns nothing
    local integer buffid
    local string func
    set trigger126=GetTriggeringTrigger()
    set buffid=GetHandleInt(trigger126,"buffid")
    set func=GetHandleString(trigger126,"func")
    if GetUnitAbilityLevel(GetTriggerUnit(),buffid)>0 and GetHandleUnit(trigger126,"master")==GetEventDamageSource()then
    call DisableTrigger(GetTriggeringTrigger())
    set  unit126=GetHandleUnit(trigger126,"master")
    call ExecuteFunc(func)
    call FlushHandle(trigger126)
    call DestroyTrigger(trigger126)
    endif
endfunction
function WaitForBuff takes unit master,unit target,integer buffid,string func returns nothing
    set trigger126=CreateTrigger()
    call TriggerRegisterUnitEvent(trigger126,target,EVENT_UNIT_DAMAGED)
    call TriggerAddAction(trigger126,function WaitForBuff_func)
    call SetHandleString(trigger126,"func",func)
    call SetHandleInt(trigger126,"buffid",buffid)
    call SetHandleInt(trigger126,"master",H2I(master))
endfunction
//Damaged
function FullDamageUnit takes unit from,unit to,real damage returns nothing
    call UnitDamageTarget(from,to,damage,true,false,null,null,null)
endfunction
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
//Fly
function Timer1Action takes nothing returns nothing
    local timer tm1=GetExpiredTimer()
    local timer tm2=I2Tm(GetHandleInt(tm1,"Timer2"))
    local unit u=I2U(GetHandleInt(tm1,"Unit"))
    local real startH=GetHandleReal(tm1,"StartHeight")
    local real height=GetHandleReal(tm1,"Height")
    local real timeout=GetHandleReal(tm1,"Timeout")
    local real t=TimerGetRemaining(tm2)-timeout
    local real h=startH+(height-startH)*(1-t*t/(timeout*timeout))
    call SetUnitFlyHeight(u,h,99999)
    set tm1=null
    set tm2=null
    set u=null
endfunction
function Timer2Action takes nothing returns nothing
    local timer tm2=GetExpiredTimer()
    local timer tm1=I2Tm(GetHandleInt(tm2,"Timer1"))
    local unit u=I2U(GetHandleInt(tm1,"Unit"))
    call SetUnitFlyHeight(u,0,99999)
    call FlushStoredInteger(Amamiya,I2S(H2I(u)),"JumpTimer")
    set u=null
    call FlushHandle(tm1)
    call PauseTimer(tm1)
    call DestroyTimer(tm1)
    set tm1=null
    call FlushHandle(tm2)
    call PauseTimer(tm2)
    call DestroyTimer(tm2)
    set tm2=null
    set u = null
endfunction
function Fly takes unit whichUnit, real height, real timeout returns nothing
    local timer tm1
    local timer tm2
    if GetHandleInt(whichUnit,"JumpTimer")==0 then
        set tm1=CreateTimer()
        set tm2=CreateTimer()
        call SetHandleInt(tm1,"Unit",H2I(whichUnit))
        call SetHandleReal(tm1,"StartHeight",GetUnitFlyHeight(whichUnit))
        call SetHandleReal(tm1,"Height",height)
        call SetHandleReal(tm1,"Timeout",timeout)
        call SetHandleInt(tm1,"Timer2",H2I(tm2))
        call SetHandleInt(tm2,"Timer1",H2I(tm1))
        call UnitAddAbility(whichUnit,'Arav')
        call UnitRemoveAbility(whichUnit,'Arav')
        call SetHandleInt(whichUnit,"JumpTimer",H2I(tm1))
        call TimerStart(tm1,0.01,true,function Timer1Action)
        call TimerStart(tm2,timeout*2,false,function Timer2Action)
    endif
    set tm1=null
    set tm2=null
endfunction
//DataSystem
function InitTimerSys takes nothing returns nothing
    local integer index=0
    loop      
        exitwhen index==length
        set DataSystem[index]=Location(126,621)
        call RemoveLocation(H2L(DataSystem[index]))
        set IsUsing[index]=false
        set stack[index]=index
        set index=index+1
    endloop
    set head=H2I(DataSystem[0])
    set SL=length
endfunction
function GetTimerSysHead takes nothing returns integer
    return head
endfunction
function GetTimerIndex takes handle h returns integer
    local integer i=H2I(h)
    if i<head or i>head+length then
    return -1
    else
    return i-head
    endif
endfunction
function GetIndexTimer takes integer i returns timer
    return i+head
    return null
endfunction
function NewTimer takes nothing returns timer
    set DStrigger=null
    if SL==0 then
        return null                  
    else
        set SL=SL-1
        set DataSystem[stack[SL]]=null
        set timer126=CreateTimer()
        set DataSystem[stack[SL]]=timer126
        set IsUsing[stack[SL]]=true
    endif
    return timer126
endfunction
function TimerDestroy takes timer t returns nothing
    local integer index=H2I(t)-head
    call DestroyTimer(t)
    if index<=0 or index>=head then
    return
    elseif IsUsing[index]==false then
    return
    endif
    set IsUsing[index]=false
    set stack[SL]=index
    set SL=SL+1
endfunction

function InitYuko takes nothing returns nothing
    call FlushGameCache(InitGameCache("Yuko.w3v"))
    set Amamiya=InitGameCache("Yuko.w3v")
endfunction[/jass]
回复

使用道具 举报

 楼主| 发表于 2009-5-14 10:29:28 | 显示全部楼层
发完了,沙发占领。。。
回复

使用道具 举报

发表于 2009-5-14 10:40:16 | 显示全部楼层
执行者竟然发帖跟我差不多
回复

使用道具 举报

发表于 2009-5-14 10:52:11 | 显示全部楼层
这个库能干啥捏?
回复

使用道具 举报

发表于 2009-5-14 13:19:20 | 显示全部楼层
突然发现 飞雪的贴就17个?
回复

使用道具 举报

发表于 2009-5-14 13:46:51 | 显示全部楼层
小剑剑童鞋的函数库还有待改进。。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-16 03:53 , Processed in 0.042711 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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