|
楼主 |
发表于 2007-11-29 02:51:19
|
显示全部楼层
[codes=jass]
library ZHUZHU
globals
group gt_group
sound gt_sound
texttag gt_textgag
timer gt_timer
lightning gt_lightning
unit gt_unit
effect gt_effect
trigger gt_trigger
unit array gta_unit
integer gta_length
endglobals
globals
real msg_x=0.2
real msg_y=0.05
real msg_time=30
sound ErrorMsg_sound
gamecache zz_cache
endglobals
//floating text
function PointTextTag takes string text, real x, real y, integer red, integer green, integer blue returns texttag
set gt_textgag=CreateTextTag()
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)
return gt_textgag
endfunction
function UnitTextTag takes unit u,string text,integer r,integer g,integer b returns nothing
local integer length=StringLength(text)
set gt_textgag=PointTextTag(text,0,0,r,g,b)
call SetTextTagPosUnit(gt_textgag,u,100)
endfunction
//change
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 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
function Asc2I takes string char returns integer
local string charMap = " !\\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
local string u = SubString(char, 0, 1)
local string c
local integer i = 0
if u == "" or u == null then
return 0
elseif u == "\\b" then // Backspace?
return 8
elseif u == "\\t" then // Horizontal Tab?
return 9
elseif u == "\\n" then // Newline
return 10
elseif u == "\\f" then // Form feed?
return 12
elseif u == "\\r" then // Carriage return
return 13
endif
loop
set c = SubString(charMap, i, i + 1)
exitwhen c == ""
if c == u then
return i + 32
endif
set i = i + 1
endloop
return 0
endfunction
function ASC2I takes string arg returns integer
local integer a=Asc2I(SubString(arg,0,1))
local integer b=Asc2I(SubString(arg,1,2))
local integer c=Asc2I(SubString(arg,2,3))
local integer d=Asc2I(SubString(arg,3,4))
return a*256*256*256+b*256*256+c*256+d
endfunction
//message
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 StartSound( ErrorMsg_sound )
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
//group
function CloneGroup_Child takes nothing returns nothing
call GroupAddUnit(gt_group,GetEnumUnit())
endfunction
function CloneGroup takes group from returns group
if from==null then
return null
endif
set gt_group=CreateGroup()
call ForGroup(from,function CloneGroup_Child)
return gt_group
endfunction
function GroupPickRandomUnitFlush takes group g returns unit
local integer index
set gta_length=0
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)
return gta_unit[index]
endfunction
//GameCache
function SetData takes string lable,string key,integer value returns nothing
call StoreInteger(zz_cache,lable,key,value)
endfunction
function GetData takes string lable,string key returns integer
return GetStoredInteger(zz_cache,lable,key)
endfunction
function FlushTable takes handle lable returns nothing
call FlushStoredMission(zz_cache,H2S(lable))
endfunction
function FlushKey takes handle lable,string key returns nothing
call FlushStoredInteger(zz_cache,H2S(lable),key)
endfunction
function SetInt takes handle lable,string key,integer value returns nothing
call StoreInteger(zz_cache,H2S(lable),key,value)
endfunction
function GetInt takes handle lable,string key returns integer
return GetStoredInteger(zz_cache,H2S(lable),key)
endfunction
function SetStr takes handle lable,string key,string value returns nothing
call StoreInteger(zz_cache,H2S(lable),key,S2I2(value))
endfunction
function GetStr takes handle lable,string key returns string
return I2S2(GetStoredInteger(zz_cache,H2S(lable),key))
endfunction
function SetUnit takes handle lable,string key,unit u returns nothing
call StoreInteger(zz_cache,H2S(lable),key,H2I(u))
endfunction
function GetUnit takes handle lable,string key returns unit
return GetStoredInteger(zz_cache,H2S(lable),key)
return null
endfunction
function SetTimer takes handle lable,string key,timer u returns nothing
call StoreInteger(zz_cache,H2S(lable),key,H2I(u))
endfunction
function GetTimer takes handle lable,string key returns timer
return GetStoredInteger(zz_cache,H2S(lable),key)
return null
endfunction
function SetItem takes handle lable,string key,item u returns nothing
call StoreInteger(zz_cache,H2S(lable),key,H2I(u))
endfunction
function GetItem takes handle lable,string key returns item
return GetStoredInteger(zz_cache,H2S(lable),key)
return null
endfunction
function SetLightning takes handle lable,string key,lightning u returns nothing
call StoreInteger(zz_cache,H2S(lable),key,H2I(u))
endfunction
function GetLightning takes handle lable,string key returns lightning
return GetStoredInteger(zz_cache,H2S(lable),key)
return null
endfunction
function SetEffect takes handle lable,string key,effect u returns nothing
call StoreInteger(zz_cache,H2S(lable),key,H2I(u))
endfunction
function GetEffect takes handle lable,string key returns effect
return GetStoredInteger(zz_cache,H2S(lable),key)
return null
endfunction
//timer
function TimerRun takes code func,real timeout,boolean periodic returns timer
set gt_timer=null
set gt_timer=CreateTimer()
call TimerStart(gt_timer,timeout,periodic,func)
return gt_timer
endfunction
function EndTimer takes nothing returns nothing
set gt_timer=GetExpiredTimer()
if gt_timer!=null then
call PauseTimer(gt_timer)
call FlushTable(gt_timer)
call DestroyTimer(gt_timer)
endif
endfunction
//effect
function AddTimedEffectPosUnit_Child takes nothing returns nothing
set gt_timer=GetExpiredTimer()
set gt_effect=GetEffect(gt_timer,"effect_to_destroy")
if gt_effect!=null then
call DestroyEffect(gt_effect)
endif
endfunction
function AddTimedEffectPosUnit takes unit u,string point,string modelname,real time returns nothing
set gt_timer=TimerRun(function AddTimedEffectPosUnit_Child,time,false)
set gt_effect=AddSpecialEffectTarget(modelname, u,point)
call SetEffect(gt_timer,"effect_to_destroy",gt_effect)
endfunction
//buff
function GetBuffFrom takes nothing returns unit
return ga_unit
endfunction
function WaitForBuff_func takes nothing returns nothing
local integer buffid
local string func
set gt_trigger=GetTriggeringTrigger()
set buffid=GetInt(gt_trigger,"buffid")
set func=GetStr(gt_trigger,"func")
if GetUnitAbilityLevel(GetTriggerUnit(),buffid)>0 and GetUnit(gt_trigger,"master")==GetEventDamageSource()then
call DisableTrigger(GetTriggeringTrigger())
set gt_unit=GetUnit(gt_trigger,"master")
call ExecuteFunc(func)
call FlushTable(gt_trigger)
call DestroyTrigger(gt_trigger)
endif
endfunction
function WaitForBuff takes unit master,unit target,integer buffid,string func returns nothing
set gt_trigger=CreateTrigger()
call TriggerRegisterUnitEvent(gt_trigger,target,EVENT_UNIT_DAMAGED)
call TriggerAddAction(gt_trigger,function WaitForBuff_func)
call SetStr(gt_trigger,"func",func)
call SetInt(gt_trigger,"buffid",buffid)
call SetUnit(gt_trigger,"master",master)
endfunction
//unit
function FullDamageUnit takes unit from,unit to,real damage returns nothing
call UnitDamageTarget(from,to,damage,true,false,null,null,null)
endfunction
//math
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
//init map
function InitZhuzhu takes nothing returns nothing
//for sound
set ErrorMsg_sound=CreateSoundFromLabel( "InterfaceError",false,false,false,10,10)
set gta_unit[0]=null
call FlushGameCache(InitGameCache("zhuzhu.w3v"))
set zz_cache=InitGameCache("zhuzhu.w3v")
endfunction
function InitMap takes real l,real b,real r,real t returns nothing
call SetCameraBounds(l,b,r,t,l,b,r,t)
call InitZhuzhu()
endfunction
endlibrary
[/codes] |
|