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

Create "Wild Grass" like in pokemon with random encounters?

Status
Not open for further replies.
Level 5
Joined
Feb 5, 2021
Messages
89
Hello there everybody

I posted my 2 "somewhat" working triggers down below.
What i want to achieve is like the feeling of pokemon wild grass where you click and randomly move within this area and then at random "clicks!" or "intervals (while moving only)" to sometimes hit a "random encounter" which in this case is like a bandit attack (dont mind the mobs not being bandits).

also the random encounters can only happen while the "Party" mob is moving so that the party is safe while not on the move.

The ones i have here sort of works, but the issue i get with these are the fact that if i end up clicking the smart move button hella fast (as many people playing wc3 does) it sometimes loop the effect so when the "Party" mob is unpaused it instantly triggers another encounter and this can happen like 5 times in a row before i get to actively move the "Party" mob again :)

Any ideas, improvements and fixes are appreciated!

  • Zone1HostileCritter
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Unit-type of (Ordered unit)) Equal to Party
      • (Issued order) Equal to (Order(smart))
    • Actions
      • Set VariableSet RandomEncounterRoller = (Random integer number between 1 and 10)
      • Trigger - Run Zone1HostileCritterFight <gen> (checking conditions)
  • Zone1HostileCritterFight
    • Events
    • Conditions
      • RandomEncounterRoller Less than 5
    • Actions
      • Set VariableSet Zone1EncounterUnits = (Units in Zone1EncounterArea <gen>)
      • Unit Group - Pick every unit in Zone1EncounterUnits and 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 Neutral Hostile
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
      • Item - Pick every item in Zone1EncounterArea <gen> and do (Actions)
        • Loop - Actions
          • Item - Remove (Picked item)
      • Custom script: call DestroyGroup(udg_Zone1EncounterUnits)
      • Wait 0.10 seconds
      • Set VariableSet RandomEncounterRoller = 0
      • Unit - Pause PartyBus
      • Trigger - Turn on OrderToFight <gen>
      • Trigger - Turn on Zone1Treasuree <gen>
      • Unit - Create ((Random integer number between 0 and 2) + (NumberOfPlayers / 2)) Wisp for Neutral Hostile at Zone1BottomLeftSpawn facing Default building facing degrees
      • Unit - Create ((Random integer number between 0 and 2) + (NumberOfPlayers / 2)) Wisp for Neutral Hostile at Zone1TopLeftSpawn facing Default building facing degrees
      • Set VariableSet Zone1EncounterUnits = (Units in Zone1EncounterArea <gen>)
      • Unit Group - Pick every unit in Zone1EncounterUnits and 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 Neutral Hostile
            • Then - Actions
              • Set VariableSet Zone1MobCount = (Zone1MobCount + 1)
              • Game - Display to (All players) the text: (Mobs Left To Kill + (String(Zone1MobCount)))
            • Else - Actions
      • Custom script: call DestroyGroup(udg_Zone1EncounterUnits)
      • Wait 0.10 seconds
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Unit - Move PlayerHero[(Player number of (Picked player))] instantly to Zone1PCSpawn
          • Camera - Pan camera for (Picked player) to Zone1PCSpawn over 0.00 seconds
          • Selection - Select PlayerHero[(Player number of (Picked player))] for (Picked player)
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
When a random encounter is started, set a boolean variable equal to true; when the encounter is finished (because the units are all dead or whatever), set that variable back to false. Add a condition to your first trigger that the boolean variable is not equal to true. You could make the boolean an array if it needs to work for multiple players.

There's no reason these need to be separate triggers when one of them just directly runs the other. You could use an If statement instead of the 'run trigger checking conditions'. If you want to generalize these actions to run different things from the same base trigger (say for different zones or different levels of difficulty) then I could see a use case for running other triggers in a trigger array or something.
 
Level 5
Joined
Feb 5, 2021
Messages
89
Ohh right! that sounds like a really good way to fix it! :O :D
Can this also "check" what region it is triggered in?

Also i made separate triggers because i want different levels, regions and difficulties so i thought having different triggers for different purposes might be best but honestly i dont actually know what would be the smartest :)
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
Can this also "check" what region it is triggered in?
Yes, as long as you store this information when the successful encounter roll occurs. AFAIK it'll have to be kinda silly by checking if the given order point (or position of the Party unit or whatever) is in each of the regions individually (until it checks and finds that it's true, at which point it can stop checking the rest of them). There is no "tell me what region(s) this point is in" action. In this case I would use a region array and loop over the array to check them all rather than making a stupidly long If/Then/Else tree.
 
Level 5
Joined
Feb 5, 2021
Messages
89
Yes, as long as you store this information when the successful encounter roll occurs. AFAIK it'll have to be kinda silly by checking if the given order point (or position of the Party unit or whatever) is in each of the regions individually (until it checks and finds that it's true, at which point it can stop checking the rest of them). There is no "tell me what region(s) this point is in" action. In this case I would use a region array and loop over the array to check them all rather than making a stupidly long If/Then/Else tree.
That does indeed feel silly but it sounds alot like the exact thing that i am looking for! I will try this next time i open it! Thanks you! :D
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
What I would do is use something like this to detect movement: Is Unit Moving 2.1.0.0

Then periodically check the terrain at the position of the moving unit or use regions and determine an encounter based on that.
These pokemon/final fantasy types of games use a step counter rather than rolling dice constantly to determine whether an encounter happens.
So when you first enter the tall grass you would do an initial dice roll to determine how many "steps" are needed until an encounter happens and then from that point on you count each step taken until this number is met.

Upon first entering the tall grass:
  • Set Variable StepsNeeded = Random integer number between 1 and 12
Then as you're moving inside the tall grass:
  • Set Variable StepsTaken = StepsTaken + 1
And after increasing StepsTaken check if you've taken enough steps for an encounter to happen:
  • If StepsTaken is Greater than or Equal to StepsNeeded then...
If the above is true, reset StepsTaken back to 0, re-roll StepsNeeded, set a BattleIsActive boolean as Pyrogasm suggest, and proceed to the battle. Once the battle is over, set BattleIsActive to false and resume proper control to the player.
 
Level 5
Joined
Feb 5, 2021
Messages
89
What I would do is use something like this to detect movement: Is Unit Moving 2.1.0.0

Then periodically check the terrain at the position of the moving unit or use regions and determine an encounter based on that.
These pokemon/final fantasy types of games use a step counter rather than rolling dice constantly to determine whether an encounter happens.
So when you first enter the tall grass you would do an initial dice roll to determine how many "steps" are needed until an encounter happens and then from that point on you count each step taken until this number is met.

Upon first entering the tall grass:
  • Set Variable StepsNeeded = Random integer number between 1 and 12
Then as you're moving inside the tall grass:
  • Set Variable StepsTaken = StepsTaken + 1
And after increasing StepsTaken check if you've taken enough steps for an encounter to happen:
  • If StepsTaken is Greater than or Equal to StepsNeeded then...
If the above is true, reset StepsTaken back to 0, re-roll StepsNeeded, set a BattleIsActive boolean as Pyrogasm suggest, and proceed to the battle. Once the battle is over, set BattleIsActive to false and resume proper control to the player.
Alright Alright, this seems like a useful asset, though might be a bit out of comprehension at this current time, i will deffo try to use this at some point, but since i am very weak in coding generally i try to refrain from using to much Jass :)

Thanks for the input!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
Perfect! it just looks alot like Jass when i read it but neat! i might even use it then :D
The system itself is coded in Jass but the creator designed it to be GUI friendly. You don't need to ever look at or edit any of the code, simply follow the instructions provided and look at the example map to see how it's done.
 
Level 5
Joined
Feb 5, 2021
Messages
89
The system itself is coded in Jass but the creator designed it to be GUI friendly. You don't need to ever look at or edit any of the code, simply follow the instructions provided and look at the example map to see how it's done.
Thanks for the clarification, though after having tried to fiddle around with it, i cant seem to make it trigger anything, i am fumbling blindly around, any ideas? :)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
Thanks for the clarification, though after having tried to fiddle around with it, i cant seem to make it trigger anything, i am fumbling blindly around, any ideas? :)
So when you open the demo map look at the Trigger Editor. You'll see two systems, Is Unit Moving and Unit Indexer, don't mess with these.

Instead, focus on the Test folder, which shows examples of how to use the system.

Edit: Check out this map I made. Look at the EXAMPLE folder to see how I used these systems to make a Pokemon wild encounter.
 

Attachments

  • Random Encounter Example 1.w3m
    25.9 KB · Views: 8
Level 5
Joined
Feb 5, 2021
Messages
89
So when you open the demo map look at the Trigger Editor. You'll see two systems, Is Unit Moving and Unit Indexer, don't mess with these.

Instead, focus on the Test folder, which shows examples of how to use the system.

Edit: Check out this map I made. Look at the EXAMPLE folder to see how I used these systems to make a Pokemon wild encounter.
My god! this is incredible! thanks alot! this really helped me out! :D
 
Status
Not open for further replies.
Top