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

Choose Job based on salary and availability [SOLVED]

Level 2
Joined
Jul 13, 2018
Messages
7
Hi! I need help with the following:

Variables:
  • Population (Unit Array)
  • Population Job (String Array), can be set to Lumberjack, Gold Miner, or Farmer
  • Lumberjack Available Positions (Integer Array)
  • Gold Miner Available Positions (Integer Array)
  • Farmer Available Positions (Integer Array)
  • Lumberjack Wage (Real Array)
  • Gold Miner Wage (Real Array)
  • Farmer Wage (Real Array)

I wanted to make a gui system that makes every unit in Population choose the job with the highest wage, if that job has any available positions left. All 3 Wage variables can be modified by the User anytime, so the units in Population should be able to change their job to another job with higher wage, if that job has any available positions.
I don't know how to properly set all the conditions, and the system never works as intended.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
This thread belongs in the World Editor Help Zone forum since you need help getting started. If you had posted your broken triggers/scripts then it'd make more sense to post here. Anyway, it's not a huge deal.

So it sounds like you just need help understanding the math behind it all:
  • Setup Jobs
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- Define the id of our different Job variables: --------
      • Set VariableSet LUMBERJACK = 1
      • Set VariableSet MINER = 2
      • Set VariableSet FARMER = 3
      • -------- --------
      • -------- Define the strings used to represent these Job variables: --------
      • Set VariableSet Job_Strings[LUMBERJACK] = Lumberjack
      • Set VariableSet Job_Strings[MINER] = Miner
      • Set VariableSet Job_Strings[FARMER] = Farmer
      • -------- --------
      • -------- Give these Jobs some random starting values: --------
      • For each (Integer Job) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set VariableSet Job_Positions[Job] = (Random integer number between 1 and 10)
          • Set VariableSet Job_Wages[Job] = (Random real number between 1.00 and 10.00)
          • Game - Display to (All players) for 300.00 seconds the text: ((Job_Strings[Job] + Wages: ) + (String(Job_Wages[Job])))
          • Game - Display to (All players) for 300.00 seconds the text: ((Job_Strings[Job] + Positions: ) + (String(Job_Positions[Job])))
  • Get Highest Paying Job
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Fill an array with all of the available jobs: --------
      • Set VariableSet Job_Count = 0
      • For each (Integer Job) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Job_Positions[Job] Greater than 0
            • Then - Actions
              • Set VariableSet Job_Count = (Job_Count + 1)
              • Set VariableSet Array_Of_Jobs[Job_Count] = Job
            • Else - Actions
      • -------- --------
      • -------- Make sure we actually have at least one job available: --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Job_Count Equal to 0
        • Then - Actions
          • Game - Display to (All players) for 30.00 seconds the text: |cffff0000No jobs a...
          • Skip remaining actions
        • Else - Actions
      • -------- --------
      • -------- Get the job with the highest wage: --------
      • Set VariableSet Highest_Real = 0.00
      • For each (Integer Index) from 1 to Job_Count, do (Actions)
        • Loop - Actions
          • Set VariableSet Job = Array_Of_Jobs[Index]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Job_Wages[Job] Greater than Highest_Real
            • Then - Actions
              • Set VariableSet Highest_Real = Job_Wages[Job]
              • Set VariableSet Job_Winner = Job
            • Else - Actions
      • -------- --------
      • -------- Display this wage and remove this job: --------
      • Game - Display to (All players) for 30.00 seconds the text: (Highest paying job: + Job_Strings[Job_Winner])
      • Set VariableSet Job_Positions[Job_Winner] = (Job_Positions[Job_Winner] - 1)
With these two triggers you can simulate the effect of job positions being taken based on the highest wage at the time.

The next step would be to apply this data to your Units so they can lose/gain jobs.

For example, you could use a Unit Indexer to store this data to your Units directly. This is an extension of the last trigger:
  • -------- Display this wage and remove this job: --------
  • Game - Display to (All players) for 30.00 seconds the text: (Highest paying job: + Job_Strings[Job_Winner])
  • Set VariableSet Job_Positions[Job_Winner] = (Job_Positions[Job_Winner] - 1)
  • -------- Get the Unit that is receiving this Job: --------
  • Set VariableSet Unit = (Some unit)
  • Set VariableSet CV = (Custom value of Unit)
  • -------- Add back the position of the Job that the Unit is leaving (this is assuming that it had a Job - check with an If Then Else first): --------
  • Set VariableSet Job_Positions[Unit_Job[CV]] = (Job_Positions[Unit_Job[CV]] + 1)
  • -------- Set the Unit's new Job: --------
  • Set VariableSet Unit_Job[CV] = Job_Winner
 

Attachments

  • Job Demo 1.w3m
    19.7 KB · Views: 1
Last edited:
Top