wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-29-2009, 08:46 AM   #1
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default Need help finding bug with UnitProperties

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

Collapse 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
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition

Last edited by Flame_Phoenix : 04-29-2009 at 08:48 AM.
Flame_Phoenix is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-29-2009, 09:56 AM   #2
Mr_Saturn
User
 
Join Date: Nov 2003
Posts: 27

Mr_Saturn has little to show at this moment (5)

Default

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.
Mr_Saturn is offline   Reply With Quote
Old 04-29-2009, 11:07 AM   #3
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

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
Bobo_The_Kodo is offline   Reply With Quote
Old 04-29-2009, 12:03 PM   #4
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
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.
Me does not compute .. error xD
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:
CreateUnitProperties shouldn't be used in the spell code itself, but whenever a unit enters the map.
Mmmm, I see, but the bug happens with 2 different units. The bonuses of the first unit stack with the bonuses of the second unit (having in mind they are different units, this should happen right?).
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition

Last edited by Flame_Phoenix : 04-29-2009 at 12:04 PM.
Flame_Phoenix is offline   Reply With Quote
Old 04-29-2009, 01:09 PM   #5
Viikuna-
User
 
Viikuna-'s Avatar
 
Join Date: Feb 2009
Posts: 203

Viikuna- will become famous soon enough (44)Viikuna- will become famous soon enough (44)

Default

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..
__________________
No Marlo, no game.
Viikuna- is offline   Reply With Quote
Old 04-29-2009, 01:34 PM   #6
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
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..
Why useless ?

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.
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Old 04-30-2009, 09:48 PM   #7
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

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.
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Old 04-30-2009, 09:54 PM   #8
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

UnitProperties works fine ...

If you are having problems with it, it's your fault
Bobo_The_Kodo is offline   Reply With Quote
Old 05-01-2009, 02:06 AM
Litany
This message has been deleted by Litany.
Old 05-01-2009, 07:48 AM   #9
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
If you are having problems with it, it's your fault
Then please tell me what I am doing wrong... it seems I did everything as I should and yet it works sometimes, and sometimes it doesn't ... maybe a conflict with other system? doubt it ... but it is a possibility.
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:
Nah. Unit Properties is bugged to hell. So is ObjectMerger. So is ABuff. Flame_Penis is a genius, it's just that the rest of us have no idea what the hell we're doing.
Sure, do you know what else is a bug? Your messed up brain.
Scram it.
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition

Last edited by Flame_Phoenix : 05-01-2009 at 09:15 AM.
Flame_Phoenix is offline   Reply With Quote
Old 05-01-2009, 09:34 AM   #10
Mr_Saturn
User
 
Join Date: Nov 2003
Posts: 27

Mr_Saturn has little to show at this moment (5)

Default

Take five minutes to create a new map with just ABuff, UnitProperties, and your script. Then try to reproduce your bug.
Mr_Saturn is offline   Reply With Quote
Old 05-01-2009, 09:38 AM   #11
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
Take five minutes to create a new map with just ABuff, UnitProperties, and your script. Then try to reproduce your bug.
But that way I won't find out the source of the problem in my map =(
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Old 05-01-2009, 09:54 AM   #12
Mr_Saturn
User
 
Join Date: Nov 2003
Posts: 27

Mr_Saturn has little to show at this moment (5)

Default

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.
Mr_Saturn is offline   Reply With Quote
Old 05-01-2009, 10:51 AM   #13
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

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.
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt

darkwulfv is offline   Reply With Quote
Old 05-01-2009, 12:42 PM   #14
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
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.
++
Quote:
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.
Seems a good idea mmmm however I am not sure if it is worth it because if the bug is on my map (some external force acting on UnitProperties) then it still means I simply can't use it ...

Damn,this thing is delaying my precious 2.0 alpha release ....
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition

Last edited by Flame_Phoenix : 05-01-2009 at 12:42 PM.
Flame_Phoenix is offline   Reply With Quote
Old 05-02-2009, 03:47 AM   #15
Bobo_The_Kodo
oO
 
Bobo_The_Kodo's Avatar
 
Join Date: Jul 2008
Posts: 580

Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)Bobo_The_Kodo has a spectacular aura about (109)

Default

If you want me to fix it then pm me map :)
Bobo_The_Kodo is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 09:55 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2018, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services