Flare
Stops copies me!
- Reaction score
- 662
Solved
For some reason, whenever I try to retrieve my struct data from a timer using HAIL, I get an error (cannot convert timer to integer). I also get a similar error when attaching the struct to a timer (cannot convert integer to timer)
Do I need to run the HAIL textmacro within the scope?
NOTE: This is my first time using HAIL, so if the problem is related to how I created the property or how I called the function, please explain exactly how I should fix it.
(I have marked the lines between a pair of comments. One error is in TimerActions, the other is in MeathookActions)
EDIT: oh... when I run the textmacro, the second argument is the type of the data BEING attached, not the handle type to which you are attaching the data...
For some reason, whenever I try to retrieve my struct data from a timer using HAIL, I get an error (cannot convert timer to integer). I also get a similar error when attaching the struct to a timer (cannot convert integer to timer)
Do I need to run the HAIL textmacro within the scope?
NOTE: This is my first time using HAIL, so if the problem is related to how I created the property or how I called the function, please explain exactly how I should fix it.
(I have marked the lines between a pair of comments. One error is in TimerActions, the other is in MeathookActions)
JASS:
//Meat Hook
//By Flare
//Constructed using vJASS and Strilanc's HAIL system
//Thanks to Strilanc for creating HAIL
//Thanks to DotA for the inspiration to make my own version of the spell
//REQUIRES NEWGEN WORLDEDITOR TO OPEN\\
//Importing instructions\\
///////////////////////////////////////////////////////
//Copy the HAIL trigger into your map
//Copy the Meathook trigger into your map
//Copy the Hook Dummy unit, Link Dummy unit and Meathook ability into your map
//Adjust the SPELLID, HOOKID and LINKID values in the global block.
//They MUST match the rawcodes shown in Object Editor (press Ctrl - D to view the rawcodes)
//Adjust the remainder of the constants to suit your needs
//Add the Meathook ability to a unit.
//Cast the ability, and enjoy.
///////////////////////////////////////////////////////
//End of importing instructions\\
//Initializing HAIL
//Do -NOT-, under ANY circumstances, change the following lines unless you know exactly what you are doing
//! runtextmacro HAIL_CreateProperty("HookTimer", "timer", "")
//! runtextmacro HAIL_CreateProperty("HookTrigger", "trigger", "")
scope Meathook
globals
//This limits the number of links to the hook's chain.
//Setting it higher will limit the MUI capability (currently, 81 instances max)
//Setting it lower will potentially limit the maximum distance travelled
//^--Depends on how close the links will be spawned beside each other
constant integer MAXLINKS = 100
//Rawcodes\\
//Base ability (Meathook) rawcode
private constant integer SPELLID = 039;A000039;
//Hook dummy rawcode
private constant integer HOOKID = 039;h000039;
//Link dummy ID
private constant integer LINKID = 039;h001039;
//Other constants\\
//Timer interval
private constant real TIMERINTERVAL = 0.03
//Distance travelled per second by hook
private constant real SPEED = 800
//Distance moved per timer interval
//Also used for distance between hook links
private constant real DISTANCE = SPEED*TIMERINTERVAL
//DISTANCE * MAXLINKS = Maximum possible distance. Increase SPEED, TIMERINTERVAL (not highly advised) or MAXLINKS to increase the maximum possible range.
//Currently, maximum range is 2400 (100 * (800*0.03) = 100 * 24 = 2400)
//-180 degrees in radians
//This is used for hook retraction
private constant real REVERSEANGLE = Deg2Rad (-180)
//Collision range
private constant real COLLIDERANGE = 100
//Hook size scale
private constant real HOOKSCALE = 1.
//Link size scale
private constant real LINKSCALE = 1.
//How far in front of the hero the hook will form
private constant real SPAWNOFFSET = 100
//Effect created on hook hit
//NOTE: Make sure you replace a single \ with \\ if you change this i.e.
//Abilities\Spells\Other\Stampede\StampedeMissileDeath.mdl --> Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl
private constant string FXSTRING = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"
//Determines whether the above effect is created when an ally is hit
//By default, no SFX will be created when hitting an ally.
private constant boolean ALLYHITSFX = false
endglobals
//DO NOT EDIT BELOW HERE
//--------------------------------------------------------------------------------\\
//Struct data for the hook
private struct Hookdata
unit hookcaster = null //The unit who casts Meathook
unit hooktarget = null //The target struck
unit array hooklink[MAXLINKS] //The links/segments of the hook chain
integer linkcounter //Used for creating/destroying the above units
real hookangle //Angle at which the hook travels
real currentdistance //Current distance travelled by the hook
real maxdistance //Maximum distance travelled before the hook retracts
real damage = 0//The damage, obviously
unit hook = null//The hook itself
real targetangle //Used to keep the angle between hook and victim correct on retract
real targetdistance //Same as above, except relates to distance instead of angle
boolean retracton = false
boolean targethooked = false
timer hooktimer //Timer used for extension/retraction
trigger hittrig //Trigger used for detecting when a unit is hit
method onDestroy takes nothing returns nothing //Cleaning up triggers/timers/HAIL
call ResetHookTimer (.hooktimer)
call DestroyTimer (.hooktimer)
call ResetHookTrigger (.hittrig)
call DestroyTrigger (.hittrig)
endmethod
endstruct
private function TimerActions takes nothing returns nothing
local timer t = GetExpiredTimer ()
//This line gives an error
local Hookdata a = GetHookTimer (t)
//------------------------
local real hx1 = GetUnitX (a.hook)
local real hy1 = GetUnitY (a.hook)
local real hx2
local real hy2
local real tx
local real ty
if a.retracton == false then
set a.linkcounter = a.linkcounter + 1
set a.hooklink[a.linkcounter] = CreateUnit (GetOwningPlayer (a.hookcaster), LINKID, hx1, hy1, Rad2Deg (a.hookangle))
set hx2 = hx1 + Cos(a.hookangle)*DISTANCE
set hy2 = hy1 + Sin (a.hookangle)*DISTANCE
else
set a.linkcounter = a.linkcounter - 1
call RemoveUnit (a.hooklink[a.linkcounter])
set hx2 = hx1 + Cos(a.hookangle + REVERSEANGLE)*DISTANCE
set hy2 = hy1 + Sin (a.hookangle + REVERSEANGLE)*DISTANCE
endif
set a.currentdistance = a.currentdistance + DISTANCE
call SetUnitPosition (a.hook, hx2, hy2)
if a.currentdistance >= a.maxdistance then
set a.retracton = true
endif
if a.targethooked == true then
set tx = hx2 + Cos (a.targetangle) * a.targetdistance
set ty = hy2 + Sin (a.targetangle) * a.targetdistance
call SetUnitPosition (a.hooktarget, tx, ty)
endif
endfunction
private function MeathookCond takes nothing returns boolean
return GetSpellAbilityId () == SPELLID
endfunction
private function MeathookActions takes nothing returns nothing
local Hookdata a = Hookdata.create ()
local location targetloc
local real cx
local real cy
local real tx
local real ty
local real sx
local real sy
set a.hookcaster = GetTriggerUnit ()
set a.linkcounter = 0
if GetSpellTargetUnit () == null then
set targetloc = GetSpellTargetLoc ()
set tx = GetLocationX (targetloc)
set ty = GetLocationY (targetloc)
call RemoveLocation (targetloc)
else
set tx = GetUnitX (GetSpellTargetUnit ())
set ty = GetUnitY (GetSpellTargetUnit ())
endif
set cx = GetUnitX (a.hookcaster)
set cy = GetUnitY (a.hookcaster)
set a.hookangle = Atan2 (ty-cy, tx-cx)
set sx = cx + Cos (a.hookangle)*SPAWNOFFSET
set sy = cy + Sin (a.hookangle)*SPAWNOFFSET
set a.hook = CreateUnit (GetOwningPlayer (a.hookcaster), HOOKID, sx, sy, Rad2Deg (a.hookangle))
set a.hooklink[a.linkcounter] = CreateUnit (GetOwningPlayer (a.hookcaster), LINKID, sx, sy, Rad2Deg (a.hookangle))
set a.hooktimer = CreateTimer ()
set a.hittrig = CreateTrigger ()
//This line gives an error
call SetHookTimer (a.hooktimer, a)
//------------------------
call TimerStart (a.hooktimer, TIMERINTERVAL, true, function TimerActions)
endfunction
public function InitTrig takes nothing returns nothing
local trigger Meathook = CreateTrigger ()
call TriggerRegisterAnyUnitEventBJ (Meathook, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition (Meathook, Condition (function MeathookCond))
call TriggerAddAction (Meathook, function MeathookActions)
endfunction
endscope
EDIT: oh... when I run the textmacro, the second argument is the type of the data BEING attached, not the handle type to which you are attaching the data...