Warcraft III resources & community, 2003–2006 · archived

will of the bodygaurd

3 posts
#1

will of the bodygaurd

hello i was wondering if someone could help me out witha spell. i was thinking of a bodygaurd spell that woked kinda like spirit link, but passive, and for certain units. i wanted like the bodygaurd unit would have a chance to block damage for A hero thats very close like 30% chance to block damage for him and the body gaurd would recieve the damage
#2
I am sure, that is not the smartest solution, but it should work...

Simply create a trigger, name it "WillOfTheBodyguard", convert the trigger into custom code and overwrite everything with this one:
function WillOfTheBodyguard_Guardfilter takes nothing returns boolean
  return GetUnitTypeId(GetFilterUnit()) == <- BodyguardId -> and GetUnitOwner(GetFilterUnit()) == GetUnitOwner(GetTriggerUnit())
endfunction

function WillOfTheBodyguard_Actions takes nothing returns nothing
  local filterfunc guardfilter = Filter(function WillOfTheBodyguard_Guardfilter)
  local unit bodyguard
  local unit hero = GetTriggerUnit()
  local real heroX = GetUnitX(hero)
  local real heroY = GetUnitY(hero)
  local rect minDistance = Rect(heroX - 100,heroY - 100,heroX + 100,heroY + 100)
  local group bodyguards = CreateGroup()
  call GroupEnumUnitsInRect(bodyguards,minDistance,guardfilter)
  set bodyguard = GroupPickRandomUnit(bodyguards)
  if bodyguard != null then
    if GetRandomInt(0,100) <= 30 then
      call SetUnitState(bodyguard,UNIT_STATE_LIFE,RMaxBJ(0,GetUnitState(bodyguard,UNIT_STATE_LIFE) - GetEventDamage()))
      call SetUnitState(hero,UNIT_STATE_LIFE,GetUnitState(hero,UNIT_STATE_LIFE) + GetEventDamage())
    endif
  endif
  call DestroyFilter(guardfilter)
  call RemoveRect(minDistance)
  set guardfilter = null
  set bodyguard = null
  set hero = null
  set minDistance = null
endfunction

function InitTrig_WillOfTheBodyguard takes nothing returns nothing
  set gg_trg_WillOfTheBodyguard = CreateTrigger()
  call TriggerRegisterUnitEvent(gg_trg_WillOfTheBodyguard, <- Hero Unit -> ,EVENT_UNIT_DAMAGED)
  call TriggerAddAction(gg_trg_WillOfTheBodyguard,function WillOfTheBodyguard_Actions)
endfunction


You will have to create variables for each hero and copy the line
"call TriggerRegisterUnitEvent(gg_trg_WillOfTheBodyguard, <- Hero Unit -> ,EVENT_UNIT_DAMAGED)"
for each one.

If you want the distance between hero and bodyguard to be bigger or smaller, rise or sink the numbers in the line
"local rect minDistance = Rect(heroX - 100,heroY - 100,heroX + 100,heroY + 100)".
They should all have the same value.

To make it look like an ability, create a passive ability, that does nothing and add it to the bodyguard's ones.
#3
sorry somewat of a newb with spells, and dont kno much about the variabels and dont kno how to do half of it. any other way to simplify?