• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

"Region is Already Occupied" boolean?

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi! I'm making a map filled with squares, and players place bombs on squares. When a bomber places a bomb, the bomb is centered on the region the bomber is at. The bombs last about 5 seconds.

I'd like to know how to check if there's already a bomb on the region to avoid having several bombs on the same square.
 
Level 9
Joined
Apr 19, 2011
Messages
447
I think you can check that with an integer condition:

  • (Number of units in [YOUR REGION] matching ((Unit-type of (Matching Unit)) Igual a BOMB))) Not equal to 0
I don't know if that's the best way to check it, but it should work. At least, I think so.

Regards
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
It works, but creates a temp group to handle the thing. That's what I wanted to avoid.

I just solved it checking the distance between the placed bomb and all the other bombs on the Bomb group. If distance is short (less than 512) means the bomb is at the same place, therefore is removed and bla bla.

I was wondering if there was some way of detecting the region the Bomb is placed at, so I can store a true boolean on the region ID to know the region is already occupied, and then set it to false when the bomb explodes, but I think that the only way to detect the triggering region is with "A unit enters" event. Wouldn't work for exploding (dying) bombs (unless I use "A unit leaves region" event, but that would mean having 120 triggers (because i have 120 regions), and one for each (as I have to detec them)...

I don't know if it's better to do the 120 region thing, or if compare the distance with the rest of the bombs on the group (that could be around 30 units, in the worst situation with 10 players placing bombs)
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
How about using Hashtable ?
Save the boolean to the bomb itself.

What Event did you used to spawn the bomb ?
Custom ability or default ?
I suggest default, such as Serpent Ward (you don't need to have TempLoc via this way to place the bomb if you used custom ability such as Channel).

Here is a test map, try it.

It prevents you to further place bomb when it detects another bomb in its presence, does not use Boolean at all.

Logic = Boolean
 

Attachments

  • test17.w3x
    13.1 KB · Views: 39
Level 20
Joined
Jul 14, 2011
Messages
3,213
The ability is Berserk since I don't want to stop unit current action. I don't use Locs anymore :p Pure x/y (thanks God). As you can see, I save the rect on the region ID. When the bomb is created, the trigger detects the unit entering the region, and gets the X/Y of the rect stored on the region ID to center it.

I use a custom function to register all the "A unit enters region" to center the bomb on the region. I'm trying to do the same for "A unit leaves region" but isn't working :(
JASS:
function RR takes rect r returns nothing
    local region reg = CreateRegion()
    call RegionAddRect(reg, r)
    call SaveRectHandle(udg_Hash, GetHandleId(reg), 0, r)
    call TriggerRegisterEnterRegion(gg_trg_Bomb_CenterPlace, reg, null)
endfunction

I'm adding there a "TriggerRegisterLeaveRegion(InitTrig_Bomb_Region_Clear, reg, null)" but isn't working, I don't know why. tested with specific event for one only region, and the trigger detects any unit leaving, but not the bomb. I guess that's because the bomb is inmediatly removed after it dies =/
 
Status
Not open for further replies.
Top