1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  4. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Trigger problem

Discussion in 'Triggers & Scripts' started by Pitakebab, Aug 26, 2010.

  1. Pitakebab

    Pitakebab

    Joined:
    Feb 18, 2007
    Messages:
    214
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I'm using this kind of trigger in my map to make satellites circle around planets, and it works well:
    Trigger
    • SolarSatelliteMovement
      • Events
        • Time - Every 0.05 seconds of game time
      • Conditions
      • Actions
        • Unit Group - Pick every unit in solar_sats and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Distance between (Position of (Picked unit)) and (Position of Planet (grass) 0000 <gen>)) Less than or equal to 600.00
              • Then - Actions
                • Set temp_point = (Position of Planet (grass) 0000 <gen>)
                • Set temp_loc = (temp_point offset by 500.00 towards ((Angle from (Position of Planet (grass) 0000 <gen>) to (Position of (Picked unit))) + 0.50) degrees)
                • Unit - Move (Picked unit) instantly to temp_loc, facing ((Angle from (Position of Planet (grass) 0000 <gen>) to (Position of (Picked unit))) + 90.00) degrees
                • Custom script: call RemoveLocation(udg_temp_loc)
                • Custom script: call RemoveLocation(udg_temp_point)
              • Else - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Distance between (Position of (Picked unit)) and (Position of Planet (lava) 0291 <gen>)) Less than or equal to 600.00
                  • Then - Actions
                    • Set temp_point = (Position of Planet (lava) 0291 <gen>)
                    • Set temp_loc = (temp_point offset by 500.00 towards ((Angle from (Position of Planet (lava) 0291 <gen>) to (Position of (Picked unit))) + 0.50) degrees)
                    • Unit - Move (Picked unit) instantly to temp_loc, facing ((Angle from (Position of Planet (lava) 0291 <gen>) to (Position of (Picked unit))) + 90.00) degrees
                    • Custom script: call RemoveLocation(udg_temp_loc)
                    • Custom script: call RemoveLocation(udg_temp_point)
                  • Else - Actions
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Distance between (Position of (Picked unit)) and (Position of Planet (snow) 0468 <gen>)) Less than or equal to 600.00
                      • Then - Actions
                        • Set temp_point = (Position of Planet (snow) 0468 <gen>)
                        • Set temp_loc = (temp_point offset by 500.00 towards ((Angle from (Position of Planet (snow) 0468 <gen>) to (Position of (Picked unit))) + 0.50) degrees)
                        • Unit - Move (Picked unit) instantly to temp_loc, facing ((Angle from (Position of Planet (snow) 0468 <gen>) to (Position of (Picked unit))) + 90.00) degrees
                        • Custom script: call RemoveLocation(udg_temp_loc)
                        • Custom script: call RemoveLocation(udg_temp_point)
                      • Else - Actions
                        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • (Distance between (Position of (Picked unit)) and (Position of Planet (dirt) 0466 <gen>)) Less than or equal to 600.00
                          • Then - Actions
                            • Set temp_point = (Position of Planet (dirt) 0466 <gen>)
                            • Set temp_loc = (temp_point offset by 500.00 towards ((Angle from (Position of Planet (dirt) 0466 <gen>) to (Position of (Picked unit))) + 0.50) degrees)
                            • Unit - Move (Picked unit) instantly to temp_loc, facing ((Angle from (Position of Planet (dirt) 0466 <gen>) to (Position of (Picked unit))) + 90.00) degrees
                            • Custom script: call RemoveLocation(udg_temp_loc)
                            • Custom script: call RemoveLocation(udg_temp_point)
                          • Else - Actions


    The problem is that after a while, especially if there's several satellites, my map starts to lag like hell. So could someone help me to make lagless version of this trigger. BlueBerryWizard already started it but was too lazy to finish it :) I don't know a shit about JASS so I can't finish it myself. Ofc if the lagless version could be made with GUI that would be better :p but anyways, here's the script that BBW started:
    Code (vJASS):
    scope SolarSatelliteMovement initializer init

    public function Callback takes nothing returns nothing
        local unit u = GetEnumUnit()
        local real dx = GetLocationX(locB) - GetLocationX(locA)
        local real dy = GetLocationY(locB) - GetLocationY(locA)
        local real sr SquareRoot(dx * dx + dy * dy)
       
        set dx = GetLocationX(locB) - GetLocationX(locA)
        set dy = GetLocationY(locB) - GetLocationY(locA)
        set sr = SquareRoot(dx * dx + dy * dy)
       
        if sr < 600.00 then
            //blah blah add moar stuff here I'ma lazyface
        endif
       
        set u = null
    endfunction

    public function Actions takes nothing returns nothing
     call ForGroup(udg_solar_sats, function Callback)
    endfunction

    //===========================================================================
    public function init takes nothing returns nothing
        local trigger t = CreateTrigger()
       
        call TriggerAddAction( t, function Actions )
       
        set t = null
    endfunction
     
  2. -Kobas-

    -Kobas-

    Joined:
    Jan 17, 2010
    Messages:
    5,893
    Resources:
    28
    Icons:
    1
    Tools:
    2
    Maps:
    10
    Spells:
    4
    Template:
    5
    Tutorials:
    6
    Resources:
    28
    • SolarSatelliteMovement
      • Events
        • Time - Every 0.03 seconds of game time
      • Conditions
      • Actions
        • Set X_Unit_Planet[1] = Ancient Protector 0003 <gen>
        • Set X_Unit_Satelite[1] = Wisp 0002 <gen>
        • Set X_Unit_Satelite[2] = Wisp 0004 <gen>
        • Set X_Unit_Satelite[3] = Wisp 0005 <gen>
        • Set X_Unit_Satelite[4] = Wisp 0006 <gen>
        • Set X_Unit_Satelite[5] = Wisp 0007 <gen>
        • Set X_Unit_Satelite[6] = Wisp 0008 <gen>
        • Set X_Point[1] = (Position of X_Unit_Planet[1])
        • For each (Integer A) from 1 to 6, do (Actions)
          • Loop - Actions
            • Unit - Turn collision for X_Unit_Satelite[(Integer A)] Off
            • Set X_Angle[(Integer A)] = ((Facing of X_Unit_Satelite[(Integer A)]) + 3.00)
            • Set X_Point[2] = (X_Point[1] offset by 300.00 towards X_Angle[(Integer A)] degrees)
            • Unit - Move X_Unit_Satelite[(Integer A)] instantly to X_Point[2], facing X_Angle[(Integer A)] degrees
            • Custom script: call RemoveLocation(udg_X_Point[2])
        • Custom script: call RemoveLocation(udg_X_Point[1])
    Can help, btw you need 2 triggers one to use as setup trigger and another one for loop!

    I am 2 lazy to create everything, but you can set starting angle for each satellite in setup trigger also, that way satellites can have different distance from each other!

    Setup trigger should look like:
    • Set X_Unit_Planet[1] = Ancient Protector 0003 <gen>
    • Set X_Unit_Satelite[1] = Wisp 0002 <gen>
    • Set X_Unit_Satelite[2] = Wisp 0004 <gen>
    • Set X_Unit_Satelite[3] = Wisp 0005 <gen>
    • Unit - Turn collision for X_Unit_Satelite[1] Off
    • Unit - Turn collision for X_Unit_Satelite[2] Off
    • Set X_Angle[1] = 60
    • Set X_Angle[1] = 120

    and so on
     

    Attached Files:

  3. Pitakebab

    Pitakebab

    Joined:
    Feb 18, 2007
    Messages:
    214
    Resources:
    1
    Maps:
    1
    Resources:
    1
    thanks, those unit arrays are just for testing purposes I guess? because my map has no satellites already, they're buildable units :) so I've to use that unit group. But I'll check if that system reduces the lag.

    EDIT: I modified the trigger so that it's possible to construct satellites on several planets (like in the original trigger). Now the map starts to megalag and freezes the game before even 10 satellites are trained. Any other ideas ? :)
     
    Last edited: Aug 26, 2010