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

Deposit and Withdraw commands

Status
Not open for further replies.

Celalith

C

Celalith

First of all, Hi!


I have been making my own Life of a Peasant map and I added a Bank, and now I want to add a few commands to the bank, like Deposit and Withdraw - You can deposit a random amount of gold to the bank and can later withdraw it.
The thing is I have no idea how to do it and would like some help.


Thanks in advance!
 

Celalith

C

Celalith

Yeah, I tried to make sense of that info, but I just don't understand variables.
Also with the withdraw command, It needs to know how much I have already added to the bank - so I can't withdraw more then I have added.
But thanks anyways.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
u should learn about variables if u plan on doing any types of triggering. there are tutorials that show u wat variables are and how to use them. then u should take a look at my tutorial and the things that leak tutorial.
to check how much is in there u need a variable. to deposit u need a variable. to withdraw u need a variable. they are very easy to understand and i think u can understand them.

basically u would need an integer array variable for storing the gold. then u need a few temp variables. normally an integer and a player variable. and i believe that is all u need. u would need at minimum 1 trigger to do everything. two triggers in this case would probably be better tho.

first trigger u have the deposit gold. so -de x
were x is the gold amount.
then u need to use substrings to find out how much gold the person typed in.

give me a couple minutes and ill make a simple thing for u

ill leave notes so u can see wats happening

here is that trigger and how it works is explained if u have any questions feel free to ask.
  • deposit gold
    • Events
      • Player - Player 1 (Red) types a chat message containing -de as A substring
      • Player - Player 2 (Blue) types a chat message containing -de as A substring
      • Player - Player 3 (Teal) types a chat message containing -de as A substring
      • Player - Player 4 (Purple) types a chat message containing -de as A substring
      • Player - Player 5 (Yellow) types a chat message containing -de as A substring
      • Player - Player 6 (Orange) types a chat message containing -de as A substring
      • Player - Player 7 (Green) types a chat message containing -de as A substring
      • Player - Player 8 (Pink) types a chat message containing -de as A substring
      • Player - Player 9 (Gray) types a chat message containing -de as A substring
      • Player - Player 10 (Light Blue) types a chat message containing -de as A substring
      • Player - Player 11 (Dark Green) types a chat message containing -de as A substring
      • Player - Player 12 (Brown) types a chat message containing -de as A substring
    • Conditions
    • Actions
      • -------- first i set the enterd string to a variable. --------
      • Set tempString1 = (Entered chat string)
      • -------- then i get the substring of the entered string to make sure that it is the desired string entered in the right way. i am looking for (-de ) this way someone cant type in hello -de and mess up the trigger. --------
      • Set tempString2 = (Substring(tempString1, 1, 4))
      • -------- in the conditions i check to make sure the string entered in is correct --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • tempString2 Equal to -de
        • Then - Actions
          • -------- i then set the triggering player into a variable. so i can use it later --------
          • Set tempPlayer = (Triggering player)
          • -------- i then set the length of the string entered into an integer variable --------
          • Set tempInt1 = (Length of tempString1)
          • -------- in this i set an integer to the amount of money typed in --------
          • Set tempInt2 = (Integer((Substring(tempString1, 5, tempInt1))))
          • -------- i then set an integer to the current gold that the player has --------
          • Set tempInt3 = (tempPlayer Current gold)
          • -------- this next one sets an integer variable to the players number. To be used as an index. --------
          • Set tempInt4 = (Player number of tempPlayer)
          • -------- i then check to see if that player has enough money to put into the bank. so he cant put in more than he has --------
          • Player Group - Add tempPlayer to tempPlayerGroup
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempInt2 Greater than tempInt3
            • Then - Actions
              • -------- this only fires if the player typed in more money than that player had --------
              • -------- this next action adds all the players gold into his bank. the bank is an integer indexed to that players number. --------
              • Set playersGoldDeposited[tempInt4] = (playersGoldDeposited[tempInt4] + tempInt3)
              • -------- i then subtract the gold from the player --------
              • Player - Set tempPlayer Current gold to ((tempPlayer Current gold) - tempInt3)
              • Game - Display to tempPlayerGroup the text: (You have deposited + ((String(tempInt3)) + gold into your bank))
              • -------- this one is all done now. the trigger has added the players gold into his bank. --------
            • Else - Actions
              • -------- this next action adds the gold the player typed in into his bank. the bank is an integer indexed to that players number. --------
              • Set playersGoldDeposited[tempInt4] = (playersGoldDeposited[tempInt4] + tempInt2)
              • -------- i then subtract the gold from the player --------
              • Player - Set tempPlayer Current gold to ((tempPlayer Current gold) - tempInt2)
              • Game - Display to tempPlayerGroup the text: (You have deposited + ((String(tempInt2)) + gold into your bank))
              • -------- this one is all done now. the trigger has added the players gold into his bank. --------
          • Player Group - Remove tempPlayer from tempPlayerGroup
          • -------- this first one is a custom script. this is needed because in GUI u cant set the player to null. Its a little bit of jass but its easy to understand --------
          • -------- any variable u create in the variable editor u need to use the udg_ prefix. this stands for user defined global. --------
          • Custom script: set udg_tempPlayer = null
          • Set tempInt1 = 0
          • Set tempInt2 = 0
          • Set tempInt3 = 0
          • Set tempInt4 = 0
          • -------- since its all done we need to clean some things up so it doesnt bug up next time someone activates the trigger --------
        • Else - Actions
      • -------- since its all done we need to clean some things up so it doesnt bug up next time someone activates the trigger. --------
      • Set tempString1 = <Empty String>
      • Set tempString2 = <Empty String>
  • withdraw gold
    • Events
      • Player - Player 1 (Red) types a chat message containing -wi as A substring
      • Player - Player 2 (Blue) types a chat message containing -wi as A substring
      • Player - Player 3 (Teal) types a chat message containing -wi as A substring
      • Player - Player 4 (Purple) types a chat message containing -wi as A substring
      • Player - Player 5 (Yellow) types a chat message containing -wi as A substring
      • Player - Player 6 (Orange) types a chat message containing -wi as A substring
      • Player - Player 7 (Green) types a chat message containing -wi as A substring
      • Player - Player 8 (Pink) types a chat message containing -wi as A substring
      • Player - Player 9 (Gray) types a chat message containing -wi as A substring
      • Player - Player 10 (Light Blue) types a chat message containing -wi as A substring
      • Player - Player 11 (Dark Green) types a chat message containing -wi as A substring
      • Player - Player 12 (Brown) types a chat message containing -wi as A substring
    • Conditions
    • Actions
      • -------- first i set the enterd string to a variable. --------
      • Set tempString1 = (Entered chat string)
      • -------- then i get the substring of the entered string to make sure that it is the desired string entered in the right way. i am looking for (-wi ) this way someone cant type in hello -wi and mess up the trigger. --------
      • Set tempString2 = (Substring(tempString1, 1, 4))
      • -------- in the conditions i check to make sure the string entered in is correct --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • tempString2 Equal to -wi
        • Then - Actions
          • -------- i then set the triggering player into a variable. so i can use it later --------
          • Set tempPlayer = (Triggering player)
          • -------- i then set the length of the string entered into an integer variable --------
          • Set tempInt1 = (Length of tempString1)
          • -------- in this i set an integer to the amount of money typed in --------
          • Set tempInt2 = (Integer((Substring(tempString1, 5, tempInt1))))
          • -------- this next one sets an integer variable to the players number. To be used as an index. --------
          • Set tempInt4 = (Player number of tempPlayer)
          • -------- i then set an integer to the current gold that is in that players bank --------
          • Set tempInt3 = playersGoldDeposited[tempInt4]
          • -------- i then check to see if that player has enough money in the bank. so he cant take out more than he has --------
          • Player Group - Add tempPlayer to tempPlayerGroup
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempInt2 Greater than tempInt3
            • Then - Actions
              • -------- this only fires if the player typed in more money than that player had --------
              • -------- this next action subtracts all the players gold into his bank. the bank is an integer indexed to that players number. --------
              • Set playersGoldDeposited[tempInt4] = (playersGoldDeposited[tempInt4] - tempInt3)
              • -------- i then add the gold to the player --------
              • Player - Add tempInt3 to tempPlayer Current gold
              • Game - Display to tempPlayerGroup the text: (You have withdrawn + ((String(tempInt3)) + gold from your bank))
              • -------- this one is all done now. the trigger has added the players gold into his bank. --------
            • Else - Actions
              • -------- this next action subtracts the players gold that he typed in into his bank. the bank is an integer indexed to that players number. --------
              • Set playersGoldDeposited[tempInt4] = (playersGoldDeposited[tempInt4] - tempInt2)
              • -------- i then subtract the gold from the player --------
              • Player - Add tempInt2 to tempPlayer Current gold
              • Game - Display to tempPlayerGroup the text: (You have withdrawn + ((String(tempInt2)) + gold from your bank))
              • -------- this one is all done now. the trigger has added the players gold into his bank. --------
          • Player Group - Remove tempPlayer from tempPlayerGroup
          • -------- this first one is a custom script. this is needed because in GUI u cant set the player to null. Its a little bit of jass but its easy to understand --------
          • -------- any variable u create in the variable editor u need to use the udg_ prefix. this stands for user defined global. --------
          • Custom script: set udg_tempPlayer = null
          • Set tempInt1 = 0
          • Set tempInt2 = 0
          • Set tempInt3 = 0
          • Set tempInt4 = 0
          • -------- since its all done we need to clean some things up so it doesnt bug up next time someone activates the trigger --------
        • Else - Actions
      • -------- since its all done we need to clean some things up so it doesnt bug up next time someone activates the trigger. --------
      • Set tempString1 = <Empty String>
      • Set tempString2 = <Empty String>
i also added a trigger just to tell the player how much gold he has.
  • gold check
    • Events
      • Player - Player 1 (Red) types a chat message containing -gc as An exact match
      • Player - Player 2 (Blue) types a chat message containing -gc as An exact match
      • Player - Player 3 (Teal) types a chat message containing -gc as An exact match
      • Player - Player 4 (Purple) types a chat message containing -gc as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -gc as An exact match
      • Player - Player 6 (Orange) types a chat message containing -gc as An exact match
      • Player - Player 7 (Green) types a chat message containing -gc as An exact match
      • Player - Player 8 (Pink) types a chat message containing -gc as An exact match
      • Player - Player 9 (Gray) types a chat message containing -gc as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -gc as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing -gc as An exact match
      • Player - Player 12 (Brown) types a chat message containing -gc as An exact match
    • Conditions
    • Actions
      • Set tempPlayer = (Triggering player)
      • Set tempInt1 = (Player number of tempPlayer)
      • Player Group - Add tempPlayer to tempPlayerGroup
      • Game - Display to tempPlayerGroup the text: (You have + ((String(playersGoldDeposited[tempInt1])) + gold in your bank))
      • Player Group - Remove tempPlayer from tempPlayerGroup
here is a test map. just try it out you can deposit and withdraw gold. note that gold will be added to the player every 5 seconds so u can see how this works with more gold.
 

Attachments

  • gold bank withdraw deposit and gold check.w3x
    23.6 KB · Views: 37
Last edited:

Celalith

C

Celalith

Word cannot describe how grateful I am ........ Thank you
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
Although gold usage is MPI...I think better to do it MUI, where gold is the bank's total money and each peasant/unit has it's own money, hashtable or unit indexer will take part of this...

Also you dont need that player group, just display a texttag on top of the bank or better yet, a message containing playersGoldDeposited[playerindex] gold...
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
its a banking system for players. so making it MUI is pointless.
a texttag is more processing i believe than displaying the message to the playerGroup
i never destroy the player group. i simply use it to add and remove that player at the time he triggers it so it is efficient. Its just like adding one unit to a unit group then removing that unit.
 
Status
Not open for further replies.
Top