• 🏆 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] Custom Stun: what did I do wrong?

Status
Not open for further replies.
Level 6
Joined
Mar 26, 2008
Messages
239
I've read that custom stun (stunning any unit by triggers anywhere for any duration) can be made by adding remade "Aerial Shackles" ability (removed animations,added animation of stun,infinite duration) to a dummy and adding expiration timer to it,then ordering to use it to unit which should be stunned.
I tried to do such system,but it doesn't work,I think because I missed something in the system,but cannot find what...
JASS:
function StunUnit takes unit target, real duration returns nothing
local unit T = target
local unit D
local location L = GetUnitLoc(T)
local real R = duration
  if ( IsUnitIdType(GetUnitTypeId(T), UNIT_TYPE_MAGIC_IMMUNE) == false ) then
     set D = CreateUnitAtLoc(Player(PLAYER_NEUTRAL_AGGRESSIVE), 'e00A' , L, bj_UNIT_FACING )
     call UnitAddAbility(D,'A019')
     call IssueTargetOrder(D, "magicleash",T)
     call UnitApplyTimedLife(D,'BTLF',R)
  else
  endif
set D = null
set T = null
call RemoveLocation(L)
set L = null
endfunction
"e00A" is dummy id, 'A019' is id of ability, "magicleash" - order
 
Level 9
Joined
Nov 28, 2008
Messages
704
Neutrals dont respond to orders very well at all. Use NEUTRAL_PASSIVE, as agressive tends to do its own thing. I've had the problem enough.

Otherwise, looks fairly good. Remove the location though. X and Y are much better.
 
Level 6
Joined
Mar 26, 2008
Messages
239
about your script,
it might be because the dummy is owned by Neutral Hostile...
maybe you should add a player parameter?
and i think you don't need to declare "target" with new variable...
It's local,not variable.Made it for better look of the system.
Neutrals dont respond to orders very well at all. Use NEUTRAL_PASSIVE, as agressive tends to do its own thing. I've had the problem enough.

Otherwise, looks fairly good. Remove the location though. X and Y are much better.
I'll check it now and see if this helps.

{EDIT}
It didn't fix the problem...
 
It's local,not variable.Made it for better look of the system.

Locals are variables.

Here is a better version of you script.. (still not efficient).

JASS:
function StunUnit takes unit target, real duration returns nothing
local unit D
  if ( IsUnitIdType(GetUnitTypeId(target), UNIT_TYPE_MAGIC_IMMUNE) == false ) then
     set D = CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), 'e00A' , GetUnitX(target), GetUnitY(target) bj_UNIT_FACING )
     call UnitAddAbility(D,'A019')
     call IssueTargetOrder(D, "magicleash", target)
     call UnitApplyTimedLife(D,'BTLF',duration)
  endif
set D = null
endfunction
 
Level 6
Joined
Mar 26, 2008
Messages
239
Locals are variables.

Here is a better version of you script.. (still not efficient).

JASS:
function StunUnit takes unit target, real duration returns nothing
local unit D
  if ( IsUnitIdType(GetUnitTypeId(target), UNIT_TYPE_MAGIC_IMMUNE) == false ) then
     set D = CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), 'e00A' , GetUnitX(target), GetUnitY(target) bj_UNIT_FACING )
     call UnitAddAbility(D,'A019')
     call IssueTargetOrder(D, "magicleash", target)
     call UnitApplyTimedLife(D,'BTLF',duration)
  endif
set D = null
endfunction
Strings are too long to read,that's why I made local unit

{EDIT}
Dummies don't even appear....

{EDIT 2}
Everything worked when I used Player(0) as owner of the dummy=)Anyway it's dummy and it doesn't damage,so I think Player(0) can be used=)
Final version of the system:
JASS:
function StunUnit takes unit target, real duration returns nothing
local unit T = target
local unit D = CreateUnit(Player(0), 'e00A' , GetUnitX(T), GetUnitY(T), bj_UNIT_FACING )
local real R = duration
  call UnitApplyTimedLife(D,'BTLF',R)
    if ( IsUnitIdType(GetUnitTypeId(T), UNIT_TYPE_MAGIC_IMMUNE) == false ) then
       call UnitAddAbility(D,'A019')
       call IssueTargetOrder(D, "magicleash", T)
    endif
set D = null
set T = null
endfunction
 
Strings are too long to read,that's why I made local unit

{EDIT}
Dummies don't even appear....

{EDIT 2}
Everything worked when I used Player(0) as owner of the dummy=)Anyway it's dummy and it doesn't damage,so I think Player(0) can be used=)
Final version of the system:
JASS:
function StunUnit takes unit target, real duration returns nothing
local unit T = target
local unit D = CreateUnit(Player(0), 'e00A' , GetUnitX(T), GetUnitY(T), bj_UNIT_FACING )
local real R = duration
  call UnitApplyTimedLife(D,'BTLF',R)
    if ( IsUnitIdType(GetUnitTypeId(T), UNIT_TYPE_MAGIC_IMMUNE) == false ) then
       call UnitAddAbility(D,'A019')
       call IssueTargetOrder(D, "magicleash", T)
    endif
set D = null
set T = null
endfunction

Player 0 is the default red player... btw.. cant you just use IsUnitType instead of IsUnitIDType?

and on your first trigger ins't the x in Player(x) needs to be an integer and you used
Player(PLAYER_NEUTRAL_AGGRESSIVE) maybe that's what caused the error...
 
Level 6
Joined
Mar 26, 2008
Messages
239
Player 0 is the default red player... btw.. cant you just use IsUnitType instead of IsUnitIDType?

and on your first trigger ins't the x in Player(x) needs to be an integer and you used
Player(PLAYER_NEUTRAL_AGGRESSIVE) maybe that's what caused the error...
I know that Player 0 is red player,I even explained why I used this player=)
Will see about IsUnitType.
And PLAYER_NEUTRAL_AGGRESSIVE is an integer=)
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
function StunUnit takes unit target, real duration returns nothing
local unit T = target //This made me LOL!
//Why create the unit before the 'IF'?
local unit D = CreateUnit(Player(0), 'e00A' , GetUnitX(T), GetUnitY(T), bj_UNIT_FACING ) 
local real R = duration //this  also made me lol
  call UnitApplyTimedLife(D,'BTLF',R)
    if ( IsUnitIdType(GetUnitTypeId(T), UNIT_TYPE_MAGIC_IMMUNE) == false ) then
       call UnitAddAbility(D,'A019')
       call IssueTargetOrder(D, "magicleash", T)
    endif
set D = null
set T = null
endfunction

You know 'takes' is local's. so triggerhappys code are more effecient then yours

You know 'takes' is local's. so triggerhappys code are more effecient then yours
 
Level 6
Joined
Mar 26, 2008
Messages
239
You know 'takes' is local's. so triggerhappys code are more effecient then yours

You know 'takes' is local's. so triggerhappys code are more effecient then yours
You may lol as much as you want.
I made the system much easier to read,so it's my business if I want it or not.



Thread is closed,problem is solved.
 
Level 7
Joined
Mar 8, 2009
Messages
360
JASS:
function StunUnit takes unit T, real R returns nothing
    local unit D
    if IsUnitIdType(GetUnitTypeId(T), UNIT_TYPE_MAGIC_IMMUNE) == false then
        set D = CreateUnit(Player(0), 'e00A' , GetUnitX(T), GetUnitY(T), bj_UNIT_FACING )
        call UnitApplyTimedLife(D,'BTLF',R)
        call UnitAddAbility(D,'A019')
        call IssueTargetOrder(D, "magicleash", T)
    endif
    set D = null
endfunction

why should you define more variables than necessary? I think passed variables are as fast as locals or faster.
 
Level 6
Joined
Mar 26, 2008
Messages
239
JASS:
function StunUnit takes unit T, real R returns nothing
    local unit D
    if IsUnitIdType(GetUnitTypeId(T), UNIT_TYPE_MAGIC_IMMUNE) == false then
        set D = CreateUnit(Player(0), 'e00A' , GetUnitX(T), GetUnitY(T), bj_UNIT_FACING )
        call UnitApplyTimedLife(D,'BTLF',R)
        call UnitAddAbility(D,'A019')
        call IssueTargetOrder(D, "magicleash", T)
    endif
    set D = null
endfunction
why should you define more variables than necessary? I think passed variables are as fast as locals or faster.
:grin:Well,you are right)
 
Status
Not open for further replies.
Top