• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Help optomizing Damage to Life skill

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
Hi, T4co Bell created a skill for me to damage an enemy and steal the life of the damage unit. He then told me how it worked and I decided to convert it to JASS and try it out. It works, but how can I make it better? And also make it MUI or at least MPI.

I'm getting better at vJASS as well, thanks to the tutorials and nudge in the right direction from users :) Thanks. But I didn't really know how to apply the vJASS when a lot of the code is calling Triggers.

Also neither the texttags nor graphics will show.

Anyways, here is the code:

JASS:
scope Rend initializer Init

globals
    private unit array LearningHero
    private unit array AcquiredUnit
    private constant integer SPELLID        = 'rend'
endglobals

private function ThirdActions takes nothing returns nothing
 local integer i = GetPlayerId(GetOwningPlayer(GetEventDamageSource()))
 local texttag tag = CreateTextTag()
    call SetTextTagText(tag, R2S(GetEventDamage()), 0)
    call SetTextTagPosUnit(tag, AcquiredUnit[i], 0)
    call SetTextTagColor(tag, 255,0,0,255)
    call SetTextTagVelocity(tag, 64, 90)
    call SetTextTagLifespan(tag, 2.0)
    call SetWidgetLife(LearningHero[i], GetWidgetLife(LearningHero[i]) + (GetEventDamage() * (0.25+0.25*GetUnitAbilityLevel(LearningHero[i], SPELLID))) )
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", LearningHero[i], "origin"))
endfunction

private function ThirdConditions takes nothing returns boolean
 local integer i = GetRandomInt(1,10)
 local integer p = GetPlayerId(GetOwningPlayer(GetEventDamageSource()))
    return GetEventDamageSource() == LearningHero// and i == 10
endfunction

private function SecondActions takes nothing returns nothing
 local trigger t = CreateTrigger()
 set AcquiredUnit[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))] = GetEventTargetUnit()
    call TriggerRegisterUnitEvent( t, AcquiredUnit[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))], EVENT_UNIT_DAMAGED )
    call TriggerAddCondition(t, function ThirdConditions)
    call TriggerAddAction(t, function ThirdActions)
endfunction
    
private function Trig_Meow_1_Conditions takes nothing returns boolean
    return GetLearnedSkill() == SPELLID
endfunction

private function FirstActions takes nothing returns nothing
 local trigger t
 local unit L = GetLearningUnit()
    call DisableTrigger(GetTriggeringTrigger())
 set LearningHero[GetPlayerId(GetOwningPlayer(L))] = L
 set t = CreateTrigger()
    call TriggerRegisterUnitEvent( t, LearningHero[GetPlayerId(GetOwningPlayer(L))], EVENT_UNIT_ACQUIRED_TARGET )
    call TriggerAddAction(t, function SecondActions)
 set L = null
endfunction

//===========================================================================

private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_HERO_SKILL )
    call TriggerAddCondition( t, Condition( function Trig_Meow_1_Conditions ) )
    call TriggerAddAction( t, function FirstActions )
endfunction

private function InitTrig_Rend takes nothing returns nothing
endfunction

endscope
 
Level 4
Joined
Jan 27, 2010
Messages
133
Why not keep it enabled so it is MUI or destroy it if it does not need to be.

Because only keeping the trigger enabled w/o adding a check for level will cause trouble when the hero levels the skill above level 1 ?

[jass="How it should be done"]private function FirstActions takes nothing returns nothing
local trigger t
local unit L = GetLearningUnit()

// Actually, I'm not sure if this event fires before or after you learn the skill...
// If it's before, you'll need to test for 0 instead of 1.
if GetUnitAbilityLevel( L, SPELLID ) == 1 then

set LearningHero[GetPlayerId(GetOwningPlayer(L))] = L
set t = CreateTrigger()
call TriggerRegisterUnitEvent( t, LearningHero[GetPlayerId(GetOwningPlayer(L))], EVENT_UNIT_ACQUIRED_TARGET )
call TriggerAddAction(t, function SecondActions)

endif

set L = null
endfunction[/code]
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
Ahhhh thanks again themerion! =D I've been led in the right direction. I'm surprised I didn't see that error before.

I'll have to test this out in a multiplayer game to be sure it works, as Computer heroes refuse to learn the skill for it.

I still don't know why the special effect and textag won't work though.

Also is there a better way to do this skill? Perhaps an easy solution to fixing the leaks?
 
Status
Not open for further replies.
Top