| 08-05-2009, 10:07 AM | #1 |
Hello ! I'm learning vJass to make some spells, and i'm trying to make a knockback spell, called MindPush. I learnt basics of vJass with a tutorial in the Hive Workshop and with this one http://www.wc3c.net/showthread.php?t=91491 to understand structs. I based my spell on this tutorial : http://www.wc3c.net/showthread.php?t=97068, to learn how to code a knockback. But my spell doesn't work ( the target is paused, but doesn't move ). I really don't understand why it's not working. I attach on my post the jass code, and the map. My spell:scope MindPush initializer Init //===Begining of Setup Part================================================ globals private constant integer SPELL_ID = 'A000' private constant real INTERVAL = 0.04 private constant real DURATION = 3.5 private constant damagetype D_TYPE = DAMAGE_TYPE_NORMAL private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC private constant string EFFECT = "Abilities\\Weapons\\BallistaMissile\\BallistaMissileTarget.mdl" endglobals private function KbDist takes integer level returns real return I2R(level) * 300 endfunction private function Damage takes integer level returns real return I2R(level) * 10 endfunction //===End of Setup Part===================================================== private struct Kback_Data unit u // Unit knockbacked real d1 real d2 real cos real sin effect e = null endstruct //========================================================================= globals private timer tim private Kback_Data array arKb private integer totalKb = 0 private item I = CreateItem('ciri', 0, 0) endglobals //===Vexorian's CheckPathability function reworked by Silvernon============ private function CheckPathabilityTrickGet takes nothing returns nothing set bj_rescueChangeColorUnit = bj_rescueChangeColorUnit or (GetEnumItem()!= I) endfunction private function CheckPathabilityTrick takes real x, real y returns boolean local integer i=30 local real X local real Y local rect r call SetItemPosition(I,x,y) set X = GetItemX(I) - x set Y = GetItemY(I) - y if X * X + Y * Y <=100 then return true endif set r=Rect(x-i,y-i,x+i,y+i) set bj_rescueChangeColorUnit=false call EnumItemsInRect(r,null,function CheckPathabilityTrickGet) call RemoveRect(r) set r=null return bj_rescueChangeColorUnit endfunction private function CheckPathability takes real x, real y returns boolean local boolean b = CheckPathabilityTrick(x,y) call SetItemVisible(I,false) return b endfunction //========================================================================= private function Knockback_Execute takes nothing returns nothing local Kback_Data kd local integer i = 0 local real x local real y loop exitwhen( i >= totalKb) set kd = arKb[i] set x = GetUnitX(kd.u) + kd.d1 * kd.cos set y = GetUnitY(kd.u) + kd.d1 * kd.sin if CheckPathability(x, y) then call SetUnitX(kd.u, x) call SetUnitY(kd.u, y) elseif CheckPathability(x, y) == false then //Target is stunned endif set kd.d1 = kd.d1 - kd.d2 if kd.d1 <= 0 then //End of Knockback if kd.e != null then call DestroyEffect(kd.e) endif call PauseUnit(kd.u, false) set arKb[i] = arKb[totalKb - 1] set totalKb = totalKb - 1 call kd.destroy() endif set i = i + 1 endloop if totalKb == 0 then call PauseTimer(tim) endif endfunction //========================================================================= private function Knockback takes unit u, real d, real a, real t returns nothing local Kback_Data kd = Kback_Data.create() local integer q = R2I(t / INTERVAL) set kd.u = u set kd.d1 = 2 * d / (q + 1) set kd.d2 = kd.d1 / q set kd.cos = Cos(a) set kd.sin = Sin(a) if EFFECT != "" then set kd.e = AddSpecialEffectTarget(EFFECT, u, "chest") endif call SetUnitPosition(u, GetUnitX(u), GetUnitY(u)) //For stoping any orders call PauseUnit(u, true) //Posing unit to avoid any undesirable effect while knockbacking if totalKb == 0 then call TimerStart(tim, INTERVAL, true, function Knockback_Execute) endif set totalKb = totalKb + 1 set arKb[totalKb - 1] = kd endfunction //===Actions conditions Init================================================== private function Actions takes nothing returns nothing local unit caster = GetTriggerUnit() local unit target = GetSpellTargetUnit() local integer level = GetUnitAbilityLevel(caster, SPELL_ID) local real dist = KbDist(level) local location locC = GetUnitLoc(caster) local location locT = GetUnitLoc(target) local real angle = Atan2(GetLocationY(locT) - GetLocationY(locC), GetLocationX(locT) - GetLocationX(locC)) call UnitDamageTarget(caster, target, Damage(level), true, false, A_TYPE, D_TYPE, null) call Knockback(target, dist, angle, DURATION) call RemoveLocation(locC) call RemoveLocation(locT) set locC = null set locT = null set caster = null set target = null endfunction //============================================================================ private function Conditions takes nothing returns boolean return GetSpellAbilityId() == SPELL_ID endfunction //============================================================================ private function Init takes nothing returns nothing local trigger MindPushTrg = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(MindPushTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT) call TriggerAddCondition(MindPushTrg, Condition(function Conditions)) call TriggerAddAction(MindPushTrg, function Actions ) set tim = CreateTimer() //preloading effects call Preload(EFFECT) endfunction endscope I hope you can help me to find my mistake(s) =) thanks Holystars |
| 08-05-2009, 11:46 AM | #2 |
No idea. Try adding some debug messages. |
| 08-05-2009, 01:57 PM | #3 |
Hi Anitarf, Thanks for that advice, I didn't think about trying to put some debug messages ... I could find where it doesn't work and it was a problem of pathability. I noticed that the item needed by the CheckPathablity function was not created, so I moved the initialisation of my global variable "I" to the function Init, and it perfectly works now =) That was a stupid mistake ^^ |
