• 🏆 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] Item Problem 2

Status
Not open for further replies.
Guys i am making an amour that gives 7% chance to root an melle attacker. However i don't know what i am doing (lol) ...
I did it in GUI and converted to JASS but i think my JASS modifications don't work .. can you help me ?

GUI converted Script:
JASS:
function Trig_Jungle_armor_Func002C takes nothing returns boolean
    if ( not ( IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    if ( not ( UnitHasItemOfTypeBJ(GetAttackedUnitBJ(), 'I013') == true ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetAttacker(), UNIT_TYPE_MELEE_ATTACKER) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Jungle_armor_Conditions takes nothing returns boolean
    if ( not Trig_Jungle_armor_Func002C() ) then
        return false
    endif
    return true
endfunction

function Trig_Jungle_armor_Func001C takes nothing returns boolean
    if ( not ( 7 >= GetRandomInt(1, 100) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Jungle_armor_Actions takes nothing returns nothing
    if ( Trig_Jungle_armor_Func001C() ) then
        call CreateNUnitsAtLoc( 1, 'h01H', GetOwningPlayer(GetAttackedUnitBJ()), GetUnitLoc(GetAttacker()), bj_UNIT_FACING )
        call UnitApplyTimedLifeBJ( 2.50, 'BTLF', GetLastCreatedUnit() )
        call UnitAddAbilityBJ( 'A00P', GetLastCreatedUnit() )
        call SetUnitAbilityLevelSwapped( 'A00P', GetLastCreatedUnit(), 2 )
        call IssueTargetOrderBJ( GetLastCreatedUnit(), "entanglingroots", GetAttacker() )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Jungle_armor takes nothing returns nothing
    set gg_trg_Jungle_armor = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Jungle_armor, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Jungle_armor, Condition( function Trig_Jungle_armor_Conditions ) )
    call TriggerAddAction( gg_trg_Jungle_armor, function Trig_Jungle_armor_Actions )
endfunction


And here is my script, 100 smaller and i think it doesn't work ... and it has BJ's i don't know how to remove ... and DOES IT LEAK ? very important i need to know plz ... =s _:

JASS:
function JungleArmor_Conds takes nothing returns boolean
local integer rootchance = 7
return GetRandomInt(1, 100) <= rootchance and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) and UnitHasItemOfTypeBJ(GetTriggerUnit(), 'I013') and IsUnitType(GetAttacker(), UNIT_TYPE_MELEE_ATTACKER)
endfunction
//======================================================================================================================================================================================================================
function JungleArmor_Acts takes nothing returns nothing
        local unit victim = GetTriggerUnit()
        local unit attacker = GetAttacker()
        local unit dummy = CreateUnit( GetOwningPlayer(victim), 'h01H', GetUnitX(attacker), GetUnitY(attacker), 0)
        call UnitApplyTimedLife(dummy, 'BTLF', 2.5)
        call UnitAddAbility(dummy, 'A00P')
        call SetUnitAbilityLevel(dummy, 'A00P', 2)
        call IssueTargetOrder(dummy, "entanglingroots", attacker)
        set victim = null
        set attacker = null
        set dummy = null  
endfunction
//===========================================================================
function InitTrig_Jungle_armour takes nothing returns nothing
    local trigger JungleArmor = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( JungleArmor, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( JungleArmor, Condition( function JungleArmor_Conds ) )
    call TriggerAddAction( JungleArmor, function JungleArmor_Acts )
endfunction

Any help ? plz ?
 
Level 9
Joined
Mar 25, 2005
Messages
252
This worked when I tested:
JASS:
function Trig_Jungle_armor_Conditions takes nothing returns boolean
return GetRandomInt(1, 100) <= 7 and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) and UnitHasItemOfTypeBJ(GetTriggerUnit(), 'wlsd') and IsUnitType(GetAttacker(), UNIT_TYPE_MELEE_ATTACKER)
endfunction
function Trig_Jungle_armor_Actions takes nothing returns nothing
        local unit victim = GetTriggerUnit()
        local unit attacker = GetAttacker()
        local unit dummy = CreateUnit( GetOwningPlayer(victim), 'h004', GetUnitX(attacker), GetUnitY(attacker), 0)
        call UnitApplyTimedLife(dummy, 'BTLF', 2.5)
        call UnitAddAbility(dummy, 'A003')
        call SetUnitAbilityLevel(dummy, 'A003', 2)
        call IssueTargetOrder(dummy, "entanglingroots", attacker)
        set victim = null
        set attacker = null
        set dummy = null
endfunction
//===========================================================================
function InitTrig_Jungle_armour takes nothing returns nothing
set gg_trg_Jungle_armour = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Jungle_armour, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Jungle_armour, Condition( function Trig_Jungle_armor_Conditions ) )
    call TriggerAddAction( gg_trg_Jungle_armour, function Trig_Jungle_armor_Actions )
endfunction

Just make sure that your trigger is called "Jungle armour"

The TriggerRegisterAnyUnitEventBJ is one of the useful BJs. This is what it looks like:
JASS:
function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
    local integer index

    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
UnitHasItemOfTypeBJ is actually a wrapper for another BJ that's actually not that bad.

JASS:
function GetInventoryIndexOfItemTypeBJ takes unit whichUnit, integer itemId returns integer
    local integer index
    local item    indexItem

    set index = 0
    loop
        set indexItem = UnitItemInSlot(whichUnit, index)
        if (indexItem != null) and (GetItemTypeId(indexItem) == itemId) then
            return index + 1
        endif

        set index = index + 1
        exitwhen index >= bj_MAX_INVENTORY
    endloop
    return 0
endfunction

function UnitHasItemOfTypeBJ takes unit whichUnit, integer itemId returns boolean
    return GetInventoryIndexOfItemTypeBJ(whichUnit, itemId) > 0
endfunction
 
Level 9
Joined
Mar 25, 2005
Messages
252
Well I guess you could get rid of the timed life and remove the dummy unit after a wait. However Im not sure at all of how much that improves the spell, but afaik removing a unit is better than just killing it.

JASS:
function Trig_Jungle_armor_Actions takes nothing returns nothing
        local unit victim = GetTriggerUnit()
        local unit attacker = GetAttacker()
        local unit dummy = CreateUnit( GetOwningPlayer(victim), 'h004', GetUnitX(attacker), GetUnitY(attacker), 0)
        call UnitAddAbility(dummy, 'A003')
        call SetUnitAbilityLevel(dummy, 'A003', 2)
        call IssueTargetOrder(dummy, "entanglingroots", attacker)
        call TriggerSleepAction(2.5)
        call RemoveUnit(dummy)
        set victim = null
        set attacker = null
        set dummy = null
endfunction
 
Last edited:
Thx guys, well here is the final version of the spell, i added the "SetUnitExploded" function but i don't know if i did it correctly. Btw, if i change the decaying field of the unit to "does not decay, does not raise" the will will leave no corpse and there will be no need to explode it rit ???
I also didn't change the BJ Item at the top because i just think it is too much complicated for me to do so.
Anyway, here is the final version:

Spell:
JASS:
function JungleArmor_Conds takes nothing returns boolean
local integer rootchance = 7
return GetRandomInt(1, 100) <= rootchance and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) and UnitHasItemOfTypeBJ(GetTriggerUnit(), 'I013') and IsUnitType(GetAttacker(), UNIT_TYPE_MELEE_ATTACKER)
endfunction
//======================================================================================================================================================================================================================
function JungleArmor_Acts takes nothing returns nothing
        local unit victim = GetTriggerUnit()
        local unit attacker = GetAttacker()
        local unit dummy = CreateUnit( GetOwningPlayer(victim), 'h01H', GetUnitX(attacker), GetUnitY(attacker), 0)
        call UnitApplyTimedLife(dummy, 'BTLF', 2.5)
        call UnitAddAbility(dummy, 'A00P')
        call SetUnitAbilityLevel(dummy, 'A00P', 2)
        call IssueTargetOrder(dummy, "entanglingroots", attacker)
        call SetUnitExploded(dummy, true) 
        set victim = null
        set attacker = null
        set dummy = null  
endfunction
//===========================================================================
function InitTrig_Jungle_Armor takes nothing returns nothing
    local trigger JungleArmor = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( JungleArmor, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( JungleArmor, Condition( function JungleArmor_Conds ) )
    call TriggerAddAction( JungleArmor, function JungleArmor_Acts )
endfunction

Thx for help, i am opened to new suggestions about improving this spell if you have some.
 
Status
Not open for further replies.
Top