RoyalFlare 发表于 2015-1-24 12:50:50

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

本帖最后由 RoyalFlare 于 2015-1-24 12:56 编辑

检查单位可通行状态
library CheckPathability initializer init
public function init takes nothing returns nothing
function CheckPathability takes unit u, real x, real y returns boolean
    local real ox = GetUnitX(u)
    local real oy = GetUnitY(u)
    if x > 9376. or x < -9632. or y > 9376. or y < -9632. then    //map bounds
      return false
    endif
    call SetUnitX(u, -9472.) //move unit to safespot
    call SetUnitY(u, 9216.)
    call SetUnitPosition(checkpathabilityunit, x, y) //requires global unit here
    set x = GetUnitX(checkpathabilityunit)-x
    set y = GetUnitY(checkpathabilityunit)-y
    call SetUnitX(checkpathabilityunit, -9472.) //moves global unit back to safespot
    call SetUnitY(checkpathabilityunit, 9216.)
    call SetUnitX(u, ox)
    call SetUnitY(u, oy)
    return x*x+y*y <= 100.
endfunction
function CheckPathability_IgnoreUnits takes real x, real y returns boolean
    if x > 9376. or x < -9632. or y > 9376. or y < -9632. then    //map bounds
      return false
    endif
    call SetItemPosition(checkpathabilityitem,x,y) //requires global item
    call SetItemVisible(checkpathabilityitem, false)
    set x = GetItemX(checkpathabilityitem)-x
    set y = GetItemY(checkpathabilityitem)-y
    return x*x+y*y <=100
endfunction
endfunction
endlibrary
//===========================================================================
function InitTrig_Init takes nothing returns nothing
endfunction
击退主函数
library Knockback requires CheckPathability
globals
// Things to change, !!CHANING THE DUMMY UNIT TO YOURS IS NECESSARY TO WORK!!
private constant real Interval = 0.3125 // How often the timer will execute
private constant integer Dummy = 'h000' // Rawcode ID of your dummy unit
// Change these values to the ones where your unit should slide faster
// NOTE: If you want any more terrain types added, create a new "private constant integer" named
// TerrainIdx, replace x with the next number. After that, increase the "TerrainChecks" value by 1.
private constant integer TerrainId1 = 'Nice' // Northrend Ice
private constant integer TerrainId2 = 'Idki' // Icecrown Glacies, Dark Ice
private constant integer TerrainId3 = 'Iice' // Icecrown Glacies, Ice
private constant integer TerrainId4 = 'Ldrt'
private constant integer TerrainId5 = 'Ldro'
private constant integer TerrainId6 = 'Ldrg'
private constant integer TerrainChecks = 6 // Amount of Terrain Checks which have to be checked
// Things you mustn't change, necessary for the whole to work
private timer KnockbackTimer = CreateTimer() // Timer used to move the unit
private integer array StructArray // Struct array to allow multiple instances
private integer TotalRunnings = 0 // Integer to show the number of running instances
endglobals
public struct Data
unit KnockbackedUnit // Stores the unit which gets moved
real MoveAmount // Amount of how many the unit gets moved each time
real MoveAmountAbstraction // Amount of how many is substraced each time to make the movement slowly stop
real sin // Stores the sin value of the unit to not need to execute it each time
real cos // Same as above, only for the cos value
real Radius // The radius in which units/trees will trigger
real HitPercentage // The percentage of how fast the unit has to move from its original speed
boolean UnitCanMove // Boolean to check if the unit gets paused during the whole thing or not
boolean CheckTerrain // Boolean to check if the terrain should be checked or not
string MoveEffect = "" // Model Path for the effect which gets created
static method init takes unit Target, real Distance, real TimeUntilFinish, real Angle, real Radius, real HitPercentage, boolean UnitCanMove, boolean CheckTerrain, string EffectName returns Data
// Creates the struct
local Data data = .allocate()
// Initializes the target as the KnockbackedUnit
set data.KnockbackedUnit = Target
// Formula for this. 2 * max distance moved, divided by the number of executions + 1. Simply, huh?
set data.MoveAmount = 2 * Distance / ( ( TimeUntilFinish / Interval ) + 1 )
// Formula for the Abtraction. Should be pretty obvious.
set data.MoveAmountAbstraction = data.MoveAmount / ( TimeUntilFinish / Interval )
// Sets up the sin and cos.
set data.sin = Sin(Angle)
set data.cos = Cos(Angle)
// Sets up the radius
set data.Radius = Radius
// Sets up the percentage
set data.HitPercentage = data.MoveAmount * HitPercentage
// Sets up the booleans
set data.UnitCanMove = UnitCanMove
set data.CheckTerrain = CheckTerrain
// Sets up the effect
set data.MoveEffect = EffectName
// If the unit shouldn't move, it will be paused. Before that it will be moved to its own position to stop all orders.
if UnitCanMove then
call SetUnitPosition ( Target, GetUnitX( Target ), GetUnitY( Target ) )
call PauseUnit ( Target, true )
endif
// If there are no executions yet, the timer will be started.
if TotalRunnings == 0 then
call TimerStart ( KnockbackTimer, Interval, true, function Data.move )
endif
// Sets up the array for the structstack, and sets the running Knockbacks to one more.
set StructArray[ TotalRunnings ] = data
set TotalRunnings = TotalRunnings + 1
return data
endmethod
static method move takes nothing returns nothing
local Data data
local integer LoopInteger = 0 // Needed for the structstack
local real UnitX // X value of the unit, will be changed to get the new unitposition
local real UnitY // same as above, for the Y value
local rect CheckRect // Neede to check for the units/trees
local boolean Pathable // To check if the terrain is pathable or not
loop
exitwhen LoopInteger >= TotalRunnings
// Setup the struct for the usage
set data = StructArray[ TotalRunnings - 1 ]
// To not have some problems with the Pathability
set Pathable = false
// If theres an special effect specified, there will be one created, otherwise not.
if data.MoveEffect != "" and data.MoveEffect != null then
set UnitX = GetUnitX( data.KnockbackedUnit )
set UnitY = GetUnitY( data.KnockbackedUnit )
call DestroyEffect ( AddSpecialEffect( data.MoveEffect, UnitX, UnitY ) )
set UnitX = UnitX + data.MoveAmount * data.cos
set UnitY = UnitY + data.MoveAmount * data.sin
else
// Simple polar projection with X/Y values [ Old X/Y + amount * cos for X and sin for Y ]
set UnitX = GetUnitX( data.KnockbackedUnit ) + data.MoveAmount * data.cos
set UnitY = GetUnitY( data.KnockbackedUnit ) + data.MoveAmount * data.sin
endif
// Reduce the amount each time
set data.MoveAmount = data.MoveAmount - data.MoveAmountAbstraction
// Checks whether the terrain is pathable or not. thx to Vexorian for his function
set Pathable = CheckPathability( UnitX, UnitY )
if Pathable then
call SetUnitX( data.KnockbackedUnit, UnitX )
call SetUnitY( data.KnockbackedUnit, UnitY )
endif
// If the movement is finished (amount <= 0), the struct gets destroyed
if data.MoveAmount <= 0 or Pathable == false then
set TotalRunnings = TotalRunnings - 1
set data = StructArray[ TotalRunnings ]
call data.destroy()
endif
set LoopInteger = LoopInteger + 1
endloop
// When there are no knockbacks left, the timer gets paused
if TotalRunnings == 0 then
call PauseTimer( KnockbackTimer )
endif
endmethod
method onDestroy takes nothing returns nothing
// To unpause the unit when it is needed, after the destroy
if .UnitCanMove == false then
call PauseUnit( .KnockbackedUnit, false)
endif
endmethod
endstruct
function Knockback takes unit Target, real Distance, real TimeUntilFinish, real Angle, real Radius, real HitPercentage, boolean UnitCanMove, boolean CheckTerrain, string EffectName returns nothing
call Data.init( Target, Distance, TimeUntilFinish, Angle, Radius, HitPercentage, UnitCanMove, CheckTerrain, EffectName )
endfunction
endlibrary
//===========================================================================
function InitTrig_Knockback takes nothing returns nothing
endfunction
最近重建地图的核心代码 用上老外的系统 JassHelper编译的时候提示如下
Line 60: Syntax Error, unexpected: "takes"?
指向这个位置
function CheckPathability takes unit u, real x, real y returns boolean
求各位大神答疑解惑 难道返回的布尔值有问题麽? takes不到数值
@希瓦 @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

RoyalFlare 发表于 2015-1-24 12:52:24


//=======================================================================
function H2I takes handle h returns integer
    return h
    return 0
endfunction
//=======================================================================
//Bullet Lancher Sys Support Function
globals
    real Main_MapMinX
    real Main_MapMinY
    real Main_MapMaxX
    real Main_MapMaxY
endglobals
function sMapPointInit takes nothing returns nothing
    local string s
    set Main_MapMinX = GetRectMinX(bj_mapInitialPlayableArea)
    set Main_MapMinY = GetRectMinY(bj_mapInitialPlayableArea)
    set Main_MapMaxX = GetRectMaxX(bj_mapInitialPlayableArea)
    set Main_MapMaxY = GetRectMaxY(bj_mapInitialPlayableArea)
    set s = "MinX: " + R2S(Main_MapMinX) + " MinY: " + R2S(Main_MapMinY) + " MaxX: " + R2S(Main_MapMaxX) + " MaxY: " + R2S(Main_MapMaxY)
    call DisplayTextToPlayer(Player(0),0,0,s)
endfunction
function sPointIsInMap takes real x, real y, boolean checkpath returns boolean
    if checkpath then
      if IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) then// 这里可以修改地形判断的条件 这里是地面单位可通行 当然你也可以修改为空中单位可飞行 如果马甲单位有设置飞行高度的话
            return false
      endif
    endif
    if x < Main_MapMinX then
      return false
    endif
    if x > Main_MapMaxX then
      return false
    endif
    if y < Main_MapMinY then
      return false
    endif
    if y > Main_MapMaxY then
      return false
    endif
    return true
endfunction
function fCommonFilter takes nothing returns boolean
    local unit u = GetFilterUnit()
    if GetUnitState(u, UNIT_STATE_LIFE) <= 0 then
      set u = null
      return false
    endif
    if IsUnitType(u, UNIT_TYPE_STRUCTURE) then
      set u = null
      return false
    endif
    if GetUnitTypeId(u) == 'h000' then// 'h000'为马甲单位ID 根据实际需要做相应修改 也可以同时匹配多个马甲单位ID
      set u = null
      return false
    endif
    set u = null
    return true
endfunction
//=======================================================================
//=======================================================================
// TimerSys Main Function
globals
    timer array Main_Timer
    integer Main_First_Timer
    integer Main_First_Attachable_Timer
    boolean array Main_Timer_Attachable
   
    integer Main_Max_Timer = 1000
endglobals
function TimerDataSysInit takes nothing returns nothing
    local integer i = 0
    set Main_Timer = CreateTimer()
    set Main_Timer_Attachable = true
    set Main_First_Timer = H2I(Main_Timer)
    set Main_First_Attachable_Timer = Main_First_Timer
    loop
      set i = i + 1
      exitwhen i == Main_Max_Timer
            set Main_Timer = CreateTimer()
            set Main_Timer_Attachable = true
    endloop
endfunction
function TimerDataSysGetID takes nothing returns integer
    local integer id = Main_First_Attachable_Timer - Main_First_Timer
    local integer idr = id
    set Main_Timer_Attachable = false
    loop
      set id = id + 1
      exitwhen id > Main_Max_Timer
            if Main_Timer_Attachable == true then
                set Main_First_Attachable_Timer = id + Main_First_Timer
                return idr
            endif
    endloop
    return Main_Max_Timer + 1
endfunction
function TimerDataSysGetTimerID takes timer t returns integer
    return H2I(t) - Main_First_Timer
endfunction
function TimerDataSysFlush takes timer t returns nothing
    local integer id = H2I(t)
    call PauseTimer(t)
    set Main_Timer_Attachable = true
    if Main_First_Attachable_Timer > id then
      set Main_First_Attachable_Timer = id
    endif
endfunction
//========================================================================
调用方法:
新建1个触发器 命名为MapsInitialization
MapsInitialzation
    事件
      地图初始化
    条件
    动作
      -------- ------------------ 这一行无论如何都是要的... --------------------- --------
      自定义代码:   call TimerDataSysInit()
      -------- --------------------------------------------------------------------- --------
      自定义代码:   call sMapPointInit()
      -------- --------------------------------------------------------------------- --------
      可见度 - 禁用 战争迷雾
      可见度 - 禁用 黑色阴影
      -------- --------------------------------------------------------------------- --------


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

RoyalFlare 发表于 2015-1-26 17:49:56

本帖最后由 RoyalFlare 于 2015-1-26 20:38 编辑

人工顶1下 GA论坛的人越来越少了
发个帖都没人回复XD
页: [1]
查看完整版本: 这个系统为何不能通过编译?