Need help with counting units, moving like wilderness maps and random

xandor

New Member
Reaction score
0
Sorry for long post :p
I am trying to make a map similar to wilderness survival / troll tribes maps.

Started today and managed to do camp fire, cooking, crafting items, hero selection, random item spawns in regions with max item cap etc. Im surprised how easy it is but since im new to this im sure my solutions isnt the best.

Havent read the leak thread yet but will do once i get the hang on this so im not that concerned about leaks atm.


But i wonder, is it any better way to do random than to do like this:
RandomVariable = random(1-10)
if(RandomVariable = 1) do stuff
if(RandomVariable = 2)...

And more importmantly about the animals. How my spawning is right now(dunno how you write triggers on forum):
Event
Time - 10
Action
if(VariableAnimalCountRegion1 < 3)
Spawn animal
VariableAnimalCountRegion1 += 1

Event
Unit - dies
Action
{TempAnimalCountRegion1 = 0
Unit Group - Pick every unit in AnimalRegion1 and do actions
loop
{ Set TempAnimalCountRegion1 += 1 }
Set AnimalCountRegion1 = TempAnimalCountRegion1}

This works as long as animal stay in region, if they move out if it they keep spawning when any unit die. I tried with a Unit Group variable but i cant get it to work becouse they units is still in the Unit Group when they are dead and dont know how to remove them.

Is it a bad way by going through every unit every time a unit die and every item when a item is going to be spawned? Cant come up with a better solution to know where spawns is needed yet.

So my questions:
1. Is it any better way to ranomize what is gonna spawn or drop than i do?

2. What better solutions could i do for animals that spawn?

3. And also how can i get animals to move similar to how they move in wilderness survival and troll tribes? Wolfs i think i can use a attack move every now and then to random locations near the wolf.
Do i get right behaviour with Neutral Hostile, Neutral Victim, Neutral Extra and Neutral Passive? Havent tried what they do, only tried Hostile.
Or do i write in trigger that when a animal get attacked, if it is a animal that is afraid make it move to a position nearby? Or any other way?
 

Chilling

New Member
Reaction score
1
To help you get more answers, here is how you copy your triggers more readably onto the forum:
1. Find the trigger you want to copy
2. Click on the trigger. Above the 'Events' of the trigger will be the name of the trigger. Right click on that and click 'Copy As Text'
3. When Editing your post, click on the 'WC3 GUI Tags' button (it's a lower-case 'a' like the world editor icon for trigger editor)
4. Paste your trigger into the WC3 tags that should've been created from the WC3 GUI Tags button.
Now it'll show up properly with little to no work.
Good luck!
 

Ayanami

칼리
Reaction score
288
1) Well, for your random part, maybe you might want to use a bigger number. For example:

Trigger:
  • Set RandomInt = (Random integer between 1 and 100)


Imagine this as 1% to 100%.

Then, possibly you want a 10% chance, then:

Trigger:
  • RandomInt Less than or equal to 10.


Then let's say you want another 10%. Then:

Trigger:
  • RandomInt Less than or equal to 20
    • RandomInt Greater than 11


Something like that., I think would be better.

2) Use a unit group, like you previously did. When units die, they do remain in the unit group. What you could do is to force remove it from the unit group by using:

Trigger:
  • Unit Group - Remove Unit


Just remove the units upon death, like this:

Trigger:
  • Remove Spawn Group
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in SpawnGroup) Equal to true
    • Actions
      • Unit Group - Remove (Triggering unit) from SpawnGroup


That would do just fine.

3) About your wolves, you could make it attack-move to a random location in the map. Well, Neutral Hostile basically units basically attack any player's unit in sight, set aside for Neutral Passive and their own units. I don't think they roam around the map though, you'll need a trigger for that.

As for animals running away, if wolves can't kill the animals, then just put them in Neutral Hostile. Either you can 1) Make a trigger that causes animals to run when attacked or 2) Just don't give the animal any attack (which most probably you won't). This will cause them to run away automatically when attacked as they cannot attack back.
 

xandor

New Member
Reaction score
0
Thank you for replys.

Implemented it and works great. Managed to get units to roam around also :)

I tried to optimize it also, can you tell me how you think it is?
Unit groups
Points
Units (that isnt used for anything anymore)
Special Effects
Mainly said those in the optimization thread. I optimized all points. Gotta remove select hero units and doodads near them after some gametime have passed i think. Other than that i can only think of Unit Groups but not sure how to do with them. Think i should just make a temp group when i loop through them and if i do any action on them instead of the real group.


Item Spawn, spawns items at random places in the region
Trigger:
  • Item Spawn
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Point = (Random point in Item Spawn Zone &lt;gen&gt;)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemCountRegion1 Less than 5
        • Then - Actions
          • Set RandomInt = (Random integer number between 1 and 15)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomInt Less than or equal to 5
            • Then - Actions
              • Item - Create Tinder at Temp_Point
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (RandomInt Greater than 5) and (RandomInt Less than or equal to 10)
                • Then - Actions
                  • Item - Create Stick at Temp_Point
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (RandomInt Greater than 10) and (RandomInt Less than or equal to 15)
                    • Then - Actions
                      • Item - Create Flint at Temp_Point
                    • Else - Actions
          • Set ItemCountRegion1 = (ItemCountRegion1 + 1)
        • Else - Actions
      • Custom script: call RemoveLocation (udg_Temp_Point)


Animal Spawns Think i leak on Unit Groups here, not sure how i should change it though. Every 10 second a random wolf out of 3 different spawn.
Trigger:
  • Animal Spawn
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Point = (Random point in Animal Spawn Zone &lt;gen&gt;)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AnimalCountRegion1 Less than 3
        • Then - Actions
          • Set RandomInt = (Random integer number between 1 and 15)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomInt Less than or equal to 5
            • Then - Actions
              • Unit - Create 1 Timber Wolf for Neutral Hostile at Temp_Point facing Default building facing degrees
              • Unit Group - Add (Last created unit) to UnitGroupRegion1
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (RandomInt Greater than 5) and (RandomInt Less than or equal to 10)
                • Then - Actions
                  • Unit - Create 1 Giant Wolf for Neutral Hostile at Temp_Point facing Default building facing degrees
                  • Unit Group - Add (Last created unit) to UnitGroupRegion1
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (RandomInt Greater than 10) and (RandomInt Less than or equal to 15)
                    • Then - Actions
                      • Unit - Create 1 Dire Wolf for Neutral Hostile at Temp_Point facing Default building facing degrees
                      • Unit Group - Add (Last created unit) to UnitGroupRegion1
                    • Else - Actions
          • Set AnimalCountRegion1 = (AnimalCountRegion1 + 1)
        • Else - Actions
      • Custom script: call RemoveLocation (udg_Temp_Point)


Roaming animals I think these also leak at Unit Group. Every 5 sec they have a 50% chance each of moving to a random location between -300 to 300 x and y away.
Trigger:
  • Animal Movement
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in UnitGroupRegion1 and do (Actions)
        • Loop - Actions
          • Set RandomInt = (Random integer number between 1 and 10)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomInt Greater than 5
            • Then - Actions
              • Set Temp_Point = ((Position of (Picked unit)) offset by ((Random real number between -300.00 and 300.00), (Random real number between -300.00 and 300.00)))
              • Unit - Order (Picked unit) to Attack-Move To Temp_Point
            • Else - Actions
          • Custom script: call RemoveLocation (udg_Temp_Point)
 

Ayanami

칼리
Reaction score
288
Unit Groups only leak when you set the unit group variable then set it to another variable before removing the group. Here's an example:

Trigger:
  • Actions
    • Set TempGroup = Units in MyRegion
    • Set TempGroup = Units in AnotherRegion &lt;-- Leaks


To fix this leak, you do this:

Trigger:
  • Actions
    • Set TempGroup = Units in MyRegion
    • call DestroyGroup(udg_TempGroup)
    • set TempGroup = Units in AnotherRegion &lt;-- Leak safe


However, in your case, you simply added units to the unit group. That doesn't cause any leaks. However, just beware that if you remove a unit that's inside a unit group before removing it from the unit group, it'll cause a leak. For example:

Trigger:
  • Actions
    • Set MyUnit = SomeUnit
    • Unit Group - Add MyUnit to TempGroup &lt;-- No leak here
    • Unit - Remove MyUnit from the game &lt;-- Leaks


If I'm not wrong, the removal of the unit will cause a "shadow reference" in the unit group. Thus, you do this:

Trigger:
  • Actions
    • Set MyUnit = SomeUnit
    • Unit Group - Add MyUnit to TempGroup &lt;-- No leak here
    • Unit Group - Remove MyUnit from TempGroup &lt;-- Removed MyUnit from group
    • Unit - Remove MyUnit from the game &lt;-- Leak safe


Hope that explains unit groups. Your final trigger leaks apoint:

Trigger:
  • Actions
    • Set Temp_Point = ((Position of (Picked unit)) offset by ((Random real number between -300.00 and 300.00), (Random real number between -300.00 and 300.00)))


Should be:

Trigger:
  • Actions
    • Set Temp_Point = (Position of (Picked unit))
    • Set Temp_Offset = (Temp_Point offset by ((Random real number between -300.00 and 300.00), (Random real number between -300.00 and 300.00)))
 

HydraRancher

Truth begins in lies
Reaction score
197
For randoming, you don't need to greater than a number AND less than a number if you have already filtered out the options.

Example:

You have a random number 1-30

You feed it through a condition:

Less than or equal to 5

It comes out negative. Now the possible numbers it could be are 6-30.

So you can simply run it through only 1 condition.

Less than or equal to 10

And so on.


Saves time. :)
 

xandor

New Member
Reaction score
0
Thanks for replys, they helped. Fixed the memory leak and will fix my randoms to 1 condition each soon.

I got some more things i been thinking about.

How do i make it possible to attack a tree only when i got a axe equipped?

Attack 1 targets allowed - Tree
That one allows me to attack tree but i cant find anything to set it in triggers or to give it as a property of a weapon.

I could probably make a ability "Cut Tree" and allow that ability to hit trees but not the unit itself and then only allow that ability to be used if a axe is in inventory, but im sure its better ways to do it.

And will reducing health, mana over time be like this (gotta try it soon):
Event
Time - every 10.0 sec
Action
set variable = current health
variable -= decrease value
set health = variable

Havent found how to make recipe shops where you can look what is needed to craft a item also. Think i know all except for where to put the requirements for the items. Like Camp Fire = tinder flint stick, but i dunno where to say it is those 3 items.
 

Ayanami

칼리
Reaction score
288
How do i make it possible to attack a tree only when i got a axe equipped?

Attack 1 targets allowed - Tree
That one allows me to attack tree but i cant find anything to set it in triggers or to give it as a property of a weapon.

I could probably make a ability "Cut Tree" and allow that ability to hit trees but not the unit itself and then only allow that ability to be used if a axe is in inventory, but im sure its better ways to do it.

You can't set attack property by triggers. Well, yes, the Cut Tree ability would work. I think there's an item ability that changes your Attack 1 to Attack 2.

And will reducing health, mana over time be like this (gotta try it soon):
Event
Time - every 10.0 sec
Action
set variable = current health
variable -= decrease value
set health = variable

You'll need to refer to a unit of course.

Havent found how to make recipe shops where you can look what is needed to craft a item also. Think i know all except for where to put the requirements for the items. Like Camp Fire = tinder flint stick, but i dunno where to say it is those 3 items.

Recipe items require a Recipe System. Basically, you'll need to use a trigger to check if you have all the required items and the recipe in the inventory. If you have it, then the trigger will remove the items and give you the new item. Try use the Search function to find a recipe system. You can input item details in the "Tooltip" area of the item.
 

xandor

New Member
Reaction score
0
Gotta see if i can set attack 2 to cut trees and attack 1 to not do it then, and activate it with item.


Refer to a unit about decreasing health / mana you mean i will do like this?
set variable = specific unit current health
variable -= decrease value
set specific unit health = variable

Just didnt write it. Think i have to store the heroes everyone pick for this in some way though. But think i can do it at the Select Hero trigger.


I made a recipe system myself so i can craft Camp Fire, Armory and axe right now. But i dont know how to show what is required. So it works but i cant show the user what they need to have in inventory to craft.
 

Ayanami

칼리
Reaction score
288
Refer to a unit about decreasing health / mana you mean i will do like this?
set variable = specific unit current health
variable -= decrease value
set specific unit health = variable

Just didnt write it. Think i have to store the heroes everyone pick for this in some way though. But think i can do it at the Select Hero trigger.

You could add units that need to have their health/mana decreased in a unit group. Then do this:

Trigger:
  • Periodic
    • Events
      • Time - Every 10.00 seconds of game-time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in DecreaseGroup and do (Actions)
        • Loop - Actions
          • Set DecreaseValue = 20.00
          • Unit - Set life of (Picked unit) to (((Current life) of (Picked unit)) - DecreaseValue)


I made a recipe system myself so i can craft Camp Fire, Armory and axe right now. But i dont know how to show what is required. So it works but i cant show the user what they need to have in inventory to craft.

Use the "Tooltip" on your items?
 

xandor

New Member
Reaction score
0
Yes, that sounds good.

I can use the tooltip also, just tried messing around with it abit more and using tooltip it looks different than how i usually see it, normally its more like its a requirement to buy (even though you wont buy it from there just look) not just a text. But just a text works equally good i think.
 

xandor

New Member
Reaction score
0
Couldn't you just make an ability off Eat Tree without the Heal?
I wasnt able to make axe work yet with attack button. If i use Eat Tree ability it will be same as the other idea i was thinking about right? I make a ability and when its cast a trigger check if a axe is in inventory and if so it attacks the tree, right? Or will i use that one differently?



Got another problem. When the player choose which hero it wants i want to send player 1-4 to region 1, player 5-8 to region 2 and player 9-12 to region 3.

Something is wrong with this. The hero always spawn in the first region even if its not in the first team. I think the game always thinks im player one.

Trigger:
  • Select Hero 1 Alchemist
    • Events
      • Unit - A unit enters Hero 1 Alchemist &lt;gen&gt;
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Select A Hero
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Equal to Player 1 (Red)) or ((Owner of (Triggering unit)) Equal to Player 2 (Blue))
        • Then - Actions
          • Set Temp_Point = (Center of Spawn Team 1 &lt;gen&gt;)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Equal to Player 3 (Teal)) or ((Owner of (Triggering unit)) Equal to Player 4 (Purple))
        • Then - Actions
          • Set Temp_Point = (Center of Spawn Team 1 &lt;gen&gt;)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Equal to Player 5 (Yellow)) or ((Owner of (Triggering unit)) Equal to Player 6 (Orange))
        • Then - Actions
          • Set Temp_Point = (Center of Spawn Team 2 &lt;gen&gt;)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Equal to Player 7 (Green)) or ((Owner of (Triggering unit)) Equal to Player 8 (Pink))
        • Then - Actions
          • Set Temp_Point = (Center of Spawn Team 2 &lt;gen&gt;)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Equal to Player 9 (Gray)) or ((Owner of (Triggering unit)) Equal to Player 10 (Light Blue))
        • Then - Actions
          • Set Temp_Point = (Center of Spawn Team 3 &lt;gen&gt;)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Equal to Player 11 (Dark Green)) or ((Owner of (Triggering unit)) Equal to Player 12 (Brown))
        • Then - Actions
          • Set Temp_Point = (Center of Spawn Team 3 &lt;gen&gt;)
        • Else - Actions
      • Unit - Create 1 Alchemist for (Owner of (Entering unit)) at Temp_Point facing Default building facing degrees
      • Unit Group - Add (Last created unit) to StatDecreaseUnitGroup
      • Unit - Remove (Entering unit) from the game
      • Custom script: call RemoveLocation (udg_Temp_Point)
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Your triggering is kinda messy, why don't you use
Trigger:
  • Or - Any (Conditions) are true
instead of normal Or conditions?

And you should use If/Then/Else If/Then/Else , as in you place each If/Then/Else function at the Else Actions of the previous one, like this:
Trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • Then - Actions
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
        • Then - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
            • Else - Actions


Are you always playing as Player 1? Did you try setting a few computer players instead?
 

xandor

New Member
Reaction score
0
Dunno why i didnt see that OR, ye it is better to use it.

And better to put if/then/else like you said for those ye, since every if doesnt have to run then.


I tried putting me alone at various spots and to put 4 computers in first team and then put myself on 5th spot and try map but didnt work either, i always appear at the first spawn zone when i choose a hero.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
It could be because WC3 always sees you as player 1 in a single player game... Can you ask some friends to test it with you? Or maybe start the map in a Local Area Network game.
 

xandor

New Member
Reaction score
0
Same problem in LAN, didnt try with players only computers but it need to work without players or people will spawn at same area if teams are half full also.
 

Ayanami

칼리
Reaction score
288
Same problem in LAN, didnt try with players only computers but it need to work without players or people will spawn at same area if teams are half full also.

When you test, do you appear red in color? Or do you have the proper color?
 

xandor

New Member
Reaction score
0
Got it to work.

Changed so i dont check on player but instead i check on color.

Trigger:
  • Select Hero 1 Alchemist
    • Events
      • Unit - A unit enters Hero 1 Alchemist &lt;gen&gt;
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Select A Hero
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Color of (Triggering player)) Equal to Red
              • (Color of (Triggering player)) Equal to Blue
              • (Color of (Triggering player)) Equal to Teal
              • (Color of (Triggering player)) Equal to Purple
        • Then - Actions
          • Set Temp_Point = (Random point in AreaLowLevel1 &lt;gen&gt;)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Color of (Triggering player)) Equal to Yellow
                  • (Color of (Triggering player)) Equal to Orange
                  • (Color of (Triggering player)) Equal to Green
                  • (Color of (Triggering player)) Equal to Pink
            • Then - Actions
              • Set Temp_Point = (Center of Spawn Team 2 &lt;gen&gt;)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Color of (Triggering player)) Equal to Gray
                      • (Color of (Triggering player)) Equal to Light Blue
                      • (Color of (Triggering player)) Equal to Dark Green
                      • (Color of (Triggering player)) Equal to Brown
                • Then - Actions
                  • Set Temp_Point = (Center of Spawn Team 3 &lt;gen&gt;)
                • Else - Actions
      • Unit - Create 1 Alchemist for (Owner of (Entering unit)) at Temp_Point facing Default building facing degrees
      • Unit Group - Add (Last created unit) to StatDecreaseUnitGroup
      • Unit - Remove (Entering unit) from the game
      • Custom script: call RemoveLocation (udg_Temp_Point)
 

xandor

New Member
Reaction score
0
Changed my mind, it doesnt work now...

It worked when i tested it before but now its really wierd.

Right now i always get teleported to region 1 even though i got 1 region / team and 3 teams and tried all teams.
Before i got teleported to region 1 after i removed that region entirely for the trigger... So it kinda remembered that it was there before and still teleported me there.
It also put me at random position when i had center...

Got no idea why it is messing with me so much.


Actually working now again, changed to:
Trigger:
  • (Color of (Owner of (Entering unit))) Equal to Red


And the program acting so wierd was just becouse it didnt run with latest changes. Didnt save before running.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top