• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

A strange problem...

Status
Not open for further replies.
Level 10
Joined
Sep 6, 2007
Messages
440
I was making a spell which has a Level*5 chance to turn a unit to your own side for level*5 seconds. The problem is the first creep converted does not return to his own owner. Here is the trigger check it out.
  • Mind Tricks
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Attacked unit) is A Hero) Equal to False
          • (Level of Mind Tricks for (Attacking unit)) Greater than or equal to 1
    • Actions
      • Set CasterB = (Attacking unit)
      • Set VictimB = (Attacked unit)
      • Set Chance = (Random integer number between 1 and 100)
      • Set OwnerA = (Owner of VictimB)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance Less than or equal to ((Level of Mind Tricks for CasterB) x 5)
        • Then - Actions
          • Special Effect - Create a special effect attached to the chest of VictimB using Abilities\Spells\Other\Charm\CharmTarget.mdl
          • Unit - Change ownership of VictimB to (Owner of CasterB) and Change color
          • Countdown Timer - Start Timer as a One-shot timer that will expire in ((Real((Level of Mind Tricks for CasterB))) x 5.00) seconds
          • Trigger - Turn on Expires <gen>
        • Else - Actions
----AND----
  • Expires
    • Events
      • Time - Timer expires
    • Conditions
    • Actions
      • Unit - Change ownership of VictimB to OwnerA and Change color
      • Trigger - Turn off (This trigger)
 
Level 4
Joined
Jul 23, 2007
Messages
129
If you convert a second unit before the first has become yours again, then the variable VictimB will be changed to the new unit instead of the old unit. So the old unit can no longer be referenced by the variable, so the expire trigger will not give him back to his owner, but will give the new unit (the new value for VictimB) back instead.

I'm not sure how to make this work the way you want. If it were me I would simply reduce the chance of conversion and make it permanent. That way it doesn't matter if the VictimB variable changes because the expire trigger doesn't need to run anymore.
 
Level 12
Joined
Mar 23, 2008
Messages
942
  • Mind Tricks
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Attacked unit) is A Hero) Equal to False
          • (Level of Mind Tricks for (Attacking unit)) Greater than or equal to 1
    • Actions
      • Custom script: local unit udg_VictimB
      • Set CasterB = (Attacking unit)
      • Set VictimB = (Attacked unit)
      • Set Chance = (Random integer number between 1 and 100)
      • Set OwnerA = (Owner of VictimB)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance Less than or equal to ((Level of Mind Tricks for CasterB) x 5)
        • Then - Actions
          • Special Effect - Create a special effect attached to the chest of VictimB using Abilities\Spells\Other\Charm\CharmTarget.mdl
          • Unit - Change ownership of VictimB to (Owner of CasterB) and Change color
          • Wait ((Real((Level of Mind Tricks for CasterB))) x 5.00) seconds
          • Trigger - Run Expires <gen>
        • Else - Actions
----AND----
  • Expires
    • Events
    • Conditions
    • Actions
      • Unit - Change ownership of VictimB to OwnerA and Change color
      • Trigger - Turn off (This trigger)

That will solve it.

But that will only work if there is only one unit that have that ability, if you wanna it to be MUI, you need to delete: Set CasterB = (Attacking unit) and Set VictimB = (Attacked unit) and use Attacking unit and Attacked unit instead of variables
 
Level 4
Joined
Jul 23, 2007
Messages
129
  • Events
  • Unit - A unit Is attacked
  • Conditions
  • And - All (Conditions) are true
  • Conditions
  • ((Attacked unit) is A Hero) Equal to False
  • (Level of Mind Tricks for (Attacking unit)) Greater than or equal to 1
  • Actions
  • Custom script: local unit udg_VictimB
  • Custom script: local player udg_OwnerA
  • Set CasterB = (Attacking unit)
  • Set VictimB = (Attacked unit)
  • Set Chance = (Random integer number between 1 and 100)
  • Set OwnerA = (Owner of VictimB)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • Chance Less than or equal to ((Level of Mind Tricks for CasterB) x 5)
  • Then - Actions
  • Special Effect - Create a special effect attached to the chest of VictimB using Abilities\Spells\Other\Charm\CharmTarget.mdl
  • Unit - Change ownership of VictimB to (Owner of CasterB) and Change color
  • Wait ((Real((Level of Mind Tricks for CasterB))) x 5.00) seconds
  • Unit - Change ownership of VictimB to OwnerA and Change color
  • Else - Actions
Try it this way. That may work.
 
Level 12
Joined
Mar 23, 2008
Messages
942
Try it this way. That may work.
PurplePoot tells me that you can only use 1 local in Gui.
So or he only add that skill to one player, or he makes it all in Jass.
(D'oh, I forgot to fusion triggers because of local variable xD)

Here, I converted the trigger to Jass, now it will work:
JASS:
function Trig_Mind_Tricks_Copy_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_HERO) == false ) ) then
        return false
    endif
    if ( not ( GetUnitAbilityLevelSwapped('PUT HERE THE ABILITY ID', GetAttacker()) >= 1 ) ) then
    return false
    endif
    return true
endfunction

function Trig_Mind_Tricks_Copy_Func005C takes nothing returns boolean
    if ( not ( chance <= ( GetUnitAbilityLevelSwapped('PUT HERE THE ABILITY ID', casterb) * 5 ) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Mind_Tricks_Copy_Actions takes nothing returns nothing
    local unit casterb = GetAttacker()
    local unit victimb = GetAttackedUnitBJ()
    local integer chance = GetRandomInt(1, 100)
    local player owner = GetOwningPlayer(victimb)
    if ( Trig_Mind_Tricks_Copy_Func005C() ) then
        call AddSpecialEffectTargetUnitBJ( "chest", victimb, "Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl" )
        call SetUnitOwner( victimb, GetOwningPlayer(casterb), true )
        call TriggerSleepAction( I2R(( GetUnitAbilityLevelSwapped('PUT HERE THE ABILITY ID', casterb) * 5 )) )
        call SetUnitOwner( victimb, owner, true )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Mind_Tricks_Copy takes nothing returns nothing
    set gg_trg_Mind_Tricks_Copy = CreateTrigger( )
    call DisableTrigger( gg_trg_Mind_Tricks_Copy )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Mind_Tricks_Copy, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Mind_Tricks_Copy, Condition( function Trig_Mind_Tricks_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Mind_Tricks_Copy, function Trig_Mind_Tricks_Copy_Actions )
endfunction

Remember to change "PUT HERE THE ABILITY ID" to the raw code of your mindtrick ability.
 
Last edited:
Level 4
Joined
Jul 23, 2007
Messages
129
How would someone implement that? Just convert and empty trigger to jass then copy + paste what you have into it and input the ability ID?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
How would someone implement that? Just convert and empty trigger to jass then copy + paste what you have into it and input the ability ID?
Convert the trigger you posted above. Then change the names of the variables to something without 'udg_' at their initialization and each of their use.
And yes, all of the variables that should be local, should be initialized.
 
Level 12
Joined
Mar 23, 2008
Messages
942
None of the types are declared for locals in that script...
Lol, sorry I forgot xD

If you can't copy and paste from here, try to paste in notepad and them copy again and paste in WE.
If don't work... just copy each line separately xD

JASS:
function Trig_Mind_Tricks_Copy_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_HERO) == false ) ) then
        return false
    endif
    if ( not ( GetUnitAbilityLevelSwapped('PUT HERE THE ABILITY ID', GetAttacker()) >= 1 ) ) then
    return false
    endif
    return true
endfunction

function Trig_Mind_Tricks_Copy_Func005C takes nothing returns boolean
    if ( not ( chance <= ( GetUnitAbilityLevelSwapped('PUT HERE THE ABILITY ID', casterb) * 5 ) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Mind_Tricks_Copy_Actions takes nothing returns nothing
    local unit casterb = GetAttacker()
    local unit victimb = GetAttackedUnitBJ()
    local integer chance = GetRandomInt(1, 100)
    local player owner = GetOwningPlayer(victimb)
    if ( Trig_Mind_Tricks_Copy_Func005C() ) then
        call AddSpecialEffectTargetUnitBJ( "chest", victimb, "Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl" )
        call SetUnitOwner( victimb, GetOwningPlayer(casterb), true )
        call TriggerSleepAction( I2R(( GetUnitAbilityLevelSwapped('PUT HERE THE ABILITY ID', casterb) * 5 )) )
        call SetUnitOwner( victimb, owner, true )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Mind_Tricks_Copy takes nothing returns nothing
    set gg_trg_Mind_Tricks_Copy = CreateTrigger( )
    call DisableTrigger( gg_trg_Mind_Tricks_Copy )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Mind_Tricks_Copy, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Mind_Tricks_Copy, Condition( function Trig_Mind_Tricks_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Mind_Tricks_Copy, function Trig_Mind_Tricks_Copy_Actions )
endfunction
 
Level 12
Joined
Mar 23, 2008
Messages
942
I don't know Jass.
What do you wanna me to do? xD

I just converted to text to be able to use locals.
Almost all lines use variable, so I think this is better than doing a GUI trigger only with custom scripts xD
 
Level 10
Joined
Sep 6, 2007
Messages
440
I did insert the ability ID as A000. Because it was on the raw data with Au at the end. Do I have to insert that as well?
EDIT: I think this will be some sort of a request but, can someone really do this for me? It just freezes my WE when I enable it. ( WE disabled it )
 
Level 12
Joined
Mar 23, 2008
Messages
942
I did insert the ability ID as A000. Because it was on the raw data with Au at the end. Do I have to insert that as well?
EDIT: I think this will be some sort of a request but, can someone really do this for me? It just freezes my WE when I enable it. ( WE disabled it )
Send your map to someone that know JASS so if it finds a bug he can fix it.
 
Level 10
Joined
Sep 6, 2007
Messages
440
JASS:
function Trig_Mind_Tricks_Copy_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_HERO) == false ) ) then
        return false
    endif
    if ( not ( GetUnitAbilityLevelSwapped('A000', GetAttacker()) >= 1 ) ) then
    return false
    endif
    return true
endfunction
function Trig_Mind_Tricks_Copy_Func005C takes nothing returns boolean
    if ( not ( chance <= ( GetUnitAbilityLevelSwapped('A000', casterb) * 5 ) ) ) then
        return false
    endif
    return true
endfunction
function Trig_Mind_Tricks_Copy_Actions takes nothing returns nothing
    local unit casterb = GetAttacker()
    local unit victimb = GetAttackedUnitBJ()
    local integer chance = GetRandomInt(1, 100)
    local player ownera = GetOwningPlayer(victimb)
    if ( Trig_Mind_Tricks_Copy_Func005C() ) then
        call AddSpecialEffectTargetUnitBJ( "chest", victimb, "Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl" )
        call SetUnitOwner( victimb, GetOwningPlayer(casterb), true )
        call TriggerSleepAction( I2R(( GetUnitAbilityLevelSwapped('A000', casterb) * 5 )) )
        call SetUnitOwner( victimb, owner, true )
    else
    endif
endfunction
function InitTrig_Mind_Tricks_Copy takes nothing returns nothing
    set gg_trg_Mind_Tricks_Copy = CreateTrigger( )
    call DisableTrigger( gg_trg_Mind_Tricks_Copy )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Mind_Tricks_Copy, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Mind_Tricks_Copy, Condition( function Trig_Mind_Tricks_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Mind_Tricks_Copy, function Trig_Mind_Tricks_Copy_Actions )
endfunction
There this is what causes problems. I can save my map by disabling this skill. Otherwise it's unplayable.
 
Level 9
Joined
Mar 25, 2005
Messages
252
Fixed:
JASS:
// Put this code into a trigger named Mind Tricks
// Replace 'A000' with the rawcode of your ability
function Trig_Mind_Tricks_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(), 'A000') > 0 and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false
endfunction
function Trig_Mind_Tricks_Actions takes nothing returns nothing
    local unit caster = GetAttacker()
    local unit target
    local player originalOwner
    if GetRandomInt(1, 100) <= GetUnitAbilityLevel(caster, 'A000') * 5 then // (level * 5)% chance
        set target = GetTriggerUnit()
        set originalOwner = GetOwningPlayer(target)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl", target, "chest"))
        call SetUnitOwner(target, GetOwningPlayer(caster), true)
        call TriggerSleepAction(GetUnitAbilityLevel(caster, 'A000') * 5) // waits (level * 5) seconds
        call SetUnitOwner(target, originalOwner, true)
        set target = null
    endif
    set caster = null
endfunction
function InitTrig_Mind_Tricks takes nothing returns nothing
    set gg_trg_Mind_Tricks = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Mind_Tricks, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_Mind_Tricks, Condition( function Trig_Mind_Tricks_Conditions))
    call TriggerAddAction(gg_trg_Mind_Tricks, function Trig_Mind_Tricks_Actions)
endfunction
 
Level 9
Joined
Mar 25, 2005
Messages
252
Does TriggerSleepAction have any difference between wait?

Yeah it varies a bit. Don't know how much and what that depends on though. It also has some minimum wait time which I've heard to be about 0.27 seconds.

What was making WE get crashed?

JASS:
function Trig_Mind_Tricks_Copy_Func005C takes nothing returns boolean
    if ( not ( chance <= ( GetUnitAbilityLevelSwapped('A000', casterb) * 5 ) ) ) then
        return false
    endif
    return true
endfunction
The other function had locals with the names "chance" and "casterb", but this function has no clue about them (since they aren't global nor declared in this function), they could just as well be imaginary words that have nothing to do with anything as far as this function is concerned. They are propably what crashed your WE.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Yeah it varies a bit. Don't know how much and what that depends on though. It also has some minimum wait time which I've heard to be about 0.27 seconds.
Well ... no.
They are the same thing. Wait is the GUI name of triggersleepaction. So they have the same minimum 'wait time', which is a bit too much for a smooth leak free performance.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Well you were not wrong.
But you answered a different question :)
And in an as a matter of fact fashion the minimum delay is less, about 0.1 ( stated on another tread), but usually it takes between 0.2-0.25(numbers from that tread; not tested by me, but I believe them).
Tread
 
Status
Not open for further replies.
Top