• 🏆 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!

How to count buildings

Status
Not open for further replies.
Level 6
Joined
Oct 25, 2010
Messages
203
Im trying to make a trigger that goes something like:

If player 1 has no buildings than make Player 3 building (X) vulnerable
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
  • Count Units
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units owned by Player 1 (Red) matching (((Matching unit) is A structure) Equal to True))) Equal to 0
        • Then - Actions
        • Else - Actions
Keep in mind that you have to destroy unit groups to prevent leaks: Things That Leak
 
Level 14
Joined
Mar 11, 2017
Messages
587
Just a pun.

From things that leak:
base.gif
Trigger
  • joinminus.gif
    events.gif
    Events
    • line.gif
      joinbottom.gif
      if.gif
      Event
  • joinminus.gif
    cond.gif
    Conditions
    • line.gif
      joinbottom.gif
      cond.gif
      Conditions
  • joinbottomminus.gif
    actions.gif
    Actions
    • empty.gif
      join.gif
      page.gif
      Custom script: set bj_wantDestroyGroup = true
    • empty.gif
      joinbottom.gif
      unitgroup.gif
      Unit Group - Pick every unit in (Playable Map Area) and do (Unit - Hide (Picked unit))

set bj_wantDestroyGroup = true
is the leak solver for unit groups and you have to write it before you even create the group.
 
Level 18
Joined
Nov 21, 2012
Messages
835
hey severed
much lighter is this solution:
put in map header in "Custom Script Code" section:
native GetBuilding takes player p returns unit
this native returns last buildings preplaced/constructed for given player, if returns null, that means player has no structures

to check if player red has no buildings use something like this trigger
  • CheckPlayerRedBuildings
    • Events
    • Conditions
    • Actions
      • Custom script: if GetBuilding(Player(0))==null then
      • -------- -------------- --------
      • -------- means player red has no buildings (also no buildings under construction) --------
      • -------- do your actions here --------
      • -------- -------------- --------
      • Custom script: endif
 
Level 6
Joined
Oct 25, 2010
Messages
203
i put "native GetBuilding takes player p returns unit" into the map header/custom script

I added "Custom script: if GetBuilding(Player(0))==null" then but does 0=1? and 1=player2?
then I add Custom script: endif

but does that mean I should get rid of the suggestions from Cuore? they seem to be working so I dont want to mess anything up
 
Level 6
Joined
Oct 25, 2010
Messages
203
  • Count Units
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units owned by Player 1 (Red) matching (((Matching unit) is A structure) Equal to True))) Equal to 0
          • (Number of units in (Units owned by Player 2 (Blue) matching (((Matching unit) is A structure) Equal to True))) Equal to 0
        • Then - Actions
          • Unit - Remove Invulnerable (Neutral) from Resurrection Stone (Team 1) 0273 <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units owned by Player 4 (Purple) matching (((Matching unit) is A structure) Equal to True))) Equal to 0
          • (Number of units in (Units owned by Player 5 (Yellow) matching (((Matching unit) is A structure) Equal to True))) Equal to 0
        • Then - Actions
          • Unit - Remove Invulnerable (Neutral) from Resurrection Stone (Team 2) 0274 <gen>
        • Else - Actions
Keep in mind that you have to destroy unit groups to prevent leaks: Things That Leak

this is the trigger I started with^ based on what Jampion suggested

then I created a new trigger for this:
From things that leak:
is the leak solver for unit groups and you have to write it before you even create the group.

  • Custom script: set bj_wantDestroyGroup = true
  • empty.gif
    joinbottom.gif
    unitgroup.gif
    Unit Group - Pick every unit in (Playable Map Area) and do (Unit - Hide (Picked unit))
At this point^ everything is working fine


So if I am going to switch it over to ZiBitheWand3r3r suggestion, should I erase the trigger with bj_wantDestroyGroup??

Also do I replace (Number of units in (Units owned by Player 1 (Red) matching (((Matching unit) is A structure) Equal to True))) Equal to 0
with Custom script: if GetBuilding(Player(0))==null or do I keep both?? and is 0 = player 1? so 1 = player2?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
So if I am going to switch it over to ZiBitheWand3r3r suggestion, should I erase the trigger with bj_wantDestroyGroup??
Yes, you can just use the trigger ZiBitheWand3r3r posted. In between the two custom scripts you can do your actions, as he said.

Also do I replace (Number of units in (Units owned by Player 1 (Red) matching (((Matching unit) is A structure) Equal to True))) Equal to 0
with Custom script: if GetBuilding(Player(0))==null or do I keep both?? and is 0 = player 1? so 1 = player2?
Player(x)=Player x+1, so yes Player(0) = Player 1

You can't put custom script as a condition into an if-block. As you need two conditions you can either use two conditions or use the keyword "and".

  • Count Units
    • Events
    • Conditions
    • Actions
      • -------- Use "and" --------
      • Custom script: if ( GetBuilding(Player(0))==null and GetBuilding(Player(1))==null ) then
      • Unit - Remove Invulnerable (Neutral) from Resurrection Stone (Team 1) 0273 <gen>
      • Custom script: endif
      • -------- Or use two if-conditions --------
      • Custom script: if ( GetBuilding(Player(3))==null ) then
      • Custom script: if ( GetBuilding(Player(4))==null ) then
      • Unit - Remove Invulnerable (Neutral) from Resurrection Stone (Team 2) 0274 <gen>
      • Custom script: endif
      • Custom script: endif
 
Level 6
Joined
Oct 25, 2010
Messages
203
i just screwed up all my triggers by adding this line

Custom script: if ( GetBuilding(Player(0))==null

it disabled like 5 different things idk why... :(

I deleted it, I think everything went back to normal (i hope)
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
you forgot the closing bracket ")" and the keyword "then"
It has to be "if ( GetBuilding(Player(0))==null ) then"
Look at my trigger above and make sure that your custom scripts are looking like mine.
Alos make sure that "native GetBuilding takes player p returns unit" is in the map header.
 
Level 6
Joined
Oct 25, 2010
Messages
203
you forgot the closing bracket ")" and the keyword "then"
It has to be "if ( GetBuilding(Player(0))==null ) then"
Look at my trigger above and make sure that your custom scripts are looking like mine.
Alos make sure that "native GetBuilding takes player p returns unit" is in the map header.
Ok i double checked everything and now it says:

Script Errors
Line 2576: Expected end of Line

//***************************************************************************
//*
//* Custom Script Code
//*
//***************************************************************************
native GetBuilding takes player p returns unit
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
You need a world editor that uses JassHelper.
You probably want to get SharpCraft World Editor Extended Bundle

From the JassHelper manual:
Native declaration Freedom
This feature (added in 0.9.I.0) is similar to global declarations, but it is for more advanced users, so if you do not understand a single thing of these few paragraphs, feel free to skip to the explanation about the debug keyword. Warcraft III supports declaration of natives in the map script, but it requires the natives to be declared just after the script's globals section. Jasshelper will detect these declarations along the map and move them to the correct place.

Why would you want to do this? And what native functions exactly? There are some few native functions that were created for AI scripts that are not declared in common.j, some of them are actually useful for Jass maps. There is also the possibility you are using a modded/hacked version of warcraft III, and importing a whole new common.j for the native functions is probably too annoying for you, in this case you can declare the new custom functions in the map as well.

There is a protection in this feature that will make jasshelper delete declarations of duplicate natives. (i.e if the native was already declared in common.j, it will remove the native from the map script, to ensure your map is actually playable). This heavily depends on the common.j version provided to jasshelper. This is something to consider if for some reason the common.j version you (or newgen pack) is passing to jasshelper is different to the common.j version you intend the map to be playable with.
 
Level 6
Joined
Oct 25, 2010
Messages
203
I saw that the other day, been reading somethings, so much to learn :( I'll try that sharpeditor later, but for now ill stick with my original triggers.

Thanks, I'll post again if the time comes :)
 
Level 14
Joined
Mar 11, 2017
Messages
587
Well, I didn't even know that GetPlayerStructureCount(PLAYER, BOOL) existed. XD
It's indeed perfect for this job. Big Thank you to Zibi and Jampion for helping triggernoobs out :)

  • ExampleTrigger
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Count structures controlled by Player 1 (Red) (Include incomplete structures)) Equal to 0
          • (Count structures controlled by Player 2 (Blue) (Include incomplete structures)) Equal to 0
        • Then - Actions
          • Unit - Remove Invulnerable (Neutral) from Resurrection Stone (southeast facing) 0000 <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Count structures controlled by Player 4 (Purple) (Include incomplete structures)) Equal to 0
          • (Count structures controlled by Player 5 (Yellow) (Include incomplete structures)) Equal to 0
        • Then - Actions
          • Unit - Remove Invulnerable (Neutral) from Resurrection Stone (southwest facing) 0001 <gen>
        • Else - Actions
 
Last edited:
Status
Not open for further replies.
Top