• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

will of the bodygaurd

Status
Not open for further replies.
Level 2
Joined
Jun 22, 2006
Messages
6
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
 
Level 5
Joined
May 22, 2006
Messages
150
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:
JASS:
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.
 
Level 2
Joined
Jun 22, 2006
Messages
6
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?
 
Status
Not open for further replies.
Top