-Kill Command

Carl-Fredrik

New Member
Reaction score
51
Picking Every Unit Matching

Hi everyone!
I'm learning Jass/vJass...

So I'm about to make a trigger that kills the player's Hero when he types "-kill" in my map.

So I made the event... then I converted the GUI Unit Group Actions...

It looks like this:

JASS:
function Trig_Untitled_Trigger_002_Func001001002001 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002001 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002002 takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == GetTriggerPlayer() )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Untitled_Trigger_002_Func001001002002001(), Trig_Untitled_Trigger_002_Func001001002002002() )
endfunction

function Trig_Untitled_Trigger_002_Func001001002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Untitled_Trigger_002_Func001001002001(), Trig_Untitled_Trigger_002_Func001001002002() )
endfunction

function Trig_Untitled_Trigger_002_Func001A takes nothing returns nothing
endfunction

function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Untitled_Trigger_002_Func001001002)), function Trig_Untitled_Trigger_002_Func001A )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_002_Actions )
endfunction



My first thought was (of course): What a mess!?
So.. do I really need all those functions to check if the unit picked is: Hero, Alive, Under the Player's Control?

I was wondering if there's a better way... thanks in advance! :)

// Carl-Fredrik
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
This blob of code:
JASS:
function Trig_Untitled_Trigger_002_Func001001002001 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002001 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002002 takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == GetTriggerPlayer() )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Untitled_Trigger_002_Func001001002002001(), Trig_Untitled_Trigger_002_Func001001002002002() )
endfunction

function Trig_Untitled_Trigger_002_Func001001002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Untitled_Trigger_002_Func001001002001(), Trig_Untitled_Trigger_002_Func001001002002() )
endfunction


can be rewritten as

JASS:
function Trig_Untitled_Trigger_002_Func001001002 takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true and IsUnitAliveBJ(GetFilterUnit()) == true and GetOwningPlayer(GetFilterUnit()) == GetTriggerPlayer()
endfunction


But please do rename the function names if you ever plan on using it :D!

Edit: It's not fully optimised yet but this should give you the main idea ;).
 

Carl-Fredrik

New Member
Reaction score
51
This blob of code:
JASS:
function Trig_Untitled_Trigger_002_Func001001002001 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002001 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002002 takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == GetTriggerPlayer() )
endfunction

function Trig_Untitled_Trigger_002_Func001001002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Untitled_Trigger_002_Func001001002002001(), Trig_Untitled_Trigger_002_Func001001002002002() )
endfunction

function Trig_Untitled_Trigger_002_Func001001002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Untitled_Trigger_002_Func001001002001(), Trig_Untitled_Trigger_002_Func001001002002() )
endfunction


can be rewritten as

JASS:
function Trig_Untitled_Trigger_002_Func001001002 takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true and IsUnitAliveBJ(GetFilterUnit()) == true and GetOwningPlayer(GetFilterUnit()) == GetTriggerPlayer()
endfunction


But please do rename the function names if you ever plan on using it :D!

Edit: It's not fully optimised yet but this should give you the main idea ;).

Thanks. That was what I needed ;)
And I will change the functions names :p
+Rep
 

Carl-Fredrik

New Member
Reaction score
51
Ok... so I made this command that kills your own hero when used:

JASS:
scope KillCommand initializer InitKill

globals
    private group KILLGROUP = CreateGroup()
endglobals

private function TypeComparison takes nothing returns boolean
    local unit u = GetFilterUnit()
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true and IsUnitAliveBJ(u) == true and GetOwningPlayer(u) == GetTriggerPlayer()
endfunction

private function KillCommandActions takes nothing returns nothing
    call UnitDamageTargetBJ(GetEnumUnit(), GetEnumUnit(), 100000000.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
    call DestroyGroup(KILLGROUP)
    set KILLGROUP = null
endfunction

private function Actions takes nothing returns nothing
    call GroupEnumUnitsInRect(KILLGROUP, GetPlayableMapRect(), Condition (function TypeComparison))
    call ForGroup(KILLGROUP, function KillCommandActions)
endfunction
    
private function InitKill takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, Player(0), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(1), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(2), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(3), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(4), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(5), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(6), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(7), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(8), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(9), "-kill", true)
    call TriggerAddAction(t, function Actions)
endfunction
endscope


So, this works once, but when the hero has revived it doesn't work anymore :O

Any idea why? :/
I revive the hero through a GUI trigger if you'd be wondering.
And if something can be optimized in the script, tell me, I'm learning :)

Thanks in advance!!
// Carl-Fredrik
 

Exide

I am amazingly focused right now!
Reaction score
448
Probably beacuse of this:

JASS:

    call DestroyGroup(KILLGROUP)
    set KILLGROUP = null


Dunno why you're using vJASS (or even JASS) for this trigger, though. :p
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
JASS:
scope KillCommand initializer InitKill

globals
    private group KILLGROUP = CreateGroup()
endglobals

private function TypeComparison takes nothing returns boolean
    local unit u = GetFilterUnit()
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true and IsUnitAliveBJ(u) == true and GetOwningPlayer(u) == GetTriggerPlayer()
endfunction

private function KillCommandActions takes nothing returns nothing
    call UnitDamageTargetBJ(GetEnumUnit(), GetEnumUnit(), 100000000.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
    // You can also use call KillUnit(GetEnumUnit())
endfunction

private function Actions takes nothing returns nothing
    call GroupEnumUnitsInRect(KILLGROUP, GetPlayableMapRect(), Condition (function TypeComparison))
    call ForGroup(KILLGROUP, function KillCommandActions)
    call GroupClear(KILLGROUP)
    // Removed the group destroy/nulling since its a global group that will be reused and just cleared it from all units so it can be reused without picking wierd units or bugging up.
endfunction
    
private function InitKill takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, Player(0), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(1), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(2), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(3), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(4), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(5), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(6), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(7), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(8), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(9), "-kill", true)
    call TriggerAddAction(t, function Actions)
endfunction
endscope

fixed.
 

Carl-Fredrik

New Member
Reaction score
51
JASS:
scope KillCommand initializer InitKill

globals
    private group KILLGROUP = CreateGroup()
endglobals

private function TypeComparison takes nothing returns boolean
    local unit u = GetFilterUnit()
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true and IsUnitAliveBJ(u) == true and GetOwningPlayer(u) == GetTriggerPlayer()
endfunction

private function KillCommandActions takes nothing returns nothing
    call UnitDamageTargetBJ(GetEnumUnit(), GetEnumUnit(), 100000000.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
    // You can also use call KillUnit(GetEnumUnit())
endfunction

private function Actions takes nothing returns nothing
    call GroupEnumUnitsInRect(KILLGROUP, GetPlayableMapRect(), Condition (function TypeComparison))
    call ForGroup(KILLGROUP, function KillCommandActions)
    call GroupClear(KILLGROUP)
    // Removed the group destroy/nulling since its a global group that will be reused and just cleared it from all units so it can be reused without picking wierd units or bugging up.
endfunction
    
private function InitKill takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, Player(0), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(1), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(2), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(3), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(4), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(5), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(6), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(7), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(8), "-kill", true)
    call TriggerRegisterPlayerChatEvent(t, Player(9), "-kill", true)
    call TriggerAddAction(t, function Actions)
endfunction
endscope

fixed.

Thanks :)

I use JASS for this trigger because I want to learn and if I do small stuff like this then I'll slowly start using JASS more than GUI I'm hoping ^^

Can't give anymore rep within the next 24 hours... o_O
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top