scope CaptureShip initializer Init
globals
private constant integer Abi='A000' //Your Capture Ship Abi ID
//private constant integer Buff='B000' //Your Board Ship Buff
private constant integer Inventory='A001' // The 'Add Inventory(Hero)'
private constant string SFX = "UI\\Feedback\\GoldCredit\\GoldCredit.mdl"
private constant string Message="Capture Ship Success!"
private constant string Message2="Failed!"
endglobals
private function c takes nothing returns boolean
local unit u=GetTriggerUnit()
local unit tu=GetSpellTargetUnit()
local integer Chance=0
local integer ChanceInt=0
local location loc=GetUnitLoc(tu)
if GetSpellAbilityId()==Abi then //and GetUnitAbilityLevel(u,Buff)>0 then I DONT KNOW WhAT'S THAT BUFF >.<
if GetOwningPlayer(u)!= Player(0) and GetOwningPlayer(tu) != Player(8) then
if GetPlayerSlotState(GetOwningPlayer(tu)) != PLAYER_SLOT_STATE_PLAYING and GetOwningPlayer(tu) != GetOwningPlayer(u) then
set Chance=Chance+10-R2I(GetUnitStatePercent(tu, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE))
//set Chance=100
set ChanceInt=GetRandomInt(0,100)
if ChanceInt <= Chance then
call SetUnitOwner(tu,GetOwningPlayer(u),true)
call UnitAddAbility(tu,Inventory)
set Chance=0
loop
exitwhen Chance>5
call UnitAddItem(tu,(UnitItemInSlot(u,Chance)))
set Chance=Chance+1
endloop
////////////////////
// The Eye Candies//
////////////////////
call DestroyEffect(AddSpecialEffectLoc(SFX,loc))
call SetUnitState(tu,UNIT_STATE_LIFE,(GetUnitState(tu,UNIT_STATE_MAX_LIFE)))
call SetUnitState(tu,UNIT_STATE_MANA,(GetUnitState(tu,UNIT_STATE_MAX_MANA)))
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, Message)
else
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, Message2)
call KillUnit(u)
endif
endif
endif
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function c))
endfunction
endscope