Custom script leak removal for an array

Weyird

Member
Reaction score
5
Hi there,
I'm making a map involving the control of very large numbers of units and to make things easier for players I've handily supplied them with a "Game Controls" unit that has abilities to select all the units in an area into a custom unit-group, and then other abilities will be used to command the units in this unit-group.
But to remove leaks I need to destroy the unit group every time the player uses the ability to set a new one.. But it's an array, with one for each player.

A GUI trigger doing what I need would look something like:
Event:
Unit uses selection ability
Action:
For each intiger from 1 to (number of players)
- if player (player number [loop intiger value]) = player number (owner of triggering unit) then:
- - Custom script destoy Player_Selection[player number of (owner of triggering unit)]
- - set Player_Selection[player number of (owner of triggering unit)]: the new group


So how would the script look like for that bit in bold?
 

Romek

Super Moderator
Reaction score
963
[ljass]call DestroyGroup(udg_Player_Selection[GetPlayerId(GetOwningPlayer(GetTriggerUnit())) + 1])[/ljass]
 

NeuroToxin

New Member
Reaction score
46
to Efficienize what Romek said (Efficienize? Nice huh) Instead of GetOwningPlayer(GetTriggerUnit()) You can just use GetTriggerPlayer()
 

Weyird

Member
Reaction score
5
WorldEditor is alerting me that both of those have errors :(
It says it expected a name
 

Weyird

Member
Reaction score
5
OK oops, found my mistake. I Just copied&paste the previously pro-offered script, but didnt notice the variable was PlayerSelection not Player_Selection

Here's the relevant part of the trigger anyway, just to make sure if it'll work:

Trigger:
  • Game Controls
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • -------- Select all in 700 AoE --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Select Units
        • Then - Actions
          • Unit Group - Pick every unit in PlayerSelection[(Player number of (Owner of (Triggering unit)))] and do (Unit Group - Remove (Picked unit) from PlayerSelection[(Player number of (Owner of (Triggering unit)))])
          • Custom script: call DestroyGroup(udg_PlayerSelection[GetPlayerId(GetOwningPlayer(GetTriggerUnit())) + 1])
          • Set temp_Point = (Target point of ability being cast)
          • Set PlayerSelection[(Player number of (Owner of (Triggering unit)))] = (Units within 700.00 of temp_Point matching ((((Matching unit) is A structure) Not equal to True) and ((Owner of (Matching unit)) Equal to (Owner of (Triggering unit)))))
          • Custom script: call RemoveLocation(udg_temp_Point)
        • Else - Actions


I removed every unit from the group as well... I'm not sure if that is neccessary or if it'll just cause unneeded lag?
 

Laiev

Hey Listen!!
Reaction score
188
you don't need to remove every unit from a group... just destroy it and its ok
 
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