Unable to refer to units?

Kazuga

Let the game begin...
Reaction score
110
Hi there, I have been away from the WC3 editor for so long that I have even forgot the very basics, just came back to it to make a map with a friend and bumped into something that is probably very easy to solve but I have no idea what is wrong.

Basically I'm trying to make a so called KnockBack system, which will handle all forms of knockbacks caused during the game. For this I created global variables;
(AUD = AllUnitData)
AUDID - Integer Array
AUDUnit - Unit Array
AUDKBForce - Real Array
AUDKBAngle - Real Array

I begin with adding all the already existing units in the game to the data when the game starts, currently while testing two Footman are in the center of the map, no additional units are yet created.

Code:
Init 1
    Events
        Map initialization
    Conditions
    Actions
        Set TempGroup = (Units in (Playable map area))
        Set tempInt = 1
        Unit Group - Pick every unit in TempGroup and do (Actions)
            Loop - Actions
                Game - Display to (All players) the text: (Roar  + (String(tempInt)))
                Set tempInt = (tempInt + 1)
                Set AUDID[tempInt] = tempInt
                Unit - Set the custom value of (Picked unit) to AUDID[tempInt]

Here is the knockback system code that I need help with, the loop is run the correct amount of times but nothing happens to the footman.

Code:
function takevalues takes real kraft, real angle returns nothing


endfunction

function KBActions takes nothing returns nothing
    local integer LC = 1
    local unit U = null
    local real kraft = 0
    local real angle = 0
    
    
    loop 
    
        set LC = LC + 1
        
//This message is shown with the correct number and value.
        call DisplayTextToForce( GetPlayersAll(), I2S(LC) + " - Looped" )
        
        set kraft = udg_AUDKBForce[LC]
        set angle = udg_AUDKBAngle[LC]
        set U = udg_AUDUnit[LC]
        
//Here I'm just testing if it at all refers to any of the two units, nothing happens.
        call DisplayTextToForce( GetPlayersAll(), GetUnitName(U) )
    call AddSpecialEffectLocBJ( GetUnitLoc(U), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" )
        
        call SetUnitX(U, GetUnitX(U) + kraft * Cos(angle * bj_DEGTORAD))
        call SetUnitY(U, GetUnitY(U) + kraft * Sin(angle * bj_DEGTORAD))
        
        //set udg_AUDKBForce[LoopCounter] = -5
        
    exitwhen LC == udg_AUDID[LC] 
    endloop
    
    
    
   
endfunction

//===========================================================================
function InitTrig_KnockBackSystem2 takes nothing returns nothing
    set gg_trg_KnockBackSystem2 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_KnockBackSystem2, 1 )
    call TriggerAddAction( gg_trg_KnockBackSystem2, function KBActions )
endfunction

This is just a test ability trigger to test push a target, a simple single target spell both Footman possess.
Code:
Knuff
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
    Actions
        Game - Display to (All players) the text: Casting
        Set AUDKBForce[AUDID[(Custom value of (Target unit of ability being cast))]] = 100.00
        Set AUDKBAngle[AUDID[(Custom value of (Target unit of ability being cast))]] = 100.00

Anyone who can see what I have missed? I have looked it over and even rewrote the whole thing trying to make it work. It has to be some sort of problem in the Index or something...
 

WaterKnight

Member
Reaction score
7
You do not set the udg_AUDUnit array but instead the elements of udg_AUDID strangely get their own indizes attached?

Trigger:
  • Set AUDID[tempInt] = tempInt
--> You get what you put in.

Also why ending the loop when interator == udg_AUDID[iterator]? Would you not want to run it from start to end, namely have a variable that holds the amount/last.
 

Kazuga

Let the game begin...
Reaction score
110
Thanks, that solved it. Gave me a laugh when I got it to work and my footman flew off out of the map bounds and caused WC3 to crash ^^. <3:thup:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top