[转载]完美的刷怪系统
只需要在地图初始化的时候call InitCreep(),然后在Unit Die事件中call CreepDie(GetDyingUnit())就行了,注意要加一个
GameCache的变量CC, 这里设定的90s后自动复活,你可以自己修改.
特点:
1. 刷怪功能完美,,刷的新怪和原来的怪物初始位置相同,而且我这里设定了有50%的几率会刷出一个同等级但
是随机类型的怪物出来。可以自行取舍。召唤的出来的怪物不会被误刷。
2. 只需要利用地图的GameCache,不需要变量。
3. 我这里设定了当怪物原来所在的位置有建筑物时则不会复活,一直等到没有建筑物了再复活。这个设定是为了
避免已经清理矿区造好基地了,怪物还在不停的刷。可以自行取舍。
4. 里面附带了掉宝系统。
//Creep Die,只需要调用CreepDie()函数和InitCreep()函数
function H2HI takes handle h returns integer
return h
return 0
endfunction
function NearToBuildingFilter0 takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and GetPlayerId(GetOwningPlayer(GetFilterUnit()))<=11
endfunction
function NearToBuilding takes real X, real Y returns boolean
local location loc=Location(X,Y)
local group g=GetUnitsInRangeOfLocMatching(800, loc, Condition(function NearToBuildingFilter0))
local boolean yn=( FirstOfGroup(g)!=null )
call RemoveLocation(loc)
call DestroyGroup(g)
return yn
endfunction
function CreepRevive takes nothing returns nothing
local timer tm= GetExpiredTimer()
local string tmMis="CreepTimer"+I2S(H2HI(tm))
local string creepMis
local integer TypeId=GetStoredInteger(udg_CC,tmMis,"TypeId")
local real X=GetStoredReal(udg_CC,tmMis,"X")
local real Y=GetStoredReal(udg_CC,tmMis,"Y")
local real Facing=GetStoredReal(udg_CC,tmMis,"Facing")
local unit u
if NearToBuilding(X,Y) then
call TimerStart(tm,60,false,function CreepRevive)
return
endif
call FlushStoredMission(udg_CC,tmMis)
call DestroyTimer(tm)
set u=CreateUnit(Player(12),TypeId,X,Y,Facing)
call SetUnitAcquireRange( u, 200 )
set creepMis="Creep"+I2S(H2HI(u))
call StoreInteger(udg_CC,creepMis,"TypeId",TypeId)
call StoreReal(udg_CC,creepMis,"X",X)
call StoreReal(udg_CC,creepMis,"Y",Y)
call StoreReal(udg_CC,creepMis,"Facing",Facing)
endfunction
function CreepDie takes unit u returns nothing
local integer itemId=0
local string mis="Creep"+I2S(H2HI(u))
local timer tm=CreateTimer()
local string tmMis="CreepTimer"+I2S(H2HI(tm))
local integer TypeId=0
//drop item
if GetRandomInt(1,100)<=20 then
loop
exitwhen itemId!=0
set itemId=ChooseRandomItemEx(ConvertItemType(GetRandomInt(0,4)),GetUnitLevel(u)*GetRandomInt(7,10)/10)
endloop
call CreateItem(itemId,GetUnitX(u),GetUnitY(u))
endif
//revive creep
set TypeId=GetStoredInteger(udg_CC,mis,"TypeId")
if TypeId==0 then
//unknown creep, no revive
return
endif
if GetRandomInt(1,2)<=1 then
set TypeId=ChooseRandomCreep(GetUnitLevel(u))
endif
call StoreInteger(udg_CC,tmMis,"TypeId",TypeId)
call StoreReal(udg_CC,tmMis,"X",GetStoredReal(udg_CC,mis,"X"))
call StoreReal(udg_CC,tmMis,"Y",GetStoredReal(udg_CC,mis,"Y"))
call StoreReal(udg_CC,tmMis,"Facing",GetStoredReal(udg_CC,mis,"Facing"))
call FlushStoredMission(udg_CC,mis)
call TimerStart(tm,90,false,function CreepRevive)
endfunction
//Init Creep
function InitCreepEnum takes nothing returns nothing
local unit u=GetEnumUnit()
local string mis
if IsUnitType(u,UNIT_TYPE_STRUCTURE)==false then
set mis="Creep"+I2S(H2HI(u))
call StoreInteger(udg_CC,mis,"TypeId",GetUnitTypeId(u))
call StoreReal(udg_CC,mis,"X",GetUnitX(u))
call StoreReal(udg_CC,mis,"Y",GetUnitY(u))
call StoreReal(udg_CC,mis,"Facing",GetUnitFacing(u))
endif
endfunction
function InitCreep takes nothing returns nothing
local group g=CreateGroup()
call GroupEnumUnitsOfPlayer(g,Player(12),null)
call ForGroup(g, function InitCreepEnum )
call DestroyGroup(g)
endfunction