找回密码
 点一下
查看: 1777|回复: 2

这个系统为何不能通过编译?

[复制链接]
发表于 2015-1-24 12:50:50 | 显示全部楼层 |阅读模式
本帖最后由 RoyalFlare 于 2015-1-24 12:56 编辑

检查单位可通行状态

  1. library CheckPathability initializer init
  2. public function init takes nothing returns nothing
  3. function CheckPathability takes unit u, real x, real y returns boolean
  4.     local real ox = GetUnitX(u)
  5.     local real oy = GetUnitY(u)
  6.     if x > 9376. or x < -9632. or y > 9376. or y < -9632. then    //map bounds
  7.         return false
  8.     endif
  9.     call SetUnitX(u, -9472.) //move unit to safespot
  10.     call SetUnitY(u, 9216.)
  11.     call SetUnitPosition(checkpathabilityunit, x, y) //requires global unit here
  12.     set x = GetUnitX(checkpathabilityunit)-x
  13.     set y = GetUnitY(checkpathabilityunit)-y
  14.     call SetUnitX(checkpathabilityunit, -9472.) //moves global unit back to safespot
  15.     call SetUnitY(checkpathabilityunit, 9216.)
  16.     call SetUnitX(u, ox)
  17.     call SetUnitY(u, oy)
  18.     return x*x+y*y <= 100.
  19. endfunction
  20. function CheckPathability_IgnoreUnits takes real x, real y returns boolean
  21.     if x > 9376. or x < -9632. or y > 9376. or y < -9632. then    //map bounds
  22.         return false
  23.     endif
  24.     call SetItemPosition(checkpathabilityitem,x,y) //requires global item
  25.     call SetItemVisible(checkpathabilityitem, false)
  26.     set x = GetItemX(checkpathabilityitem)-x
  27.     set y = GetItemY(checkpathabilityitem)-y
  28.     return x*x+y*y <=100
  29. endfunction
  30. endfunction
  31. endlibrary
  32. //===========================================================================
  33. function InitTrig_Init takes nothing returns nothing
  34. endfunction
复制代码
击退主函数

  1. library Knockback requires CheckPathability
  2. globals
  3. // Things to change, !!CHANING THE DUMMY UNIT TO YOURS IS NECESSARY TO WORK!!
  4. private constant real Interval = 0.3125 // How often the timer will execute
  5. private constant integer Dummy = 'h000' // Rawcode ID of your dummy unit
  6. // Change these values to the ones where your unit should slide faster
  7. // NOTE: If you want any more terrain types added, create a new "private constant integer" named
  8. // TerrainIdx, replace x with the next number. After that, increase the "TerrainChecks" value by 1.
  9. private constant integer TerrainId1 = 'Nice' // Northrend Ice
  10. private constant integer TerrainId2 = 'Idki' // Icecrown Glacies, Dark Ice
  11. private constant integer TerrainId3 = 'Iice' // Icecrown Glacies, Ice
  12. private constant integer TerrainId4 = 'Ldrt'
  13. private constant integer TerrainId5 = 'Ldro'
  14. private constant integer TerrainId6 = 'Ldrg'
  15. private constant integer TerrainChecks = 6 // Amount of Terrain Checks which have to be checked
  16. // Things you mustn't change, necessary for the whole to work
  17. private timer KnockbackTimer = CreateTimer() // Timer used to move the unit
  18. private integer array StructArray // Struct array to allow multiple instances
  19. private integer TotalRunnings = 0 // Integer to show the number of running instances
  20. endglobals
  21. public struct Data
  22. unit KnockbackedUnit // Stores the unit which gets moved
  23. real MoveAmount // Amount of how many the unit gets moved each time
  24. real MoveAmountAbstraction // Amount of how many is substraced each time to make the movement slowly stop
  25. real sin // Stores the sin value of the unit to not need to execute it each time
  26. real cos // Same as above, only for the cos value
  27. real Radius // The radius in which units/trees will trigger
  28. real HitPercentage // The percentage of how fast the unit has to move from its original speed
  29. boolean UnitCanMove // Boolean to check if the unit gets paused during the whole thing or not
  30. boolean CheckTerrain // Boolean to check if the terrain should be checked or not
  31. string MoveEffect = "" // Model Path for the effect which gets created
  32. static method init takes unit Target, real Distance, real TimeUntilFinish, real Angle, real Radius, real HitPercentage, boolean UnitCanMove, boolean CheckTerrain, string EffectName returns Data
  33. // Creates the struct
  34. local Data data = .allocate()
  35. // Initializes the target as the KnockbackedUnit
  36. set data.KnockbackedUnit = Target
  37. // Formula for this. 2 * max distance moved, divided by the number of executions + 1. Simply, huh?
  38. set data.MoveAmount = 2 * Distance / ( ( TimeUntilFinish / Interval ) + 1 )
  39. // Formula for the Abtraction. Should be pretty obvious.
  40. set data.MoveAmountAbstraction = data.MoveAmount / ( TimeUntilFinish / Interval )
  41. // Sets up the sin and cos.
  42. set data.sin = Sin(Angle)
  43. set data.cos = Cos(Angle)
  44. // Sets up the radius
  45. set data.Radius = Radius
  46. // Sets up the percentage
  47. set data.HitPercentage = data.MoveAmount * HitPercentage
  48. // Sets up the booleans
  49. set data.UnitCanMove = UnitCanMove
  50. set data.CheckTerrain = CheckTerrain
  51. // Sets up the effect
  52. set data.MoveEffect = EffectName
  53. // If the unit shouldn't move, it will be paused. Before that it will be moved to its own position to stop all orders.
  54. if UnitCanMove then
  55. call SetUnitPosition ( Target, GetUnitX( Target ), GetUnitY( Target ) )
  56. call PauseUnit ( Target, true )
  57. endif
  58. // If there are no executions yet, the timer will be started.
  59. if TotalRunnings == 0 then
  60. call TimerStart ( KnockbackTimer, Interval, true, function Data.move )
  61. endif
  62. // Sets up the array for the structstack, and sets the running Knockbacks to one more.
  63. set StructArray[ TotalRunnings ] = data
  64. set TotalRunnings = TotalRunnings + 1
  65. return data
  66. endmethod
  67. static method move takes nothing returns nothing
  68. local Data data
  69. local integer LoopInteger = 0 // Needed for the structstack
  70. local real UnitX // X value of the unit, will be changed to get the new unitposition
  71. local real UnitY // same as above, for the Y value
  72. local rect CheckRect // Neede to check for the units/trees
  73. local boolean Pathable // To check if the terrain is pathable or not
  74. loop
  75. exitwhen LoopInteger >= TotalRunnings
  76. // Setup the struct for the usage
  77. set data = StructArray[ TotalRunnings - 1 ]
  78. // To not have some problems with the Pathability
  79. set Pathable = false
  80. // If theres an special effect specified, there will be one created, otherwise not.
  81. if data.MoveEffect != "" and data.MoveEffect != null then
  82. set UnitX = GetUnitX( data.KnockbackedUnit )
  83. set UnitY = GetUnitY( data.KnockbackedUnit )
  84. call DestroyEffect ( AddSpecialEffect( data.MoveEffect, UnitX, UnitY ) )
  85. set UnitX = UnitX + data.MoveAmount * data.cos
  86. set UnitY = UnitY + data.MoveAmount * data.sin
  87. else
  88. // Simple polar projection with X/Y values [ Old X/Y + amount * cos for X and sin for Y ]
  89. set UnitX = GetUnitX( data.KnockbackedUnit ) + data.MoveAmount * data.cos
  90. set UnitY = GetUnitY( data.KnockbackedUnit ) + data.MoveAmount * data.sin
  91. endif
  92. // Reduce the amount each time
  93. set data.MoveAmount = data.MoveAmount - data.MoveAmountAbstraction
  94. // Checks whether the terrain is pathable or not. thx to Vexorian for his function
  95. set Pathable = CheckPathability( UnitX, UnitY )
  96. if Pathable then
  97. call SetUnitX( data.KnockbackedUnit, UnitX )
  98. call SetUnitY( data.KnockbackedUnit, UnitY )
  99. endif
  100. // If the movement is finished (amount <= 0), the struct gets destroyed
  101. if data.MoveAmount <= 0 or Pathable == false then
  102. set TotalRunnings = TotalRunnings - 1
  103. set data = StructArray[ TotalRunnings ]
  104. call data.destroy()
  105. endif
  106. set LoopInteger = LoopInteger + 1
  107. endloop
  108. // When there are no knockbacks left, the timer gets paused
  109. if TotalRunnings == 0 then
  110. call PauseTimer( KnockbackTimer )
  111. endif
  112. endmethod
  113. method onDestroy takes nothing returns nothing
  114. // To unpause the unit when it is needed, after the destroy
  115. if .UnitCanMove == false then
  116. call PauseUnit( .KnockbackedUnit, false)
  117. endif
  118. endmethod
  119. endstruct
  120. function Knockback takes unit Target, real Distance, real TimeUntilFinish, real Angle, real Radius, real HitPercentage, boolean UnitCanMove, boolean CheckTerrain, string EffectName returns nothing
  121. call Data.init( Target, Distance, TimeUntilFinish, Angle, Radius, HitPercentage, UnitCanMove, CheckTerrain, EffectName )
  122. endfunction
  123. endlibrary
  124. //===========================================================================
  125. function InitTrig_Knockback takes nothing returns nothing
  126. endfunction
复制代码
最近重建地图的核心代码 用上老外的系统 JassHelper编译的时候提示如下
Line 60: Syntax Error, unexpected: "takes"?
指向这个位置
function CheckPathability takes unit u, real x, real y returns boolean
求各位大神答疑解惑 难道返回的布尔值有问题麽? takes不到数值[bq3]
@希瓦 @chyj4747 @ckpig @zhuzeitou @actboy168
原帖地址在此:
http://www.wc3c.net/showthread.php?t=92525
http://www.wc3c.net/showthread.php?t=93891

原始代码页:
http://peeeq.de/code.php?id=2195 KnockBack System
http://peeeq.de/code.php?id=2202 Library CheckPathability

冰封-1.w3x

19.31 KB, 下载次数: 0

 楼主| 发表于 2015-1-24 12:52:24 | 显示全部楼层

  1. //=======================================================================
  2. function H2I takes handle h returns integer
  3.     return h
  4.     return 0
  5. endfunction
  6. //=======================================================================
  7. //  Bullet Lancher Sys Support Function
  8. globals
  9.     real Main_MapMinX
  10.     real Main_MapMinY
  11.     real Main_MapMaxX
  12.     real Main_MapMaxY
  13. endglobals
  14. function sMapPointInit takes nothing returns nothing
  15.     local string s
  16.     set Main_MapMinX = GetRectMinX(bj_mapInitialPlayableArea)
  17.     set Main_MapMinY = GetRectMinY(bj_mapInitialPlayableArea)
  18.     set Main_MapMaxX = GetRectMaxX(bj_mapInitialPlayableArea)
  19.     set Main_MapMaxY = GetRectMaxY(bj_mapInitialPlayableArea)
  20.     set s = "MinX: " + R2S(Main_MapMinX) + " MinY: " + R2S(Main_MapMinY) + " MaxX: " + R2S(Main_MapMaxX) + " MaxY: " + R2S(Main_MapMaxY)
  21.     call DisplayTextToPlayer(Player(0),0,0,s)
  22. endfunction
  23. function sPointIsInMap takes real x, real y, boolean checkpath returns boolean
  24.     if checkpath then
  25.         if IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) then  // 这里可以修改地形判断的条件 这里是地面单位可通行 当然你也可以修改为空中单位可飞行 如果马甲单位有设置飞行高度的话
  26.             return false
  27.         endif
  28.     endif
  29.     if x < Main_MapMinX then
  30.         return false
  31.     endif
  32.     if x > Main_MapMaxX then
  33.         return false
  34.     endif
  35.     if y < Main_MapMinY then
  36.         return false
  37.     endif
  38.     if y > Main_MapMaxY then
  39.         return false
  40.     endif
  41.     return true
  42. endfunction
  43. function fCommonFilter takes nothing returns boolean
  44.     local unit u = GetFilterUnit()
  45.     if GetUnitState(u, UNIT_STATE_LIFE) <= 0 then
  46.         set u = null
  47.         return false
  48.     endif
  49.     if IsUnitType(u, UNIT_TYPE_STRUCTURE) then
  50.         set u = null
  51.         return false
  52.     endif
  53.     if GetUnitTypeId(u) == 'h000' then  // 'h000'为马甲单位ID 根据实际需要做相应修改 也可以同时匹配多个马甲单位ID
  54.         set u = null
  55.         return false
  56.     endif
  57.     set u = null
  58.     return true
  59. endfunction
  60. //=======================================================================
  61. //=======================================================================
  62. // TimerSys Main Function
  63. globals
  64.     timer array Main_Timer
  65.     integer Main_First_Timer
  66.     integer Main_First_Attachable_Timer
  67.     boolean array Main_Timer_Attachable
  68.    
  69.     integer Main_Max_Timer = 1000
  70. endglobals
  71. function TimerDataSysInit takes nothing returns nothing
  72.     local integer i = 0
  73.     set Main_Timer[0] = CreateTimer()
  74.     set Main_Timer_Attachable[0] = true
  75.     set Main_First_Timer = H2I(Main_Timer[0])
  76.     set Main_First_Attachable_Timer = Main_First_Timer
  77.     loop
  78.         set i = i + 1
  79.         exitwhen i == Main_Max_Timer
  80.             set Main_Timer[i] = CreateTimer()
  81.             set Main_Timer_Attachable[i] = true
  82.     endloop
  83. endfunction
  84. function TimerDataSysGetID takes nothing returns integer
  85.     local integer id = Main_First_Attachable_Timer - Main_First_Timer
  86.     local integer idr = id
  87.     set Main_Timer_Attachable[id] = false
  88.     loop
  89.         set id = id + 1
  90.         exitwhen id > Main_Max_Timer
  91.             if Main_Timer_Attachable[id] == true then
  92.                 set Main_First_Attachable_Timer = id + Main_First_Timer
  93.                 return idr
  94.             endif
  95.     endloop
  96.     return Main_Max_Timer + 1
  97. endfunction
  98. function TimerDataSysGetTimerID takes timer t returns integer
  99.     return H2I(t) - Main_First_Timer
  100. endfunction
  101. function TimerDataSysFlush takes timer t returns nothing
  102.     local integer id = H2I(t)
  103.     call PauseTimer(t)
  104.     set Main_Timer_Attachable[id - Main_First_Timer] = true
  105.     if Main_First_Attachable_Timer > id then
  106.         set Main_First_Attachable_Timer = id
  107.     endif
  108. endfunction
  109. //========================================================================
复制代码
调用方法:
新建1个触发器 命名为MapsInitialization

  1. MapsInitialzation
  2.     事件
  3.         地图初始化
  4.     条件
  5.     动作
  6.         -------- ------------------ 这一行无论如何都是要的... --------------------- --------
  7.         自定义代码:   call TimerDataSysInit()
  8.         -------- --------------------------------------------------------------------- --------
  9.         自定义代码:   call sMapPointInit()
  10.         -------- --------------------------------------------------------------------- --------
  11.         可见度 - 禁用 战争迷雾
  12.         可见度 - 禁用 黑色阴影
  13.         -------- --------------------------------------------------------------------- --------
复制代码


除了louter的这套系统以外是否还有其他的选择?
回复

使用道具 举报

 楼主| 发表于 2015-1-26 17:49:56 | 显示全部楼层
本帖最后由 RoyalFlare 于 2015-1-26 20:38 编辑

人工顶1下 GA论坛的人越来越少了
发个帖都没人回复XD
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-12-22 17:40 , Processed in 0.258019 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表