杀怪加属性脚本
首先制作一个物品 id 为pmna
初始化一个触发
globals
constant boolean LIBRARY_YDWEGetItemOfTypeFromUnitBJNull=true
item yd_NullTempItem
constant boolean LIBRARY_YDWETriggerEvent=true
trigger yd_DamageEventTrigger=null
trigger array YDWETriggerEvent__DamageEventQueue
integer YDWETriggerEvent__DamageEventNumber=0
item bj_lastMovedItemInItemSlot=null
trigger YDWETriggerEvent__MoveItemEventTrigger=null
trigger array YDWETriggerEvent__MoveItemEventQueue
integer YDWETriggerEvent__MoveItemEventNumber=0
constant boolean LIBRARY_YDWEUnitHasItemOfTypeBJNull=true
trigger gg_trg_a=null
endglobals
设置触发条件
function Trig_aConditions takes nothing returns boolean
return((IsUnitEnemy(GetDyingUnit(),GetOwningPlayer(GetKillingUnitBJ()))==true)and(IsUnitType(GetKillingUnitBJ(),UNIT_TYPE_HERO)==true)and(YDWEUnitHasItemOfTypeBJNull(GetKillingUnitBJ(),'pmna')==true))
endfunction
设置要执行的操作,这里我们添加英雄三围
function Trig_aActions takes nothing returns nothing
if((IsUnitType(GetDyingUnit(),UNIT_TYPE_HERO)==true))then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,10)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,10)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,10)
else
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
endif
endfunction
根据难度设置不同等级下三围增加
function Trig_aActions takes nothing returns nothing
if((IsUnitType(GetDyingUnit(),UNIT_TYPE_HERO)==true))then
if ((GetClickedButtonBJ()==udg_selevt[0])) then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
else
if ((GetClickedButtonBJ()==udg_selevt[1])) then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
else
if ((GetClickedButtonBJ()==udg_selevt[2])) then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,3)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,3)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,3)
else
if ((GetClickedButtonBJ()==udg_selevt[3])) then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,4)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,4)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,4)
else
if ((GetClickedButtonBJ()==udg_selevt[4])) then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,8)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,8)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,8)
else
if ((GetClickedButtonBJ()==udg_selevt[5])) then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,16)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,16)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,16)
else
if ((GetClickedButtonBJ()==udg_selevt[6])) then
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,32)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,32)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,32)
endif
endif
endif
endif
endif
endif
endif
else
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
endif
endfunction
初始化触发器
function InitTrig_a takes nothing returns nothing
set gg_trg_a=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_a,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(gg_trg_a,Condition(function Trig_aConditions))
call TriggerAddAction(gg_trg_a,function Trig_aActions)
endfunction
初始化触发器放入系统个性化触发器系统中
function InitCustomTriggers takes nothing returns nothing
call InitTrig_a()
endfunction
个性化触发器系统放入 main 函数中
function main takes nothing returns nothing
call InitCustomTriggers()
endfunction
检查存在某件物品
function YDWEGetItemOfTypeFromUnitBJNull takes unit whichUnit,integer itemId returns item
local integer index=0
loop
set yd_NullTempItem=UnitItemInSlot(whichUnit,index)
if GetItemTypeId(yd_NullTempItem)==itemId then
return yd_NullTempItem
endif
set index=index+1
exitwhen index>=bj_MAX_INVENTORY
endloop
return null
endfunction
function YDWEAnyUnitDamagedTriggerAction takes nothing returns nothing
local integer i=0
loop
exitwhen i>=YDWETriggerEvent__DamageEventNumber
if YDWETriggerEvent__DamageEventQueue[i]!=null and IsTriggerEnabled(YDWETriggerEvent__DamageEventQueue[i])and TriggerEvaluate(YDWETriggerEvent__DamageEventQueue[i])then
call TriggerExecute(YDWETriggerEvent__DamageEventQueue[i])
endif
set i=i+1
endloop
endfunction
function YDWEAnyUnitDamagedFilter takes nothing returns boolean
if GetUnitAbilityLevel(GetFilterUnit(),'Aloc')<=0 then
call TriggerRegisterUnitEvent(yd_DamageEventTrigger,GetFilterUnit(),EVENT_UNIT_DAMAGED)
endif
return false
endfunction
function YDWEAnyUnitDamagedEnumUnit takes nothing returns nothing
local trigger t=CreateTrigger()
local region r=CreateRegion()
local group g=CreateGroup()
call RegionAddRect(r,GetWorldBounds())
call TriggerRegisterEnterRegion(t,r,Condition(function YDWEAnyUnitDamagedFilter))
call GroupEnumUnitsInRect(g,GetWorldBounds(),Condition(function YDWEAnyUnitDamagedFilter))
call DestroyGroup(g)
set r=null
set t=null
set g=null
endfunction
function YDWESyStemAnyUnitDamagedRegistTrigger takes trigger trg returns nothing
if trg==null then
return
endif
if YDWETriggerEvent__DamageEventNumber==0 then
set yd_DamageEventTrigger=CreateTrigger()
call TriggerAddAction(yd_DamageEventTrigger,function YDWEAnyUnitDamagedTriggerAction)
call YDWEAnyUnitDamagedEnumUnit()
endif
set YDWETriggerEvent__DamageEventQueue[YDWETriggerEvent__DamageEventNumber]=trg
set YDWETriggerEvent__DamageEventNumber=YDWETriggerEvent__DamageEventNumber+1
endfunction
function YDWESyStemItemUnmovableTriggerAction takes nothing returns nothing
local integer i=0
if GetIssuedOrderId()>=852002 and GetIssuedOrderId()<=852007 then
set bj_lastMovedItemInItemSlot=GetOrderTargetItem()
loop
exitwhen i>=YDWETriggerEvent__MoveItemEventNumber
if YDWETriggerEvent__MoveItemEventQueue[i]!=null and IsTriggerEnabled(YDWETriggerEvent__MoveItemEventQueue[i])and TriggerEvaluate(YDWETriggerEvent__MoveItemEventQueue[i])then
call TriggerExecute(YDWETriggerEvent__MoveItemEventQueue[i])
endif
set i=i+1
endloop
endif
endfunction
function YDWESyStemItemUnmovableRegistTrigger takes trigger trg returns nothing
if trg==null then
return
endif
if YDWETriggerEvent__MoveItemEventNumber==0 then
set YDWETriggerEvent__MoveItemEventTrigger=CreateTrigger()
call TriggerAddAction(YDWETriggerEvent__MoveItemEventTrigger,function YDWESyStemItemUnmovableTriggerAction)
call TriggerRegisterAnyUnitEventBJ(YDWETriggerEvent__MoveItemEventTrigger,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
endif
set YDWETriggerEvent__MoveItemEventQueue[YDWETriggerEvent__MoveItemEventNumber]=trg
set YDWETriggerEvent__MoveItemEventNumber=YDWETriggerEvent__MoveItemEventNumber+1
endfunction
function GetLastMovedItemInItemSlot takes nothing returns item
return bj_lastMovedItemInItemSlot
endfunction
function YDWEUnitHasItemOfTypeBJNull takes unit whichUnit,integer itemId returns boolean
local integer index=0
if itemId !=0 then
loop
if GetItemTypeId(UnitItemInSlot(whichUnit,index))==itemId then
return true
endif
set index=index+1
exitwhen index>=bj_MAX_INVENTORY
endloop
endif
return false
endfunction
function InitGlobals takes nothing returns nothing
set i=0
loop
exitwhen(i>1)
set udg_a[i]=0
set i=i+1
endloop
set i=0
loop
exitwhen(i>1)
set udg_s[i]=0
set i=i+1
endloop
endfunction