1. globals
  2. constant integer MOUNT_UNIT_ID = 'n001'
  3. constant integer MOUNT_ABILITY_ID = 'A002'
  4. constant integer UNMOUNT_ABILITY_ID = 'A001'
  5. constant integer MOUNTED_BUFF_ID = 'B000'
  6. constant integer FLY_ABILITY_ID = 'Amrf'
  7. endglobals
  8. function Trig_Mount_Conditions takes nothing returns boolean
  9. return GetSpellAbilityId() == MOUNT_ABILITY_ID
  10. endfunction
  11. struct MountingData
  12. unit mounter
  13. unit mount
  14. timer time
  15. static method create takes unit caster, unit created returns MountingData
  16. local MountingData d = MountingData.allocate()
  17. set d.mounter = caster
  18. set d.mount = created
  19. return d
  20. endmethod
  21. method onDestroy takes nothing returns nothing
  22. set .mounter = null
  23. set .mount = null
  24. call ReleaseTimer(.time)
  25. endmethod
  26. endstruct
  27.  
  28. function MoveMounter takes nothing returns nothing
  29. local MountingData d = GetTimerData(GetExpiredTimer())
  30. local real x = GetWidgetX(d.mount) + 20 * Cos(GetUnitFacing(d.mount) * bj_DEGTORAD)
  31. local real y = GetWidgetY(d.mount) + 20 * Sin(GetUnitFacing(d.mount) * bj_DEGTORAD)
  32. call SetUnitX(d.mounter,x)
  33. call SetUnitY(d.mounter,y)
  34. call SetUnitFacing(d.mounter,GetUnitFacing(d.mount))
  35. endfunction
  36. function Trig_Mount_Actions takes nothing returns nothing
  37. local unit mounter = GetSpellAbilityUnit()
  38. local unit mount = CreateUnit(GetOwningPlayer(mounter), MOUNT_UNIT_ID, GetWidgetX(mounter), GetWidgetY(mounter), GetUnitFacing(mounter))
  39. local MountingData d = MountingData.create(mounter,mount)
  40.  
  41. set d.time = NewTimer()
  42. call SetTimerData(d.time,d)
  43.  
  44. if GetLocalPlayer() == GetOwningPlayer(mounter) then
  45. call ClearSelection()
  46. call SelectUnit(mount, true)
  47. endif
  48.  
  49. call SetUnitPathing(mounter, false)
  50. call UnitAddAbility(mounter, FLY_ABILITY_ID)
  51. call SetUnitFlyHeight(mounter, 50.0, 0)
  52. call PauseUnit(mounter, true)
  53.  
  54. set mounter = null
  55. set mount = null
  56.  
  57. call TimerStart(d.time,0.03,true,function MoveMounter)
  58. endfunction
  59.  
  60. //===========================================================================
  61. function InitTrig_Mount takes nothing returns nothing
  62. local trigger mount = CreateTrigger()
  63. local trigger unmount = CreateTrigger()
  64. call TriggerRegisterAnyUnitEventBJ(mount, EVENT_PLAYER_UNIT_SPELL_FINISH)
  65. call TriggerAddCondition(mount, Condition(function Trig_Mount_Conditions))
  66. call TriggerAddAction(mount, function Trig_Mount_Actions)
  67. endfunction
  68.  
  69.