• 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.

[Solved] Critical hit skill problem

Status
Not open for further replies.
Level 6
Joined
Oct 1, 2012
Messages
166
Heloes Hive Workshop!

Due to Critical Hit skill's flaws I'm trying to make a triggered skill of this sort. I do it by making a leveled skill based on Critical Strike, which, at lvl 1, does nothing, but at lvl 2 it has 100% chance to critically hit. I encountered a weird problem. It is, the trigger does set the level to 2 when the counter reaches given value (determinated hero's chance to critically hit), but it wouldn't then swap to lvl 1 back.

Here's the code:

variables:
krytyk is hero's chance to hit (1-400) and krytyk_licznik is the counter counting randomly from 1 to 400.
The max chance to hit is 25%, hence the if-then-else down there
JASS:
function Trig_Krytyk_cios_Conditions takes nothing returns boolean
    return GetOwningPlayer(GetAttacker()) != Player(11)
endfunction

function krytol_bach takes nothing returns nothing
    local integer nr = GetConvertedPlayerId(GetOwningPlayer(GetEventDamageSource()))
    local unit bo = GetEventDamageSource()
    local integer kr = udg_krytyk[nr]
    local integer licznik = udg_krytyk_licznik[nr]
    if (kr > 100) then
     set kr = 100
    endif
    if (kr <= licznik) then
     call SetUnitAbilityLevel(bo, 'A000', 2)
    else
     call SetUnitAbilityLevel(bo, 'A000', 1)
    endif
    set bo = null
endfunction

function Trig_Krytyk_cios_Actions takes nothing returns nothing
    local unit cel = GetTriggerUnit()
    local trigger krytol = CreateTrigger()
    call DisplayTextToForce(GetPlayersAll(), I2S(udg_krytyk_licznik[1]))
    call TriggerRegisterUnitEvent(krytol, cel, EVENT_UNIT_DAMAGED)
    call TriggerAddAction(krytol, function krytol_bach)
    call TriggerSleepAction(1)
    call DestroyTrigger(krytol)
    set cel = null
    set krytol = null
endfunction

//===========================================================================
function InitTrig_Krytyk_cios takes nothing returns nothing
    set gg_trg_Krytyk_cios = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Krytyk_cios, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Krytyk_cios, Condition( function Trig_Krytyk_cios_Conditions ) )
    call TriggerAddAction( gg_trg_Krytyk_cios, function Trig_Krytyk_cios_Actions )
endfunction

Any ideas?
 
Level 6
Joined
Oct 1, 2012
Messages
166
You seem not to understand. It is an RPG map with critical hit chance that can be 3.75%, 15.25%, up to 25%.
But that's not the case. Even with your weird idea it won't work. It's not for the numbers, the trigger doesn't change the skill lvl.
 
Level 6
Joined
Oct 1, 2012
Messages
166
I said it has 2 lvls - first does nothing and second has 100% chance to critically hit. The Critical Strike is buggy, it doesn't work well with percents which do not divide by 5, so I decided to trigger it.
 
Level 6
Joined
Oct 1, 2012
Messages
166
The skill is triggered. The variables determine the critical hit chance. When the counter variable reaches value which is lower than the critical chance value, then the skill is set to lvl 2, which will make the hit a critical hit. That's all.

I'd be glad to talk to somebody who can use english language.
 
Last edited by a moderator:
and again ill say it ur problem is w the variables
udg_krytyk[nr]
udg_krytyk_licznik[nr]
you do not show were they r used. or how they r used so how can anyone help w the integer problem u have when u dont show the integer values. also my first and only language is english. no reason to be rude. u dont explain anything easy and ur not showing the full trigger
 
Level 6
Joined
Oct 1, 2012
Messages
166
As I said, udg_krytyk[nr] is a value between 1-400 and so is udg_krytyk_licznik[nr]. Only difference is that the former is fixed for given hero (fixed at the time, it is dependant on stats, skills and items) and the later changes every 0.1 sec. When the later reaches value equal to or lower than the former, the trigger changes the Critical Strike skill's lvl to 2 (which is a 100% chance to deal double damage). When the value of udg_krytyk_licznik[nr] is higher than the value of udg_krytyk[nr] the skill's lvl is supposed to get back to lvl 1 (0% chance to crit, a dummy lvl, so to speak). This all is done due to the buggy-ness of the Critical Strike skill, which, as I read on this forum, tends to round any % chance value to a number divisable to 5. So, if I had regular, let's sat, 100-lvls skill, the 22.5% chance would round up to 25%, which I don't want.
The 'nr' integer is given player's number.

Is it clear enough?
 
ok thts a lot better. ur problem would have to be that the value isnt changing the way u want. by that i mean the one that changes every .1s isnt being changed or being changed 2 fast. my earlier suggestion was to make a crit strike skill from the ability channel which i thought u were doing. u should put in debug messages to check the integer value to see what it gets set to. if it does hit the numbers u want then check to see were it stops firing in this trigger and that will narrow down the problem.
also u can try this
JASS:
     call SetUnitAbilityLevel(bo, 'A000', GetUnitAbilityLevel( bo, 'A000') + 1)
    else
     call SetUnitAbilityLevel(bo, 'A000', GetUnitAbilityLevel( bo, 'A000') - 1)
 
Level 6
Joined
Oct 1, 2012
Messages
166
local integer nr = GetConvertedPlayerId(GetOwningPlayer(GetEventDamageSource()))
to
local integer nr = GetPlayerId(GetOwningPlayer(GetEventDamageSource()))

I think the main reason here is that you are using GetAttacker().GetAttacker only works for attack events,not damage events.

The 'GetAttacker()' is only for the first event which records the attack and creates damage trigger.
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
JASS:
    ...
    call TriggerRegisterUnitEvent(krytol, cel, EVENT_UNIT_DAMAGED)
    call TriggerAddAction(krytol, function krytol_bach)
    call TriggerSleepAction(1)
    call DestroyTrigger(krytol)
    ...

This is very dangerous.

The attack could last longer than one second second (think of projectiles), so you might destroy an unfinished trigger leading to the handle stack corruption bug.

This will also bug if your attacked unit is under the effect of DoT, as the damage event might fire before the physical attack hits the target.
 
Level 6
Joined
Oct 1, 2012
Messages
166
Why, thank you all for help, I nailed it myself.

I made the trigger change hero's Critical Strike lvl in the same trigger which counts, so it doesn't need attack/damage trigger.

Secondly, I saw lamest bug there:

In this line:
JASS:
if (kr <= licznik) then
There should be
JASS:
if (kr >= licznik) then

And that was practically only bug, the rest worked as it should have :D

Still, +rep for useful hints, Ty guys!
 
Btw Witam :'D

Such scripts works best in coupled with damage detection engine since like posted above have said, sleep function may me inacurrate for strike detection.

There is Bribe's GUI friendly one in Spells section (since I dont think you are willing to use any vJass libraries).

JASS:
    call TriggerAddCondition( gg_trg_Krytyk_cios, Condition( function Trig_Krytyk_cios_Conditions ) )
    call TriggerAddAction( gg_trg_Krytyk_cios, function Trig_Krytyk_cios_Actions )
Merge them:

-->>
JASS:
function Trig_Krytyk_cios_Conditions takes nothing returns boolean
    local unit cel
    local trigger krytol
    if GetOwningPlayer(GetAttacker()) != Player(11) then
        set cel = GetTriggerUnit()
        set krytol = CreateTrigger()
        < ... >
    endif
    return false
endfunction

//somewhere at the bottom
call TriggerAddCondition( gg_trg_Krytyk_cios, Condition( function Trig_Krytyk_cios_Conditions ) )
 
Status
Not open for further replies.
Top