• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Small Question (Just started to learn Jass)

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Hey readers.

I've got a small question regarding a Jass function.

I've got a trigger that gives a unit a 30% chance to get a critical strike on a hit. (This is made by Rising_Dusk... Very great!:D)
However I want to change one thing.
He posted this system on wc3campaigns, so I'm 100% sure I'm allowed to change it.. However I don't really know how. I'm currently doing my best to learn as much as possible regarding Jass.

Here's the thing I want to change:
Currently it has a 30% chance to crit.
But I want to change this to:
((HeroAgilityofUnit/HeroLevelofUnit)*4,5)+(CritBonus/(HeroLevelofUnit/3)% chance to crit.

The "CritBonus" is an Integer I will increase or decrease using normal GUI. I don't know if it's possible to use GUI integers in Jass functions.

This is a rough formula I might change after a while..
I can make this in GUI.. But I don't know how to create this in Jass.

Is there someone who can tell me how?

Thanks alot!
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
This is what I have. And it's giving an error and I don't know what causes the problem.

JASS:
private function Conditions takes nothing returns boolean
    return GetTriggerDamageType() == DAMAGE_TYPE_ATTACK and GetRandomInt(1, 100) <= ( ( ( GetHeroStatBJ(bj_HEROSTAT_AGI, GetTriggerDamageSource(), true) / GetHeroLevel(GetTriggerDamageSource()) ) * R2I(4.50) ) + ( udg_CritBonus[GetConvertedPlayerId(GetOwningPlayer(GetTriggerDamageSource()))] / ( GetHeroLevel(GetTriggerDamageSource()) / 3 ) ) ) )
endfunction
 
Level 6
Joined
Sep 4, 2007
Messages
157
well for one there is no GetTriggerDamageType(). and for 2 what are you trying to do here.

you want the chances to increase with what

edit: oh i see i i found the system your talking about thats using another function
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
This is the function:

*Note: The DAMAGE_TYPE_ATTACK is used in a global.
Everything in this real Jass function works right. The problem is how can I change the crit chance.

JASS:
scope MeleeCriticalStrike
private function Conditions takes nothing returns boolean
    return GetTriggerDamageType() == DAMAGE_TYPE_ATTACK and GetRandomInt(1,100) <= 30
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerDamageSource()
    local unit t = GetTriggerDamageTarget()
    local integer lvl = 2
    local texttag te = CreateTextTag()
    local real d = GetTriggerDamage()
    
    //Deals +100% damage. (so total 2 times as much damage)
    call UnitDamageTargetEx(u, t, d*(lvl), ATTACK_TYPE_HERO, DAMAGE_TYPE_EXTRA, true)
    call SetTextTagText(te, I2S(R2I(d*(lvl)))+"!", 0.024)
    call SetTextTagPos(te, GetUnitX(u), GetUnitY(u), 0.00)
    call SetTextTagColor(te, 255, 0, 0, 255)
    call SetTextTagVelocity(te, 0, 0.03)
    call SetTextTagVisibility(te, true)
    call SetTextTagFadepoint(te, 1.4)
    call SetTextTagLifespan(te, 2)
    call SetTextTagPermanent(te, false)
    
    set te = null
    set u = null
    set t = null
endfunction

public function InitTrig takes nothing returns nothing
    local trigger trg = CreateTrigger()
    call TriggerAddAction(trg, function Actions)
    call TriggerAddCondition(trg, Condition(function Conditions))
    call TriggerRegisterDamageEvent(trg)
    set trg = null
endfunction
endscope

You can see it is 30% here.

I want to replace the 30% with this formula:
((HeroAgilityofUnit/HeroLevelofUnit)*4,5)+(CritBonus/(HeroLevelofUnit/3))

So if a hero level 10 has 20 Agility and 30 Critbonus he will have:
((20/10*4,5)+(30/(10/3)) = 9+9 = 18 % crit chance.

I think it's pretty complicated afterall.. Because the "CritBonus[?]" is an integer with an array.
The array will be the Playernumber of the owner of the hero that deals damage. (in the map players only have 1 hero)



This is a trigger I could also use to make it a bit easier.

  • Events
    • Time - Every 0.01 seconds of game time
  • Conditions
  • Actions
    • Set TempUnit = (Random unit from (Units in (Playable map area)))
    • Set CritChance[(Player number of (Owner of TempUnit))] = ((((Agility of TempUnit (Include bonuses)) / (Hero level of TempUnit)) x (Integer(4.50))) + (CritBonus[(Player number of (Owner of TempUnit))] / ((Hero level of TempUnit) / 3)))
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Oh.. and one more thing.
I can't use the Custom Value of the units to set the crit chance.
Because I have physical AND magical crit chance.
And I cannot have 2 different Custom Value's on one unit.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Really simple :D
To much ")" in the end, remove one :D

Other from that the last trigger is run to much use like 2 seconds or something.
P.s.
You can use handle variables for that, but a stuct system is recommended with that :p
 
Level 17
Joined
Apr 13, 2008
Messages
1,608
I'm sorry for chiming in but why do you need a triggered critical strike system?
We have a one hundred percent customizable critical strike ability.

It would help if you would post a link to the system so we wouldn't need to search for it.

If you don't know how to do stuff in Jass but you know how to do in GUI then you can always just make it in GUI then convert it to custom text (Jass) from the Trigger Editor's edit menu.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
It's working now.
However I get errors in gameplay.

They look like this:
Divide by zero error in
MeleeCriticalStrike__Conditions()

The trigger I'm using is called MeleeCriticalStrike..
so there's still something wrong.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
If you don't know how to do stuff in Jass but you know how to do in GUI then you can always just make it in GUI then convert it to custom text (Jass) from the Trigger Editor's edit menu.

I did.
That's why it works.
but as i posted above, it gives some errors ingame play.
Not when saving. When I save everything looks fine.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
I'm using this:

http://www.wc3campaigns.net/showthread.php?t=100618

The trigger in it is called "CriticalStrike" or something.

I changed the name to MeleeCriticalStrike because I have a SpellCriticalStrike too.. And I changed the lvl to 2. Because I want every unit to be able to crit. Even if they haven't got the Critical Strike ability.


The reason I don't give every unit a crit chance ability is because it wont work with spells.
 
Level 17
Joined
Apr 13, 2008
Messages
1,608
Okay, I thought so, I just asked.
Well, do you have NewGen Pack? If not you should download and install it.

I don't know why would the condition crash the game with division by zero error. I think the problem is something different, but maybe the more experienced users can solve this.
Anyways, download NewGen Pack from Wc3Campaigns. Just read the documentation first.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Got the NewGen Pack.

However I figured something out.

When a hero's level is < 4,5 (because I used 4,5 in the function) it will give an error AND when a normal unit attacks so the Hero_Level thingy wont work anymore.

That's what gives the errors.

So I have to change it just a littlebit now... Nearly there^^..

Could someone help me with this final step?

This is what I've got now:

JASS:
scope MeleeCriticalStrike
private function Conditions takes nothing returns boolean
    return GetTriggerDamageType() == DAMAGE_TYPE_ATTACK and GetRandomInt(1, 100) <= ((( GetHeroStatBJ(bj_HEROSTAT_AGI, GetTriggerDamageSource(), true) / GetHeroLevel(GetTriggerDamageSource()) ) * R2I(4.50) ) + ( udg_CritBonus[GetConvertedPlayerId(GetOwningPlayer(GetTriggerDamageSource()))] / ( GetHeroLevel(GetTriggerDamageSource()) / 3 )))
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerDamageSource()
    local unit t = GetTriggerDamageTarget()
    local integer lvl = 2
    local texttag te = CreateTextTag()
    local real d = GetTriggerDamage()
    
    //Deals +200% damage
    call UnitDamageTargetEx(u, t, d*(lvl), ATTACK_TYPE_HERO, DAMAGE_TYPE_EXTRA, true)
    call SetTextTagText(te, I2S(R2I(d*(lvl)))+"!", 0.024)
    call SetTextTagPos(te, GetUnitX(u), GetUnitY(u), 0.00)
    call SetTextTagColor(te, 255, 0, 0, 255)
    call SetTextTagVelocity(te, 0, 0.03)
    call SetTextTagVisibility(te, true)
    call SetTextTagFadepoint(te, 1.4)
    call SetTextTagLifespan(te, 2)
    call SetTextTagPermanent(te, false)
    
    set te = null
    set u = null
    set t = null
endfunction

public function InitTrig takes nothing returns nothing
    local trigger trg = CreateTrigger()
    call TriggerAddAction(trg, function Actions)
    call TriggerAddCondition(trg, Condition(function Conditions))
    call TriggerRegisterDamageEvent(trg)
    set trg = null
endfunction
endscope



Could someone add 2 conditions?
1: Integer: "GetTriggerDamageSource" Hero level must be greater then or equal to 5.
2: Boolean: "GetTriggerDamageSource" is a Hero equal to true.


I go try to add them myself meanwhile.
I will post when it worked or not.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Tried everything.

The problem is.

When it calculates the critchance an error will appear if the attacking unit isn't a hero or his hero level is lower then 4.5.. so 1,2,3 or 4.

I need this trigger to FIRST check if it's a hero AND is higher then level 4 and after that calculate the crit chance.

The trigger is still up here. Didn't change anything since last post.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Finnaly!
I did it!

thanks for all the help.

you will get +rep if I have some rep to spend...

JASS:
scope MeleeCriticalStrike
private function Conditions takes nothing returns boolean
    return GetTriggerDamageType() == DAMAGE_TYPE_ATTACK and IsUnitType(GetTriggerDamageSource(), UNIT_TYPE_HERO) == true and GetHeroLevel(GetTriggerDamageSource()) > 4 and GetRandomInt(1, 100) <= ((( GetHeroStatBJ(bj_HEROSTAT_AGI, GetTriggerDamageSource(), true) / GetHeroLevel(GetTriggerDamageSource()) ) * R2I(4.50) ) + ( udg_CritBonus[GetConvertedPlayerId(GetOwningPlayer(GetTriggerDamageSource()))] / ( GetHeroLevel(GetTriggerDamageSource()) / 3 )))
    endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerDamageSource()
    local unit t = GetTriggerDamageTarget()
    local integer lvl = 2
    local texttag te = CreateTextTag()
    local real d = GetTriggerDamage()
    
    //Deals +200% damage
    call UnitDamageTargetEx(u, t, d*(lvl), ATTACK_TYPE_HERO, DAMAGE_TYPE_EXTRA, true)
    call SetTextTagText(te, I2S(R2I(d*(lvl)))+"!", 0.024)
    call SetTextTagPos(te, GetUnitX(u), GetUnitY(u), 0.00)
    call SetTextTagColor(te, 255, 0, 0, 255)
    call SetTextTagVelocity(te, 0, 0.03)
    call SetTextTagVisibility(te, true)
    call SetTextTagFadepoint(te, 1.4)
    call SetTextTagLifespan(te, 2)
    call SetTextTagPermanent(te, false)
    
    set te = null
    set u = null
    set t = null
endfunction

public function InitTrig takes nothing returns nothing
    local trigger trg = CreateTrigger()
    call TriggerAddAction(trg, function Actions)
    call TriggerAddCondition(trg, Condition(function Conditions))
    call TriggerRegisterDamageEvent(trg)
    set trg = null
endfunction
endscope


This is the function now.


I copied this with DAMAGE_TYPE_SPELLS
so heroes have a chance to crit with spells and physical attacks.



Again credits for Rising_Dusk for creating the main part of this trigger.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Another problem.

Now I've got another problem.

I want to add 2 little things to the system.

This is what it does now:

If random integer between 1-100 is smaller then the crit chance of a unit (formula) it will deal 2 times as much damage on an attack of a certain attack type.

I want to change this:

If random integer between 1-100 is smaller then the crit chance of a unit (formula) it will deal 2 times as much damage on an attack of a certain attack type and create a floating text.
IF NOT it will do another if/then/else like this:
If attack type is equal to X (the same as I used above)
then create a floating text (with text equal to damage x 1)


So I add a floating text system inside this system too.


Like this in GUI:

  • Events
  • Conditions
  • Actions
    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Blablablabla... is Random integer smaller then the crit chance of a unit AND the attack type is equal to: Normal
      • Then - Actions
        • Unit - Cause (Triggering unit) to damage (Triggering unit), dealing XXX damage of attack type Normal and damage type Extra
        • Floating Text - Create floating text that reads (String((Integer((Damage taken))))) above (Triggering unit) with Z offset 5.00, using font size 8.50, color (100.00%, 0.00%, 0.00%),(*this is very red*) and 0.00% transparency
        • Floating Text - Set the velocity of (Last created floating text) to 100.00 towards 85.00 degrees
        • Floating Text - Change (Last created floating text): Disable permanence
        • Floating Text - Change the lifespan of (Last created floating text) to 1.40 seconds
        • Floating Text - Change the fading age of (Last created floating text) to 0.65 seconds
      • Else - Actions
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Unit's attack type is equal to Normal (*but he didn't crit*)
          • Then - Actions
            • Floating Text - Create floating text that reads (String((Integer((Damage taken))))) above (Triggering unit) with Z offset 5.00, using font size 8.50, color (50.00%, 5.00%, 5.00%), (This is a normal colour... so withoud a crit) and 0.00% transparency
            • Floating Text - Set the velocity of (Last created floating text) to 100.00 towards 85.00 degrees
            • Floating Text - Change (Last created floating text): Disable permanence
            • Floating Text - Change the lifespan of (Last created floating text) to 1.40 seconds
            • Floating Text - Change the fading age of (Last created floating text) to 0.65 seconds
          • Else - Actions
            • Do nothing


Hope my question is understandable
 
Status
Not open for further replies.
Top