| 04-29-2009, 08:46 AM | #1 |
Hey guys, it all started with one of my spells. At first I thought it was ABuff's fault, but Anitarf was right, it wasn't and my debugg messaged proved he was master of reason(as usual). After that I tried to find the bug with UnitProperties, and tasmirash helped find what I was doing wrong. The code worked, and I was happy .... until I decided to make another spell using UnitProperties as well .... So, this code is exactly the same code tasmirash helped me fix, with one difference: I use UnitModifyDamage instead of UnitModifyArmor ... And guess what, it bugs, it doesn't work . I make no idea what else I have to do. Also Litany is too scared and he simply refuses to help me, so I am forced to come here and ask help to the community of people that have no obligation at helping me (is a shame...) yes I debugged the code with debugg messages and all kind of crap I can remember of ... value data.bonus is correctly transported by ABuff data field, but UnitProperties seems to screw it somewhere ... And is the same problem UnitIndexing (Thx for Bodo_the_Kodo). I can't find a fix for this ... as usual there is little I can give ... I can do nothing but give rep++ and credits ... Please help =S JASS://=========================================================================== //This ability gives the caster bonus damage depending on the number of //allied ChaosOrc unit and Undead unit nearby. It gains 1 damage per each unit //and can get a maximum attack bonus of 7. // //Requires: // - Abuff // - UnitProperties // //@author Flame_Phoenix // //@credits: // - Anitarf, for ABuff // - Litany, for UnitProperties // //@version 1.1 //=========================================================================== scope InnerBurn initializer Init //=========================================================================== //=============================SETUP START=================================== //=========================================================================== globals private constant integer AID = 'A050' private constant integer AURA_ID = 'A04Z' private constant integer BUFF_ID = 'B00A' private constant string EFF = "Abilities\\Spells\\NightElf\\BattleRoar\\RoarCaster.mdl" endglobals private constant function MaxBonus takes integer level returns integer //the maximum amount of attack the caster can receive return 7 endfunction private constant function Radius takes integer level returns real //the AOE of the spell return 300. endfunction private constant function Duration takes integer level returns real //the duration of the spell return 45. endfunction private function CountUnits takes unit caster, unit helper returns boolean //the units that will add the bonus to the caster return IsUnitAlly(helper, GetOwningPlayer(caster)) and (IsUnitType(helper, UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(helper, UNIT_TYPE_MECHANICAL) == false) and (GetWidgetLife(helper) > 0.405) and (caster != helper) and (IsUnitType(helper, UNIT_TYPE_UNDEAD) or (Race[GetPlayerId(GetOwningPlayer(helper))+1] == "Chaos_Orc")) endfunction //=========================================================================== //=============================SETUP END===================================== //=========================================================================== globals private group helpers private boolexpr chooseHelpers private unit tmpCaster public aBuffType id = 0 endglobals private struct aCaster unit caster integer bonus static method create takes unit c returns aCaster local aCaster data = aCaster.allocate() set data.caster = c return data endmethod endstruct //=========================================================================== private function ChooseHelpers takes nothing returns boolean return CountUnits(tmpCaster, GetFilterUnit()) endfunction //=========================================================================== private function Cleanup takes aBuff eventBuff returns nothing local aCaster data = eventBuff.data call UnitModifyDamage(eventBuff.target.u, -data.bonus) call data.destroy() call UnitRemoveAbility(eventBuff.target.u, AURA_ID) //so we don't wait 2 seconds because of the aura call UnitRemoveAbility(eventBuff.target.u, BUFF_ID) endfunction //=========================================================================== private function Create takes aBuff eventBuff returns nothing local aCaster data = eventBuff.data //give the bonus! call BJDebugMsg("bonus ="+I2S(data.bonus)) call UnitModifyDamage(data.caster, data.bonus) //now we add the buff, we always add the buff xD call UnitAddAbility(eventBuff.target.u, AURA_ID) //prevent morphing from removing the ability call UnitMakeAbilityPermanent(eventBuff.target.u, true, AURA_ID) endfunction //=========================================================================== private function Conditions takes nothing returns boolean return GetSpellAbilityId() == AID endfunction //=========================================================================== private function Actions takes nothing returns nothing local aCaster data = aCaster.create(GetTriggerUnit()) local integer level = GetUnitAbilityLevel(data.caster, AID) //create a nice casting effect call DestroyEffect(AddSpecialEffect(EFF, GetUnitX(data.caster), GetUnitY(data.caster))) //here we count the bonus we will add and clear the group set tmpCaster = data.caster call GroupEnumUnitsInRange(helpers, GetUnitX(data.caster), GetUnitY(data.caster), Radius(level), chooseHelpers) //save the number of units and clear the group set data.bonus = CountUnitsInGroup(helpers) call GroupClear(helpers) //if we have more then 0 units, then we add the ability, else we don't if data.bonus > 0 then //at this point it is certain that we will use UnitProperties //so we innitialize it call CreateUnitProperties(data.caster) //we make a quick check for the max level if data.bonus > MaxBonus(level) then set data.bonus = MaxBonus(level) endif //apply the buff to the unit call ABuffApply(id, data.caster, data.caster, Duration(level), level, integer(data)) endif endfunction //=========================================================================== private function Init takes nothing returns nothing local trigger InnerBurnTrg = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ(InnerBurnTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition(InnerBurnTrg, Condition(function Conditions)) call TriggerAddAction(InnerBurnTrg, function Actions) //setting our globals set helpers = CreateGroup() set chooseHelpers = Condition(function ChooseHelpers) set id = aBuffType.create() //setting Abuff set id.eventCreate = ABuffEvent_Create.Create set id.eventCleanup = ABuffEvent_Cleanup.Cleanup //preloading effects call Preload(EFF) endfunction endscope |
| 04-29-2009, 09:56 AM | #2 |
Your script works fine. UnitProperties works fine. ABuff works fine. The problem is coming from somewhere else in your map. Make sure the object data for the damage bonuses is correct. |
| 04-29-2009, 11:07 AM | #3 |
CreateUnitProperties shouldn't be used in the spell code itself, but whenever a unit enters the map. If you cast the spell twice right now, then all the bonuses from the first instance will be stuck on Other than that, what exactly is happening when you test it |
| 04-29-2009, 12:03 PM | #4 | ||
Quote:
I don't get it, if the source of the problem is in my project, why does the other code work fine? Why does the source not affect my other (almost) equal spell? See here: http://www.wc3c.net/showthread.php?t=105634 Quote:
|
| 04-29-2009, 01:09 PM | #5 |
If I remember correctly, CreateUnitProperties checks if unit already has properties created for it, so it should not ruin your code, even if it is pretty useless to call it on spell effect.. |
| 04-29-2009, 01:34 PM | #6 | |
Quote:
Anyway, it is funny, I decided to follow Bob's advice and to make a global unit that hs UnitProperties created for it at the start of the map ... the bug is fixed (somehow) ... This is weird, there is something definitely wrong her, but since it works now I guess I can't complain ... rep++ to all people, as a token of my appreciation. Special rep++ for bob, which will be in credits of the spell. |
| 04-30-2009, 09:48 PM | #7 |
Bah, for some reason this whole thing is highly unstable ... sometimes it works sometimes it doesn't. Now it doesn't work .. I can't code in this conditions, so I am removing UnitProperties once and for all. Thx for all help anyway guys. PS: not double posting several hours passed. |
| 04-30-2009, 09:54 PM | #8 |
UnitProperties works fine ... If you are having problems with it, it's your fault |
| 05-01-2009, 07:48 AM | #9 | ||
Quote:
Because I just don't get it, if the error is 100% from me, then why does the spell work half of the time? Quote:
Scram it. |
| 05-01-2009, 09:34 AM | #10 |
Take five minutes to create a new map with just ABuff, UnitProperties, and your script. Then try to reproduce your bug. |
| 05-01-2009, 09:38 AM | #11 | |
Quote:
|
| 05-01-2009, 09:54 AM | #12 |
But you can confirm the source of the problem is not those systems. Once that's done you can go back to your actual map and print out so many debug messages. Or you could keep messing with the small test map until you get a similar bug. |
| 05-01-2009, 10:51 AM | #13 |
Exactly. You need a control test, and currently you have none. There's way too many variables in your project to use that as a legitimate testing platform for saying that UnitProperties is broken. So make a test map that contains only Abuff, UnitProperties, and your spell. If you test and it still has problems, try to find the exact problem source in your code. |
| 05-01-2009, 12:42 PM | #14 | ||
Quote:
Quote:
Damn,this thing is delaying my precious 2.0 alpha release .... |
| 05-02-2009, 03:47 AM | #15 |
If you want me to fix it then pm me map :) |
