• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Quick problem

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
I have a slight problem. I made a spell based off of raise dead. the trigger creates the unit. My problem is I have this for the filter and I don't think its right.
JASS:
function unitFilter takes nothing returns boolean
    return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) <= 0
endfunction

Am I wrong?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Checking for .405 is pointless and unless you are modifying the life of dead units then checking that their life is 0 will work fine. Since I doubt you are modifying the life of dead units (although don't rule it out) I'd guess that your problem is somewhere else than where you think it is.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Checking for 0.405 is necessary because the unit's life doesn't set to 0 when it dies, it stays at whatever life it was killed at.
You should try testing these things some time instead of just repeating what other people tell you. It would stop these bullshit myths from propagating.

Only use for .405 is checking whether a unit will be killed by damage that has not yet been dealt.
 
Level 9
Joined
Jun 7, 2008
Messages
440
I see what your saying however. I am positive that its the unit (dead) filter. I removed it by placing null where the filter was supposed to go. The units were created perfectly. This brings me to my next question. How do I create a check for dead units?
 
I see what your saying however. I am positive that its the unit (dead) filter. I removed it by placing null where the filter was supposed to go. The units were created perfectly. This brings me to my next question. How do I create a check for dead units?

Change your function to this and see what it spits out:
JASS:
function unitFilter takes nothing returns boolean
    local real r = GetWidgetLife(GetFilterUnit())
    if GetFilterUnit()==null then
        call BJDebugMsg("Filtered unit is null!")
    else
        call BJDebugMsg(GetUnitName(GetFilterUnit())+" : "+R2S(r))
    endif
    return r < .405 // or <= 0 or whatever you want
endfunction

Hopefully that will work to sort out the problems. It should work.
 
Level 9
Joined
Jun 7, 2008
Messages
440
Im trying to create two heros instead of two basic units. And modify their hp/dmg accordingly. In order to do that, I want to pick all dead/decaying units in the spell area and create 2 heros from a random corpse. I can do it in GUI. It seems the Jass is just giving me a headache.
 
Level 13
Joined
May 11, 2008
Messages
1,198
what if you add a units dies event in which you increase an integer. then make your own unit removal for each dead unit...so before you remove the unit, you also subtract from the integer. but you may need to subtract from the integer when other abilities that use corpses go off, too.
 
Level 9
Joined
Jun 7, 2008
Messages
440
Alright ya.
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Raise Dead
  • Actions
    • Set Cast_Unit = (Casting unit)
    • Set Temp_Loc = (Position of Cast_Unit)
    • Set Temp_Group = (Units within 300.00 of Temp_Loc matching (((Matching unit) is dead) Equal to True))
    • Set Temp_Integer = ((Intelligence of Temp_Unit (Include bonuses)) / 40)
    • For each (Integer A) from 1 to 2, do (Actions)
      • Loop - Actions
        • Set Raise_Dead_Loc = (Position of (Random unit from Temp_Group))
        • Unit - Create 1 Vampire for (Owner of Cast_Unit) at Raise_Dead_Loc facing (Facing of Temp_Unit) degrees
        • Set Temp_Unit = (Last created unit)
        • Unit - Add a (Random real number between 1.00 and 30.00) second Generic expiration timer to Temp_Unit
        • Hero - Set Temp_Unit Hero-level to Temp_Integer, Hide level-up graphics
        • Custom script: call RemoveLocation(udg_Raise_Dead_Loc)
    • Custom script: call RemoveLocation(udg_Temp_Loc)
This is what I have.
 
This is how it would look like in JASS:
JASS:
scope RaiseDead initializer Init
    globals
        private constant integer RAISE_DEAD = 'A000' //rawcode of your raise dead ability
        private constant integer VAMPIRE    = 'H000' //rawcode of the vampire
        private group   g = CreateGroup()
        private unit    cast
    endglobals
    
    private function IsDeadFilter takes nothing returns boolean
        return GetWidgetLife(GetFilterUnit())<=0.405 //check if they are dead
    endfunction
    
    private function onCast takes nothing returns boolean
        local unit fog
        local unit dum 
        local integer level
        local integer i = 0
        if GetSpellAbilityId()==RAISE_DEAD then //check if it is the raise dead spell
            set level = GetHeroInt(GetTriggerUnit(),true)/40 //this will be the level of the unit created
            call GroupEnumUnitsInRange(g,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),300,Condition(function IsDeadFilter))
            loop
                exitwhen i == 2 //we only need two units
                set fog = FirstOfGroup(g)
                if fog != null then
                    set dum = CreateUnit(GetTriggerPlayer(),VAMPIRE,GetUnitX(fog),GetUnitY(fog),GetUnitFacing(fog)) //create the vampire
                    call UnitApplyTimedLife(dum,'BTLF',GetRandomReal(1,30)) //random lifetime between 1 and 30
                    call SetHeroLevel(dum,level,false)
                    call ShowUnit(fog,false) //remove the old corpse
                    call GroupRemoveUnit(g,fog)
                endif
                set i = i + 1
            endloop
            set fog  = null
            set dum  = null
        endif
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger() 
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t,Condition(function onCast))
    endfunction
endscope

I tested it and it seems to work fine. All you need to modify are the rawcodes. :)

Also, I used a FirstOfGroup() loop because I was lazy. Really, for two units, there should be hardly any speed difference.
 
Status
Not open for further replies.
Top