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 08-20-2009, 05:17 PM   #1
DeathRing
User
 
Join Date: May 2007
Posts: 37

DeathRing has little to show at this moment (0)

Default Floating Text Damage Problems

For an RPG game I'm working on, I used moyack's damage detection system to create a system that can register critical hits. And it works nicely, except for the floating text, after awhile it starts to disappear. I'm not sure if I'm incorrectly disposing of it or if I'm forgetting to add something to make it disappear. Anyways, could someone possibly take a look at my code and see what's the problem?

Collapse JASS:
scope CriticalHits initializer init 

globals
    private constant real    factor  = 1.5 // multiplier damage factor
    
    
    private constant attacktype AT   = ATTACK_TYPE_HERO // Sets the Attack type for Physical Attacks/Spells
    private constant damagetype DT   = DAMAGE_TYPE_NORMAL // Sets the Damage type for Attacks/Spells
    private constant attacktype MagAT   = ATTACK_TYPE_NORMAL // Sets the Damage Type for Magical Spells
    
    
    private constant real CritReducedPerArmor = .005 //Sets how much Critical Chance is reduced by when the target upgrades Armor
    private constant real NBonusCrit_PerLevDiff = .1 //Sets how the amount of Bonus Critical Hit Chance a Normal Monster recieves b/t level differences
    private constant real BBonusCrit_PerLevDiff = .2 //Sets how the amount of Bonus Critical Hit Chance a Boss Monster recieves b/t level differences
endglobals


private struct data
    unit u
    unit c
    real damage
    boolean crit
    static method create takes unit u, unit c, real damage, boolean crit returns data
        local data d = data.allocate()
        set d.u = u
        set d.c = c
        set d.damage = damage
        set d.crit = crit
        return d
    endmethod
endstruct


private struct text_dat
    texttag t
    static method create takes texttag t returns text_dat
        local text_dat d = text_dat.allocate()
        set d.t = t
        return d
    endmethod
endstruct



private function delete_text takes nothing returns nothing
    local text_dat d = text_dat(GetTimerData(GetExpiredTimer()))
    
    call DestroyTextTag(d.t)
    call d.destroy()
    call ReleaseTimer(GetExpiredTimer())
endfunction


private function critical takes nothing returns nothing
    local data d = data(GetTimerData(GetExpiredTimer()))
    local real r = 0
    local real damage = 0
    local real l = GetWidgetLife(d.u)
    
    
    call d.destroy()
    call ReleaseTimer(GetExpiredTimer())
    
    set damage = d.damage * (factor)
    set damage = damage - d.damage
    
    if d.crit == true then
        call DoNonDetectableDamage(d.c, d.u,damage, true, false, AT, DT, WEAPON_TYPE_WHOKNOWS)
        
        //If the Wizard knows the Fire Ability: Enduring Flames, any critical hit that he does
        //will take 50% of that damage and burn the target for that damage over 8 seconds
        //Example: Wizard crits for 50! The target will take 25 extra damage over 8 seconds
        //Enduring Flames AbilityId is 'A01B'
        
        if GetUnitAbilityLevel(d.c,'A01B')>0 then
            set r = d.damage * (factor)
            set r = r*.5
            set r = r*.125
            call UnitDamageUnitTimed(d.c,1.,r,8.,d.u,MagAT,DT)
            call AddSpecialEffectTargetUnitWithTimer("head",d.u,"Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeDamageTarget.mdl",8)
        endif
    endif
endfunction

private function DoEffect takes nothing returns boolean
    local real d = GetEventDamage()// Damage dealt normally
    local unit u = GetTriggerUnit()// unit that receives the damage
    local real l = GetWidgetLife(u)// unit life
    local unit c = GetEventDamageSource()// unit that deals the damage
    local player p = GetOwningPlayer(c)
    local player pu = GetOwningPlayer(u) 
    local texttag t
    local real chance
    local integer lev_diff
    local timer tm
    local boolean crit
    local string msg

    
    if d<=.405 then
        return false
    endif
    
    
    if GetPlayerController(p)==MAP_CONTROL_USER then
    
        set chance = .05
        //The Warrior Requires Dexterity upgrades to enhance his Critical Chance
        //The Wizard Requires Magic upgrades to enhance his Critical Chance
        //The Thief Requires Dexterity upgrades to enhance his Critical Chance
        if GetUnitTypeId(c)=='H000' then //Warrior
            set chance = chance + (.01*GetPlayerTechCount(p,'R003',true))
        elseif GetUnitTypeId(c)=='H001' then //Wizard
            set chance = chance + (.01*GetPlayerTechCount(p,'R004',true))
        elseif GetUnitTypeId(c)=='E001' then //Thief
            set chance = chance + (.01*GetPlayerTechCount(p,'R003',true))
        endif
        
        
        if UnitHasBuffBJ(c,'B004') then //If Unit has Dark Vigor, increase their critical chance
            set chance = chance + .2
        endif
        
        
        //If a Hero upgraded their armor, their chance to take a Critical Hit
        //from a monster is reduced by .005 per Armor Level.
        //Additionally, if there's a level difference b/t a Hero and a Monster,
        //the monster's Critical Hit Chance will adjust accordingly.
        if IsUnitType(u,UNIT_TYPE_HERO)==true then
            set lev_diff = GetHeroLevel(c) - GetHeroLevel(u)
            
            set chance = chance + (lev_diff*BBonusCrit_PerLevDiff)
            
            set chance = chance - (CritReducedPerArmor*GetPlayerTechCount(pu,'R002',true))
        endif
    elseif GetPlayerController(p)==MAP_CONTROL_COMPUTER then
    
        set chance = .05
        
        //SPECIAL UNITS START
        //Certain monsters have a naturally higher crit chance than others
        //These are the following:
        if GetUnitTypeId(c)=='n006' then //Satyr
            set chance = .2
        elseif GetUnitTypeId(c)=='n00G' then //Forest Wolf
            set chance = .2
        endif
        //SPECIAL UNITS END
        
        
        //If a Hero upgraded their armor, their chance to take a Critical Hit
        //from a monster is reduced by .005 per Armor Level.
        //Additionally, if there's a level difference b/t a Hero and a Monster,
        //the monster's Critical Hit Chance will adjust accordingly.
        if IsUnitType(u,UNIT_TYPE_HERO)==true then
            set lev_diff = GetUnitLevel(c) - GetHeroLevel(u)
            
            set chance = chance + (lev_diff*NBonusCrit_PerLevDiff)
            
            set chance = chance - (CritReducedPerArmor*GetPlayerTechCount(pu,'R002',true))
        endif
    endif
    
    
    if GetRandomReal(0,1) < chance then
        set crit = true
        set tm = NewTimer()
        call SetTimerData(tm, integer(data.create(u, c, d, crit)))
        call TimerStart(tm, 0., false, function critical)
        set tm = null
        
        //The following creates the TextTag (Floating Text) information for the
        //Critical Strike
        set msg =  GetPlayerColorS(p)+I2S(R2I(d * factor))+"!"
        set t = CreateTextTag()
        call SetTextTagText(t,msg, 0.028)
        call SetTextTagPos(t, GetUnitX(u), GetUnitY(u), 0.00)
        
        call SetTextTagVelocity(t, 0, 0.06)
        call SetTextTagVisibility(t, true)
        call SetTextTagFadepoint(t, 1)
        call SetTextTagLifespan(t, 2)
        call SetTextTagPermanent(t, false)
        
        
        //This will attempt to destroy the texttag used.
        set tm = NewTimer()
        call SetTimerData(tm, integer(text_dat.create(t)))
        call TimerStart(tm, 2.01, false, function delete_text)
        set tm = null
    else
        set crit = false
        set tm = NewTimer()
        call SetTimerData(tm, integer(data.create(u, c, d, crit)))
        call TimerStart(tm, 0., false, function critical)
        set tm = null
        
        
        //The following creates the TextTag (Floating Text) information for the
        //Non-Critical Strike
        set msg =  GetPlayerColorS(p)+I2S(R2I(d))
        set t = CreateTextTag()
        call SetTextTagText(t,msg, 0.020)
        call SetTextTagPos(t, GetUnitX(u), GetUnitY(u), 0.00)
        
        call SetTextTagVelocity(t, 0, 0.06)
        call SetTextTagVisibility(t, true)
        call SetTextTagFadepoint(t, 1)
        call SetTextTagLifespan(t, 2)
        call SetTextTagPermanent(t, false)
        
        
        //This will attempt to destroy the texttag used.
        set tm = NewTimer()
        call SetTimerData(tm, integer(text_dat.create(t)))
        call TimerStart(tm, 2.01, false, function delete_text)
        set tm = null
    endif
    set t = null
    set u = null
    set c = null
    return false
endfunction

private function init takes nothing returns nothing
    call AddDamageCondition(Condition(function DoEffect))
endfunction

endscope

Thanks to any helper in advance!
DeathRing is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 08-20-2009, 07:05 PM   #2
0zyx0
Perfectionist noob
 
0zyx0's Avatar
 
Join Date: Mar 2009
Posts: 255

0zyx0 will become famous soon enough (38)0zyx0 will become famous soon enough (38)

Default

Quote:
Originally Posted by DeathRing
set tm = null
This may cause a bug, but you don't have to set the timer variable to null anyway, if you are using TimerUtils. Try removing those lines and see if the problem stops.
__________________
My new signature - Now easier to understand than ever!
0zyx0 is offline   Reply With Quote
Old 08-20-2009, 07:35 PM   #3
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Remember that texttags allow only a limit of 99 tags showed ingame at the same time.
moyack is offline   Reply With Quote
Old 08-20-2009, 07:48 PM   #4
Karawasa
Element Tower Defense
 
Karawasa's Avatar
 
Join Date: Feb 2006
Posts: 1,094

Submissions (2)

Karawasa has a spectacular aura about (78)Karawasa has a spectacular aura about (78)Karawasa has a spectacular aura about (78)

Approved Map: Tropical TagApproved Map: Element TD

Send a message via AIM to Karawasa Send a message via MSN to Karawasa
Default

Quote:
Originally Posted by moyack
Remember that texttags allow only a limit of 99 tags showed ingame at the same time.

This is your only hope;

http://www.wc3c.net/showthread.php?t=87798

I'm going to be using an updated (for 1.24 and vJASS) version of this in my map, so once that is said and done I can share it here if you want.
__________________

Element Tower Defense - Premier WC3 Custom Game
Karawasa is offline   Reply With Quote
Old 08-20-2009, 08:01 PM   #5
DeathRing
User
 
Join Date: May 2007
Posts: 37

DeathRing has little to show at this moment (0)

Default

Quote:
Originally Posted by moyack
Remember that texttags allow only a limit of 99 tags showed ingame at the same time.

I'm aware of that moyack, but its a Turn-based style of combat, Hero vs. Hero. So the limit shouldn't be a problem because there won't be a lot of texttag creation, and they'll be destroyed quickly.

Quote:
This is your only hope;

http://www.wc3c.net/showthread.php?t=87798

I'm going to be using an updated (for 1.24 and vJASS) version of this in my map, so once that is said and done I can share it here if you want.

Ooo, nice, I would greatly appreciate if you do that.
DeathRing is offline   Reply With Quote
Old 08-20-2009, 09:07 PM   #6
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

I reviewed your code, and in your case, you don't need to destroy the tags because in your case you create them all the time, even if the message is null.

My suggestion: don't destroy the tetxtags, they will be reused and recycled anyways. So you won't need the private struct text_dat and the timer which load that struct.
moyack is offline   Reply With Quote
Old 08-20-2009, 09:30 PM   #7
DeathRing
User
 
Join Date: May 2007
Posts: 37

DeathRing has little to show at this moment (0)

Default

Quote:
Originally Posted by moyack
I reviewed your code, and in your case, you don't need to destroy the tags because in your case you create them all the time, even if the message is null.

My suggestion: don't destroy the tetxtags, they will be reused and recycled anyways. So you won't need the private struct text_dat and the timer which load that struct.

Ahh, alright then, I'll give that a try then. Thanks moyack.
DeathRing is offline   Reply With Quote
Old 08-20-2009, 11:39 PM   #8
Ignitedstar
Moderator
 
Ignitedstar's Avatar


RP Section Moderator
 
Join Date: Jul 2005
Posts: 1,755

Ignitedstar has a spectacular aura about (102)Ignitedstar has a spectacular aura about (102)Ignitedstar has a spectacular aura about (102)Ignitedstar has a spectacular aura about (102)

Send a message via MSN to Ignitedstar Send a message via Yahoo to Ignitedstar
Default

Oooooh. This explains my problem, as well. I was wondering why the texttags in my map began to spontaneously disappear after a certain point in time.

So... We can only have up to 100 texttags created, period? Even if we destroy them? I always thought that we could only have a certain amount of texttags appearing at the same time, but it didn't necessarily mean the amount we could use, total. But... Doesn't SetTextTagLifeSpan (I don't have the world editor right now, I don't remember the exact function name) remove the texttag from the game, though? I must have done something wrong.

Hey- Kurawasa. Do you mind if you can share it with me, too?
__________________
Current Activity: It's a secret, now.
Evaluation: I actually logged in?!?!
"If I speak in the tongues of men and of angels, but have not love,
I am only a resounding gong or a clanging cymbal.
If I have the gift of prophecy and can fathom all mysteries and all knowledge,
and if I have a faith that can move mountains, but have not love, I am nothing."

1 Corinthians 13:1-2

Current Works:
None.

Last edited by Ignitedstar : 08-23-2009 at 10:38 PM.
Ignitedstar is offline   Reply With Quote
Old 08-21-2009, 02:52 AM   #9
Pyrogasm
Lackadaisically Absent.
 
Pyrogasm's Avatar


Respected User
 
Join Date: Sep 2006
Posts: 4,523

Submissions (9)

Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)

Hero Contest - Fourth place

Send a message via ICQ to Pyrogasm Send a message via AIM to Pyrogasm Send a message via MSN to Pyrogasm Send a message via Yahoo to Pyrogasm
Default

99 shown to each player at any given time, so your second statement is correct.
__________________
Quote:
Originally posted by Rising_Dusk
Your spells are mostly ignored because they are not very cool so we aren't very excited to review/approve them, but you are incredibly persistent and won't give us an excuse to graveyard it. That is generally what results in a resource being ignored for a long time.

The Spell Request Thread Done for, unless someone else wants to revive it...
It lasted a damn long time.

Please; Ask for Help Appropriately














Quote:
Originally posted by Kyrbi0
Huh. Almost makes me wish I had a girlfriend, to take advantage of today (wait, no, that's not what I meant... I mean, take advantage of the fact that it is international women's day... gah, never mind).
Quote:
Originally posted by Pyrogasm
Rome may not have been built in a day, but the Romans sure as hell didn't say "look at this great city we built guys!" when they had nothing more than a bit of stone and some cottages.
Pyrogasm is offline   Reply With Quote
Old 08-22-2009, 06:19 PM   #10
DeathRing
User
 
Join Date: May 2007
Posts: 37

DeathRing has little to show at this moment (0)

Default

Sorry, Moyack, but it still didnt fix the problem, I have a lot of floating text still disappearing for some reason. I thought it did work, but it didn't. : /

Last edited by DeathRing : 08-22-2009 at 11:04 PM.
DeathRing is offline   Reply With Quote
Old 06-09-2010, 04:57 AM   #11
Drain Pipe
User
 
Join Date: May 2006
Posts: 129

Drain Pipe has little to show at this moment (3)

Default

Sorry to revive this, but that limit; if you specify visibility so that each player only sees their own generated floating texts, does that mean max 99 texts for each player or what? Also, does destroying a text tag free up space for another to be created?
Drain Pipe is offline   Reply With Quote
Old 06-09-2010, 05:13 AM   #12
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 233

Submissions (1)

Bribe will become famous soon enough (30)Bribe will become famous soon enough (30)

Send a message via AIM to Bribe
Default

First one: they might cause a desync to create them locally (don't quote me on that), second one: yes, destroying them/having them "expire" frees up space for more.
Bribe is offline   Reply With Quote
Old 06-09-2010, 05:24 AM   #13
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

Textags are a special handle (they don't allocate from the general handle stack but via their own private stack) so asyncronous texttags should be fine.
__________________
Ammorth 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 05:33 PM.


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

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