| 03-22-2008, 03:31 AM | #1 |
While making an ability, I came to an odd impasse. When I test the follow spell: Intercept:scope Intercept globals private constant integer spellid = 'A04K' private constant string spellart = "Abilities\\Weapons\\DemolisherFireMissile\\DemolisherFireMissile.mdl" private constant string blinkart = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl" private constant string areaart = "Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodKnight.mdl" private constant string healart = "Abilities\\Spells\\Undead\\VampiricAura\\VampiricAuraTarget.mdl" private constant real rad = 450. endglobals private function cond takes nothing returns boolean return GetSpellAbilityId() == spellid endfunction private function filter takes nothing returns boolean return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) and (IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) == false) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) > 0. endfunction private function actions takes nothing returns nothing local unit u = GetTriggerUnit() local unit t = GetSpellTargetUnit() local integer lvl = GetUnitAbilityLevel(u,spellid) local real x = GetUnitX(t) local real y = GetUnitY(t) local real f = GetUnitFacing(t) local group g = CreateGroup() local real ang local boolexpr b = Condition(function filter) local unit m local real dmg = (GetHeroStr(u,true)*(I2R(lvl))) local real dmgcnt debug call BJDebugMsg(R2S(dmg)) call DestroyEffect(AddSpecialEffect(blinkart,GetUnitX(u),GetUnitY(u))) call SetUnitX(u,(x+100.*Cos(f*bj_DEGTORAD))) call SetUnitY(u,(y+100.*Sin(f*bj_DEGTORAD))) call DestroyEffect(AddSpecialEffectTarget(spellart,u,"origin")) call GroupEnumUnitsInRange(g,x,y,rad,b) loop set m = FirstOfGroup(g) exitwhen m == null set ang = Atan2(GetUnitY(m) - GetUnitY(u), GetUnitX(m) - GetUnitX(u)) call UnitDamageTarget(u,m,dmg,true,false,ATTACK_TYPE_HERO,DAMAGE_TYPE_FORCE,WEAPON_TYPE_WHOKNOWS) call DestroyEffect(AddSpecialEffectTarget(areaart,m,"origin")) call KS_KnockbackUnit(m,150.,ang,KS_GetUnitMass(u)) call GroupRemoveUnit(g,m) set dmgcnt = dmgcnt + dmg debug call BJDebugMsg(R2S(dmgcnt)) endloop debug call BJDebugMsg(R2S(dmgcnt)) set dmgcnt = dmgcnt * (I2R(lvl) * .05) debug call BJDebugMsg(R2S(dmgcnt)) call SetUnitState(u,UNIT_STATE_LIFE,(GetUnitState(u,UNIT_STATE_LIFE) + dmgcnt)) call BJDebugMsg("wtf") call DestroyEffect(AddSpecialEffectTarget(healart,u,"origin")) set u = null set t = null call DestroyBoolExpr(b) call DestroyGroup(g) set b = null set g = null endfunction function InitTrig_Intercept takes nothing returns nothing local trigger tr = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(tr,EVENT_PLAYER_UNIT_SPELL_EFFECT) call TriggerAddCondition(tr,Condition(function cond)) call TriggerAddAction(tr,function actions) set tr = null call Preload(spellart) call Preload(areaart) call Preload(healart) call Preload(blinkart) endfunction endscope Text showing "24.000" appears (which is the hero's starting strength) The hero "blinks" to the target location, the first two effects are spawned and one seemingly random unit gets damaged and knocked back (thanks to emjlr3 for the knockback system :)). No other text appears onscreen, the hero does not get healed and the healing effect does not spawn. Upon multiple castings, the same unit that was "randomly" picked is the only one that gets knocked back each time. Any ideas? I'm stumped... |
| 03-22-2008, 04:05 AM | #2 |
Your thread is crashing. JASS:set dmgcnt = dmgcnt + dmg |
| 03-22-2008, 04:07 AM | #3 |
A couple of things that could be changed: JASS:private function filter takes nothing returns boolean return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) and (IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) == false) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) > 0. endfunction JASS:private function filter takes nothing returns boolean return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) endfunction The unit is not getting healed because you declare the variable "dmgcnt" but you don't define it, so it is null. Meaning when you get to this line: JASS:debug call BJDebugMsg(R2S(dmgcnt)) set dmgcnt = dmgcnt * (I2R(lvl) * .05) debug call BJDebugMsg(R2S(dmgcnt)) call SetUnitState(u,UNIT_STATE_LIFE,(GetUnitState(u,UNIT_STATE_LIFE) + dmgcnt)) Also, if you are healing units, it's faster to use the commands "GetWidgetLife()" and "SetWidgetLife()". The healing special effect might not show because some effects don't show if you destroy them immediately while others do. I do not know why the knockback isn't working, but put in a debug message that says the name of "m" on each loop. That should shed some light on it. Next time please explain what you want the spell to do before saying what is wrong with it. It helps us help you. Also sorry if my explanations are haphazard, but your questions were. |
| 03-22-2008, 04:14 AM | #4 |
@Castlemaster: Good point... It helps when you proofread your posts... sorry about that. I had no idea you had to set a real to some value before you could do anything with it. So changing the declaration to local real dmgcnt = 0. should fix it? I don't want intercept to attempt to damage and knockback structures or units, so I added those lines. What good would come of leaving them out? I love optimizing. Any other tips? :) |
| 03-22-2008, 04:17 AM | #5 | |
Quote:
|
| 03-22-2008, 04:28 AM | #6 |
And, upon testing, it works beautifully. Thanks! I was really worried that I broke something there... |
