Ok im making a map with a total overhaul of the warcraft 3 attack and damage systems that enables hit/miss and criticals based on stats.
the thing is that i have four codes for attacking:
hero on hero
hero on unit
unit on hero
unit on unit
the reason i did this way is because doing everything in one could make the trigger giant and hard to mix... (i tried but all i got was more errors.)
so i started on GUI then passed to custom text and started messing with it,
using locals and reducing size ( specially the ''if'' stuff)
the thing is that, it was working before but now it isnt.
Thanks in advance.
PS: in kinda new to jass, but now that im learning C jass just seems more... beautifull...(and clean and better to do stuff... overal EXCELENT)
the thing is that i have four codes for attacking:
hero on hero
hero on unit
unit on hero
unit on unit
the reason i did this way is because doing everything in one could make the trigger giant and hard to mix... (i tried but all i got was more errors.)
so i started on GUI then passed to custom text and started messing with it,
using locals and reducing size ( specially the ''if'' stuff)
the thing is that, it was working before but now it isnt.
JASS:
function Trig_Hero_Damage_Hero_Func004C takes nothing returns boolean
if ( not ( IsUnitType(GetAttacker(), UNIT_TYPE_HERO) == true ) ) then
return false
endif
if ( not ( IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_HERO) == true ) ) then
return false
endif
return true
endfunction
function Trig_Hero_Damage_Hero_Conditions takes nothing returns boolean
if ( not Trig_Hero_Damage_Hero_Func004C() ) then
return false
endif
return true
endfunction
// End Conditions (i dont know how to reduce this part...
function Trig_Hero_Damage_Hero_Actions takes nothing returns nothing
local unit a = GetAttacker() // Gets units and creates locals
local unit b = GetAttackedUnitBJ()
local location loc = GetUnitLoc(a)
local real h
local real c
local real d
local real def
// Heroes Type (detects heroes to deal damage based on int/str/agi
if ( GetUnitTypeId(a) == 'U002' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, a, true)) * 1.40 )
else
endif
if ( GetUnitTypeId(a) == 'Ulic' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, a, true)) * 1.40 )
else
endif
if ( GetUnitTypeId(a) == 'Hamg' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, a, true)) * 1.40 )
else
endif
if ( GetUnitTypeId(a) == 'Obla' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, a, true)) * 1.40 )
else
endif
if ( GetUnitTypeId(a) == 'O001' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, a, true)) * 1.40 )
else
endif
if ( GetUnitTypeId(a) == 'H003' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_STR, a, true)) * 1.40 )
else
endif
if ( GetUnitTypeId(a) == 'Hpal' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_STR, a, true)) * 1.40 )
else
endif
if ( GetUnitTypeId(a) == 'H000' ) then
set d = ( I2R(GetHeroStatBJ(bj_HEROSTAT_STR, a, true)) * 1.40 )
else
endif
// End Heroes
set h = I2R(( GetHeroStatBJ(bj_HEROSTAT_AGI, a, true) + GetHeroLevel(a) )) //sets hit variable
set def = I2R(( ( GetHeroStatBJ(bj_HEROSTAT_AGI, b, true) + GetHeroLevel(b) ) / 2 )) //sets enemy hero deffense
set c = ( I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, a, true)) / 10.00 ) //sets critical hit chance
if ( ( h / ( h + def ) ) >= GetRandomReal(0, 1) ) then //checks hit against def
if ( ( c / 100.00 ) < GetRandomReal(0, 1) ) then //checks critical
set d = ( GetRandomReal(0.85, 1.15) * d ) //randomizes damage
call TriggerSleepAction( 0.35 ) //wait between start of animation and character hits enemy
if ( loc == GetUnitLoc(a) ) then // checks if attacker is at same location as it was when started animation to avoid an exploit
call UnitDamageTargetBJ( a, b, d, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL ) //deals the damage
call CreateTextTagUnitBJ( I2S(R2I(d)), b, 0, 9.00, 100.00, 100, 100, 0 ) //creates floating text
call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 64, 90 ) //sets floating text velocity
else
endif
else
set d = ( 2.00 * d ) // doubles damage for critical
set d = ( GetRandomReal(0.85, 1.15) * d ) // randomizes critical
call TriggerSleepAction( 0.35 ) //from here till the end is almost the same as above
if ( loc == GetUnitLoc(a) ) then
call UnitDamageTargetBJ( a, b, d, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL )
call CreateTextTagUnitBJ( I2S(R2I(d)), b, 0, 12.00, 100.00, 100, 100, 0 )
call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 32.00, 90 )
else
endif
endif
else
call TriggerSleepAction( 0.35 )
call CreateTextTagUnitBJ( "TRIGSTR_099", b, 0, 9.00, 100.00, 100, 100, 0 )
call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 64, 90 )
endif
call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 0.50 )
call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 0.30 )
endfunction
//===========================================================================
function InitTrig_Hero_Damage_Hero takes nothing returns nothing
set gg_trg_Hero_Damage_Hero = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Damage_Hero, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_Hero_Damage_Hero, Condition( function Trig_Hero_Damage_Hero_Conditions ) )
call TriggerAddAction( gg_trg_Hero_Damage_Hero, function Trig_Hero_Damage_Hero_Actions )
endfunction
Thanks in advance.
PS: in kinda new to jass, but now that im learning C jass just seems more... beautifull...(and clean and better to do stuff... overal EXCELENT)