• 🏆 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!

Why i cannot add "unit type mechanical" within this line?

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,123
Hello everyone. I don't have a knowledge about the jass and i have to add this line
JASS:
IsUnitType (u, UNIT_TYPE_MECHANICAL) == false
within this line
JASS:
if ( not (  IsUnitType(u, UNIT_TYPE_STRUCTURE) == false then

I want to check unit type is NOT Structure and Mechanical. Can you help me about that?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
You're close. You just need to close off the parenthesis (or delete them altogether).

Since you have "not" and "false on the same equator, the double negative turns it into a positive check. Therefore, you should just do this:

if not IsUnitType(u, UNIT_TYPE_STRUCTURE) and not IsUnitType(u, UNIT_TYPE_MECHANICAL) then
 
Level 17
Joined
Jun 2, 2009
Messages
1,123
You're close. You just need to close off the parenthesis (or delete them altogether).

Since you have "not" and "false on the same equator, the double negative turns it into a positive check. Therefore, you should just do this:

if not IsUnitType(u, UNIT_TYPE_STRUCTURE) and not IsUnitType(u, UNIT_TYPE_MECHANICAL) then
Thank you for your help. But sadly still error appears.

And here is the full trigger if you want to see

JASS:
function sdfg takes nothing returns boolean
    if not IsUnitType(u, UNIT_TYPE_STRUCTURE) and not IsUnitType(u, UNIT_TYPE_MECHANICAL) then
        return false
    endif
    
    if ( not ( GetUnitAbilityLevelSwapped('A02H', GetAttacker()) > 0 ) ) then
        return false
    endif
    return true
endfunction

function backstab takes nothing returns nothing
call DestroyTrigger(GetTriggeringTrigger())
if((RAbsBJ((GetUnitFacing(GetTriggerUnit())-GetUnitFacing(GetEventDamageSource())))<=105.)) and ( GetUnitAbilityLevelSwapped('A02H', GetEventDamageSource()) > 0 ) then
call UnitDamageTargetBJ( GetEventDamageSource(), GetTriggerUnit(), ( ( 80.00 * I2R(GetUnitAbilityLevelSwapped('A02H', GetEventDamageSource())) ) + 1.00 ), ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL )
call DestroyEffectBJ( AddSpecialEffectTargetUnitBJ("chest",GetTriggerUnit(),"Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl") )
endif

endfunction

function asdf takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
call TriggerAddAction( t,function backstab )
call PolledWait(2.)
call DisableTrigger(t)
call DestroyTrigger(t)
endfunction

//===========================================================================
function InitTrig_Viceclaws takes nothing returns nothing
    set gg_trg_Viceclaws = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Viceclaws, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Viceclaws, Condition( function sdfg ) )
    call TriggerAddAction( gg_trg_Viceclaws, function asdf )
endfunction
 

Attachments

  • test.png
    test.png
    31.6 KB · Views: 10

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
That's hideous and leaks like crazy. Why not just use a backstab attack that someone else already did? Attacked events are easily abused, so I can see why the person who created this wanted to include a damage event, but if you just use Damage Engine then you can avoid the attack event altogether, avoid all the leaks, etc.

I recommend not using JASS if you don't understand the basics. You can easily do this in GUI in combination with Damage Engine.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,509
The error is telling you that the variable "u" doesn't exist. If it did, you'd see the variable being declared like so:
JASS:
local unit u = GetTriggerUnit()
Add that line to the top of your sdfg function and you should be good to go.

Alternatively, you can replace the two instances of "u" with GetTriggerUnit() and the error will go away.
GetTriggerUnit() is the unit that was attacked. In GUI it's the (Triggering unit).

Remember that local variables must be declared at the top of a function before anything else.

Edit: You may also want to adjust the If Then statements to this:
vJASS:
    if ( IsUnitType(u, UNIT_TYPE_STRUCTURE) or IsUnitType(u, UNIT_TYPE_MECHANICAL) ) then
        return false
    endif

    if ( GetUnitAbilityLevelSwapped('A02H', GetAttacker()) == 0 ) then
        return false
    endif
Returning false means that it failed to work. Returning true means that it was successful.
 
Last edited:
Level 17
Joined
Jun 2, 2009
Messages
1,123
The error is telling you that the variable "u" doesn't exist. If it did, you'd see the variable being declared like so:
JASS:
local unit u = GetTriggerUnit()
Add that line to the top of your sdfg function and you should be good to go.

Alternatively, you can replace the two instances of "u" with GetTriggerUnit() and the error will go away.
GetTriggerUnit() is the unit that was attacked. In GUI it's the (Triggering unit).

Remember that local variables must be declared at the top of a function before anything else.

Edit: You may also want to adjust the If Then statements to this:
vJASS:
    if ( IsUnitType(u, UNIT_TYPE_STRUCTURE) or IsUnitType(u, UNIT_TYPE_MECHANICAL) ) then
        return false
    endif

    if ( GetUnitAbilityLevelSwapped('A02H', GetAttacker()) == 0 ) then
        return false
    endif
Returning false means that it failed to work. Returning true means that it was successful.

Truth is, i don't have a knowledge about Jass. It is one of my friends code. But can you suggest me good system about that?
Code was working like this. I just wanted to add "non mechanical"

JASS:
function sdfg takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == false ) ) then
        return false
    endif

    if ( not ( GetUnitAbilityLevelSwapped('A02H', GetAttacker()) > 0 ) ) then
        return false
    endif
    return true
endfunction

function backstab takes nothing returns nothing
call DestroyTrigger(GetTriggeringTrigger())
if((RAbsBJ((GetUnitFacing(GetTriggerUnit())-GetUnitFacing(GetEventDamageSource())))<=105.)) and ( GetUnitAbilityLevelSwapped('A02H', GetEventDamageSource()) > 0 ) then
call UnitDamageTargetBJ( GetEventDamageSource(), GetTriggerUnit(), ( ( 80.00 * I2R(GetUnitAbilityLevelSwapped('A02H', GetEventDamageSource())) ) + 1.00 ), ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL )
call DestroyEffectBJ( AddSpecialEffectTargetUnitBJ("chest",GetTriggerUnit(),"Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl") )
endif

endfunction

function asdf takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
call TriggerAddAction( t,function backstab )
call PolledWait(2.)
call DisableTrigger(t)
call DestroyTrigger(t)
endfunction

//===========================================================================
function InitTrig_Viceclaws takes nothing returns nothing
    set gg_trg_Viceclaws = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Viceclaws, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Viceclaws, Condition( function sdfg ) )
    call TriggerAddAction( gg_trg_Viceclaws, function asdf )
endfunction

That's hideous and leaks like crazy. Why not just use a backstab attack that someone else already did? Attacked events are easily abused, so I can see why the person who created this wanted to include a damage event, but if you just use Damage Engine then you can avoid the attack event altogether, avoid all the leaks, etc.

I recommend not using JASS if you don't understand the basics. You can easily do this in GUI in combination with Damage Engine.
Hmmm. I don't understand to Jass honestly. But can you show me how can i make this easily?

"Hero deals bonus damage while attacking from behind"
It should not work on structures and mechanicals.
 
Level 17
Joined
Jun 2, 2009
Messages
1,123
Did you get it working using my suggestions?

And I'm sorry but I'm not sure what you mean by "suggest a good system", do you mean a tutorial?

No i mean can we re-write this code for "when you attack enemy from behind you will deal extra damage" with 2 conditions "no structure, no mechanical"
 
Level 17
Joined
Jun 2, 2009
Messages
1,123
Look at my previous post. I showed you how to do it.
Sadly still i am getting error while saving

JASS:
function sdfg takes nothing returns boolean
    if ( IsUnitType(u, UNIT_TYPE_STRUCTURE) or IsUnitType(u, UNIT_TYPE_MECHANICAL) ) then
        return false
    endif

    if ( GetUnitAbilityLevelSwapped('A02H', GetAttacker()) == 0 ) then
        return false
    endif

function backstab takes nothing returns nothing
call DestroyTrigger(GetTriggeringTrigger())
if((RAbsBJ((GetUnitFacing(GetTriggerUnit())-GetUnitFacing(GetEventDamageSource())))<=105.)) and ( GetUnitAbilityLevelSwapped('A02H', GetEventDamageSource()) > 0 ) then
call UnitDamageTargetBJ( GetEventDamageSource(), GetTriggerUnit(), ( ( 80.00 * I2R(GetUnitAbilityLevelSwapped('A02H', GetEventDamageSource())) ) + 1.00 ), ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL )
call DestroyEffectBJ( AddSpecialEffectTargetUnitBJ("chest",GetTriggerUnit(),"Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl") )
endif

endfunction

function asdf takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
call TriggerAddAction( t,function backstab )
call PolledWait(2.)
call DisableTrigger(t)
call DestroyTrigger(t)
endfunction

//===========================================================================
function InitTrig_Viceclaws takes nothing returns nothing
    set gg_trg_Viceclaws = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Viceclaws, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Viceclaws, Condition( function sdfg ) )
    call TriggerAddAction( gg_trg_Viceclaws, function asdf )
endfunction
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,509
I have read but still i don't get it. I don't understand about Jass coding. I have read many times and still reading but i don't understand.
Probably i am gonna find GUI version of this system. Thank you for your help.
I explained it all in my first post but I understand if it's confusing.

You're better off using a Damage Engine anyway like Bribe suggested:

It'll be GUI as well.
 
Level 17
Joined
Jun 2, 2009
Messages
1,123
I explained it all in my first post but I understand if it's confusing.

You're better off using a Damage Engine anyway like Bribe suggested:

It'll be GUI as well.
Yes sadly it is confusing to me because i already said i don't have a knowledge about Jass coding. By the way just realized i had backstab system one of my maps. Thank you for your help.
 
If your warcraft version is 1.31 and above, you can copy-paste the following snippet below.

JASS:
// Technically, we can choose to return nothing, but since
// the trigger is registered to a GUI variable, it's likely that
// this trigger might be referenced somewhere else, so
// have it behave normally.
function Viceclaws_OnDamage takes nothing returns boolean
    local unit source = GetEventDamageSource()
    local unit target = GetTriggerUnit()
    local integer abilLvl = GetUnitAbilityLevel(source, 'A02H')
    local real angleDiff
    // You filter out the following conditions:
    // If the target is a structure, mechanical, or 
    // if the source does not have the desired ability,
    // then we terminate execution here.
    if (IsUnitType(target, UNIT_TYPE_STRUCTURE) or IsUnitType(target, UNIT_TYPE_MECHANICAL) or (abilLvl == 0)) then
        set source = null
        set target = null
        return false
    endif
    set angleDiff = RAbsBJ(GetUnitFacing(target) - GetUnitFacing(source))
    // I added another condition that considers edge cases at quadrants 1 and 4 in the cartesian coordinate system.
    // Not to worry, the effect should still be the same.
    if (angleDiff <= 105.0) or (angleDiff >= 255.0) then
        call DisableTrigger(GetTriggeringTrigger())
        call UnitDamageTarget( source, target, ( ( 80.00 * I2R(abilLvl) + 1.00 ), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
        call DestroyEffect( AddSpecialEffectTargetUnit("Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl", target, "chest"))
        call EnableTrigger(GetTriggeringTrigger())
        set source = null
        set target = null
        return true
    endif
    set source = null
    set target = null
    return false
endfunction

//===========================================================================
function InitTrig_Viceclaws takes nothing returns nothing
    set gg_trg_Viceclaws = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Viceclaws, EVENT_PLAYER_UNIT_DAMAGED )
    call TriggerAddCondition( gg_trg_Viceclaws, Condition( function Viceclaws_OnDamage) )
endfunction

Alternatively, you can use Damage Engine, which should allow you to handle damage events without worrying about the underlying framework. Once you've included Damage Engine in your map, you can define your damage handling trigger as follows:

  • Events
    • Game: DamageEvent Equal to 1.00
  • Conditions
    • (DamageEventTarget is Mechanical Equal to False)
    • (DamageEventTarget is a structure Equal to False)
    • (((Level of 'A02H') for DamageEventSource) Greater than 0)
  • Actions
    • If - If (All Conditions) are True, then do (Then - Actions), else do (Else - Actions)
      • If - Conditions
        • Or - Any Conditions are True
          • (Absolute value of ((Facing angle of DamageEventTarget) - (Facing angle of DamageEventSource)) Less than 105.00)
          • (Absolute value of ((Facing angle of DamageEventTarget) - (Facing angle of DamageEventSource)) Greater than 255.00)
    • Then - Actions
      • Comment: -------- I know that DamageEngine is recursion-proof, but it's a force of habit on my part --------
      • Trigger: Disable (this trigger)
      • Comment: -------- Don't know the exact name of the ability, so I placed the rawcode in its place --------
      • Unit: Cause DamageEventSource to deal ((80.00 * Real(((Level of 'A02H') for DamageEventSource))) + 1.00) to DamageEventTarget with attack type Hero and damage type Normal.
      • Trigger: Enable (this trigger)
    • Else - Actions
 
Level 17
Joined
Jun 2, 2009
Messages
1,123
Yes sadly it is confusing to me because i already said i don't have a knowledge about Jass coding. By the way just realized i had backstab system one of my maps. Thank you for your help.
@MyPad Ah thank you for your help. But i just remembered i already have this system in one of my maps and i have created it by myself. Thank you so much for your kindness.
 
Status
Not open for further replies.
Top