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

Country Checker for Risk

Status
Not open for further replies.
Level 6
Joined
Feb 10, 2011
Messages
188
I need a system that efficiently adjust income for players who control countries in risk and for players that lose countries.

So it would be something like this

Player X controls all command centers in a country
Create a spawning building for Player X
Add income based on number of command center to Player x total income

If Player X no longer owns all bases in the country the game will remove spawn building and remove the income bonus the player received for owning the whole country

Also when a player does take over a country it would be nice to have a message to all players saying Player x took Y country
 

Ardenian

A

Ardenian

This is very easy. You should learn how to do it yourself if you want to become a successful map maker, as this is a very basic of triggering, requiring basically no knowledge about math or complex WE tools.

You need variables. One to count the amount of command centers controlled by players, use an arrayed integer variable for this, using the player number of the triggering player to change the corresponding variable.

ControlledCommmands[Number of Triggering Player] = ControlledCommmands[Nuber of Triggering Player] +/- 1

For income use a periodic loop and add the wished gold or lumber to the player properties, using the ControlledCommands[ARRAY] in the formula.
Use a loop to loop through all players, using the loop variable ( integer) as array for the ControlledCommands[LOOPINTEGER] variable.

The spawn building you create/destroy/remove within the trigger where you set the amount of controlled commands, once it changes.
 
Level 6
Joined
Feb 10, 2011
Messages
188
This is very easy. You should learn how to do it yourself if you want to become a successful map maker, as this is a very basic of triggering, requiring basically no knowledge about math or complex WE tools.

You need variables. One to count the amount of command centers controlled by players, use an arrayed integer variable for this, using the player number of the triggering player to change the corresponding variable.

ControlledCommmands[Number of Triggering Player] = ControlledCommmands[Nuber of Triggering Player] +/- 1

For income use a periodic loop and add the wished gold or lumber to the player properties, using the ControlledCommands[ARRAY] in the formula.
Use a loop to loop through all players, using the loop variable ( integer) as array for the ControlledCommands[LOOPINTEGER] variable.

The spawn building you create/destroy/remove within the trigger where you set the amount of controlled commands, once it changes.

yeah your on the right track but not there.
see i tried doing what u suggested but i get stuck when i have to run the check for multiple countries i don't really want to do the same trigger 30+ times
 

Ardenian

A

Ardenian

Alright, what do we have ?

We have multiple countries.
In each country, there is a certain amount of command centers.
In each country, there is one spawner.

Correct up to here ?

So, that means we create a variable for each country ( if you use regions, then use a region variable, if the 'country' actually has no value in-game, then don't create a variable, but note the numbers for the countries somewhere)

So we have, for example:

Country[1] = A
Country[2] = B
Country[3] = C
(...)

Now, create a unit group variable with an array:

CountryCommands [1] = X
CountryCommands [2] = Y
CountryCommands [3] = Z

X, Y and Z are all command centers belonging to country A, B and C.
Country A has a group of command centers X, for example.

For the spawner, use a new unit variable with array
CountrySpawner[1] = Unit G
(...)

Country A has a group of command centres X and a spawner G.

Now, this is the basic set-up.

---

Now, the events. Note that there are multiple approaches.

my approach would be this:

Periodic event every0.03 seconds

-> Now, loop through every group

Loop Variable from 1 to NUMBER OF COUNTRIES
Pick every unit in CountryCommands[LOOP VARIABLE]

*Now it gets a bit tricky, you have to have a temporary variable for every player, being integer with an array TempInteger[1] and so on, up to the number of players*

Loop Integer variable 2 from 1 to (Count units in CountryCommands[LOOPVARIABLE])

Loop Integer variable 3 from 1 to NUMBER OF PLAYERS
If/Then/Else
If Owner of (Picked Unit) = Player[LOOPVARIABLE3]
Then Set TempInteger[LOOPVARIABE2] = TempInteger[LOOPVARIABE2] +1

If/Then/Else as action of the previous Then
If TempInteger[LOOPVARIABLE2] = (Count units in CountryCommands[LOOPVARIABLE1]
Then
Destroy ( or remove) Spawner[LOOPVARIABLE1]
Create one UNITTYPE SPAWNER for Player[LOOPVARIABLE3]
Set Spawner[LOOPVARIABLE1] = (last created unit)

***

That's it. Don't create the loops one by one, but put them in one block.

Post a trigger, then I say if it is correct.

About income we will think once this is done, income are only a few additional lines in the above shown trigger.
 
Level 6
Joined
Feb 10, 2011
Messages
188
We have multiple countries.
In each country, there is a certain amount of command centers.
In each country, there is one spawner.

yes that is correct, Id like the spawner to only appear when a player owns a country and destroyed when they no longer own it

Ok I think im doing something wrong because it doesn't seem to work. I already have a trigger I use to set countries. It works similar to what you suggested. Here is what I use to set countries
  • Set Countries
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set countryArea1[1] = Morocco <gen>
      • Set countryName[1] = Morocco
      • Set countrySpawn[1] = Region 004 <gen>
      • -------- ------------------------- --------
      • Set countryArea1[2] = Algeria <gen>
      • Set countryName[2] = Algeria
      • Set countrySpawn[2] = Region 005 <gen>
      • -------- ------------------------- --------
      • Set countryArea1[3] = Malta <gen>
      • Set countryName[3] = Malta
      • Set countrySpawn[3] = Region 006 <gen>
      • -------- ------------------------- --------
      • For each (Integer B) from 1 to 3, do (Actions)
        • Loop - Actions
          • Unit Group - Add all units of (Units in countryArea1[B] matching ((Owner of (Matching unit)) Equal to Neutral Hostile)) to countryRegions[B]
          • Unit Group - Add all units of (Units in countryArea2[B] matching ((Owner of (Matching unit)) Equal to Neutral Hostile)) to countryRegions[B]
          • Set countryCityCount[B] = (Number of units in countryRegions[B])
          • Set tempPoint1 = (Center of countrySpawn[B])
          • Set tempPoint2 = (tempPoint1 offset by (-85.00, -125.00))
          • Floating Text - Create floating text that reads (|cFFFF0303 + (countryName[B] + |r)) at tempPoint2 with Z offset 0.00, using font size 13.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: set udg_tempPoint1 = null
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempPoint2 = null
      • Custom script: call DestroyTrigger( GetTriggeringTrigger() )

Here is the loop Trigger I tried to follow your instructions while still using my already made trigger

  • Check Countries
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in countryRegions[A] and do (Actions)
            • Loop - Actions
              • For each (Integer B) from 1 to (Number of units in countryRegions[A]), do (Actions)
                • Loop - Actions
                  • For each (Integer C) from 1 to (Number of players in (All players matching (((Player(C)) slot status) Equal to Is playing))), do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of (Picked unit)) Equal to (Player(C))
                        • Then - Actions
                          • Set tempInt2[B] = (tempInt2[B] + 1)
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • tempInt2[B] Equal to (Number of units in countryRegions[A])
                            • Then - Actions
                              • Unit - Create 1 Farm for (Player(C)) at (Center of countrySpawn[A]) facing Default building facing degrees
                              • Set countrySpawnBuilding[A] = (Last created unit)
                            • Else - Actions
                        • Else - Actions
 

Ardenian

A

Ardenian

Set countries seems more or less alright.

But, never use any Integer A or Integer B. I learned you should always use variables instead.

Add this in the loop as first actions:

  • Custom script: if udg_countryRegions[udg_YOURLOOPVARIABLENAME] == null then
  • Custom script: set udg_countryRegions[udg_YOURLOOPVARIABLENAME] = CreateGroup()
  • Custom script: endif
For now, deactivate all leak-preventer, to make sure the trigger works, then add them/ re-enable them.

---

For Check Countries:

Same story as for the first trigger, use different loop variables instead of these Integer.

There is an issue:

You pick every command center for every country.
Now you pick every unit in the unit group.
Now you check its owner, but you add +1 to the wrong variable
  • Set tempInt2[B] = (tempInt2[B] + 1)
shouldn't it be
  • Set tempInt2[C] = (tempInt2[C] + 1)
as you want to get the number of units controlled by the player ? B makes no sense.

The rest should be more or less fine, but make sure to create loop variables instead of A or B or C
 
Level 6
Joined
Feb 10, 2011
Messages
188
The Integer loop variables are UDG's I just named them A, B and C. I renamed them to X,Y and Z to make it easier to see. It still doesn't work :/ What did I do wrong? I fixed what you mentioned.
  • Set Countries
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set countryArea1[1] = Morocco <gen>
      • Set countryName[1] = Morocco
      • Set countrySpawn[1] = Region 004 <gen>
      • -------- ------------------------- --------
      • Set countryArea1[2] = Algeria <gen>
      • Set countryName[2] = Algeria
      • Set countrySpawn[2] = Region 005 <gen>
      • -------- ------------------------- --------
      • Set countryArea1[3] = Malta <gen>
      • Set countryName[3] = Malta
      • Set countrySpawn[3] = Region 006 <gen>
      • -------- ------------------------- --------
      • Set countryArea1[4] = Sardinia <gen>
      • Set countryName[4] = Sardinia
      • Set countrySpawn[4] = Region 007 <gen>
      • -------- ------------------------- --------
      • For each (Integer Y) from 1 to 4, do (Actions)
        • Loop - Actions
          • Custom script: if udg_countryRegions[udg_Y] == null then
          • Custom script: set udg_countryRegions[udg_Y] = CreateGroup()
          • Custom script: endif
          • Unit Group - Add all units of (Units in countryArea1[Y] matching ((Owner of (Matching unit)) Equal to Neutral Hostile)) to countryRegions[Y]
          • Unit Group - Add all units of (Units in countryArea2[Y] matching ((Owner of (Matching unit)) Equal to Neutral Hostile)) to countryRegions[Y]
          • Set countryCityCount[Y] = (Number of units in countryRegions[Y])
          • Set tempPoint1 = (Center of countrySpawn[Y])
          • Set tempPoint2 = (tempPoint1 offset by (-85.00, -125.00))
          • Floating Text - Create floating text that reads (|cFFFF0303 + (countryName[Y] + |r)) at tempPoint2 with Z offset 0.00, using font size 13.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: set udg_tempPoint1 = null
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempPoint2 = null
      • Custom script: call DestroyTrigger( GetTriggeringTrigger() )
  • Check Countries
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer X) from 1 to 4, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in countryRegions[X] and do (Actions)
            • Loop - Actions
              • For each (Integer Y) from 1 to (Number of units in countryRegions[X]), do (Actions)
                • Loop - Actions
                  • For each (Integer Z) from 1 to (Number of players in (All players matching (((Player(Z)) slot status) Equal to Is playing))), do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of (Picked unit)) Equal to (Player(Z))
                        • Then - Actions
                          • Set tempInt2[Z] = (tempInt2[Z] + 1)
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • tempInt2[Z] Equal to (Number of units in countryRegions[X])
                            • Then - Actions
                              • Unit - Create 1 Farm for (Player(Z)) at (Center of countrySpawn[X]) facing Default building facing degrees
                              • Set countrySpawnBuilding[X] = (Last created unit)
                            • Else - Actions
                        • Else - Actions
 

Ardenian

A

Ardenian

Things that might be causing it not to work appropriate:

countryArea2[Y] is never set to anything in the Set Countries
Set tempPoint2 = (tempPoint1 offset by (-85.00, -125.00)) will show the text at the same point for every country
It might be not possible to pick Neutral Hostile, try swapping it with a computer player
Set tempInt2[Z] will never be set to 0 after it is not needed anymore

In Set Countries, remove the custom scripts at the end temporarily and see whether it works then.

If it is still not working try to debug the whole thing.
 
Status
Not open for further replies.
Top