• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Two issues, involving handles and unit groups

Status
Not open for further replies.
Level 9
Joined
Dec 6, 2007
Messages
233
I'm designing a framework for a projectile system for a summer project I'm working on. I condensed a large number of small triggers into one huge one to reduce lag, so I'm only going to show an excerpt.

  • Unit Group - Pick every unit in Temp_Unit_Group and do (Actions)
    • Loop - Actions
      • Set Ship = (Picked unit)
      • Set Ship_Handle = (Picked unit)
      • Set Temp_Unit_Loc = (Position of (Picked unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Picked unit)) Equal to Frigate
        • Then - Actions
          • Set Physical_Radius = 100.00
        • Else - Actions
      • Set Temp_Unit_Group2 = (Units in (Playable map area) matching (((Matching unit) is A sapper) Equal to True))
      • Unit Group - Pick every unit in Temp_Unit_Group2 and do (Actions)
        • Loop - Actions
          • Set Projectile = (Picked unit)
          • Set Temp_Unit_Loc2 = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Distance between Temp_Unit_Loc and Temp_Unit_Loc2) - (Load Projectile_Hitbox of (Key (Picked unit)) from Projectile_Hash)) Less than or equal to Physical_Radius
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load (Key armorvalue) of (Key Ship_Handle) from armorhash) Greater than or equal to (Load Projectile_Damage of (Key (Picked unit)) from Projectile_Hash)
                • Then - Actions
                  • Hashtable - Save ((Load (Key armorvalue) of (Key Ship_Handle) from armorhash) - (Load Projectile_Damage of (Key (Picked unit)) from Projectile_Hash)) as (Key armorvalue) of (Key Ship_Handle) in armorhash
                • Else - Actions
                  • Unit - Cause Missile_Unit to damage Ship, dealing ((Real((Load Projectile_Damage of (Key (Picked unit)) from Projectile_Hash))) - (Real((Load (Key armorvalue) of (Key Ship_Handle) from armorhash)))) damage of attack type Spells and damage type Normal
                  • Hashtable - Save 0 as (Key armorvalue) of (Key Ship_Handle) in armorhash
              • Unit - Kill (Picked unit)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc2)
          • Custom script: call DestroyGroup(udg_Temp_Unit_Group)
          • Custom script: call DestroyGroup(udg_Temp_Unit_Group2)
This part of the trigger involves registering if a projectile hits a unit, then calculating where the damage goes. The first issue is that in the latter half of the trigger, I need to reference a hashtable value via a unit handle. However, i cannot simply use "picked unit". So i used a handle variable. I couldn't find a direct way to save a handle to the variable, so i saved "picked unit" to the handle variable (Ship_Handle). Can this be done? Will it work?


Secondly, the trigger never registers a hit. I see no reason why it shouldn't, so that's why I've come here. Let me explain what's going on here:

I draw two circular regions. One around the projectile, and one around the ship. Both regions make up the "size" of their respective object. If the regions overlap, then the objects have collided, and it registers a hit. If a hit is registered, it clacluated damage to armor, then if the armor is gone, it damages the ship. This line of code is what I use to check for overlap:

  • ((Distance between Temp_Unit_Loc and Temp_Unit_Loc2) - (Load Projectile_Hitbox of (Key (Picked unit)) from Projectile_Hash)) Less than or equal to Physical_Radius
Justification: Everything has a size. The bigger the size, the easier it is to hit something with it! It also helps for if you have a massive ship, but the hitbox is still so small that the projectile can go straight through without "hitting".

If anyone has a solution to either issues, help would be greatly appreciated.
 
Yes, Handle variable for "Picked unit" does work. I use it all the time.

If the system is MUI, then you forgot to set the "Missile_Unit" variable and by set I mean define it.

  • Load Projectile_Hitbox of (Key (Picked unit)) from Projectile_Hash)
That could be of (Key(Projectile)), since you've already saved it.

I am pretty sure it's a variable issue (Missile_Unit), but I will also need to ask: is it trully a sapper (the condition you make in the pick unit group action)?
 
Level 9
Joined
Dec 6, 2007
Messages
233
Whoops, didn't see the missile_unit. I took that from another trigger; there used to be one of those for every kind of projectile, I'm reworking it to have one for all to reduce lag. Fixed

Yes, it is a sapper. I have classifications for every kind of unit, and "sapper" is the classification for projectiles.

As for (Key(Projectile)), it won't let me do that. It won't allow (Key(Variable)). Is that unusual?

The issue wasn't that Missile_Unit thing. The projectiles are acting like nothing's there, shooting straight through the ship. Even if it didn't apply damage, if the rest of the trigger worked it would have at least killed the projectile when it hit.

EDIT: Whoops, a line of code got cut off of that trigger in the first post. This came before everything:

  • Set Temp_Unit_Group = (Units in (Playable map area) matching (((Matching unit) is Mechanical) Equal to True))
 
Level 9
Joined
Dec 6, 2007
Messages
233
it's a big-ish map, that trigger i posted is an excerpt from one 5X the size. However, it's only systems, and they are all prototypes, and therefore I have no qualms about letting you see it. I agree that this question is a little, vague, so i'll send it to you. (so far the coding has been one-man, so it isn't documented. Sorry!)

EDIT: probably should tell you that the problem is at the end of the "Projectile Motion" trigger

EDIT2: FIXED, thanks anyways pharaoh_
 
Last edited:
Status
Not open for further replies.
Top