Can someone tell me why this code doesn't seem to work right?
EVENTS
Map initilization
ACTIONS
Bank - Preload and synchronize bank "baseshipcommandersplayerstats" for player 1
EVENTS
Player leaves game with Victory
ACTIONS
Bank - Open bank "baseshipcommandersplayerstats" for player (Triggering Player)
Variable - Modify Number of Wins[(Triggering Player)]: + (1 + (Load "wins" of section "record" from bank (Last opened bank) as integer value))
Bank - Store integer Number of Wins[(Triggering Player)] as "wins" of section "record" in bank (Last opened bank)
Bank - Save bank (Last opened bank)
It gets stuck at the number 2.
I will also add that I use the exact same expression at map init to record the number of games played and that works fine.
I figured as much, I was hoping to avoid this sort of thing. I have the victory conditions set in a pick each integer loop. Runs through every player in the game and checks victory conditions after the key unit dies. Problem is when I try it in the loop, all kinds of crazy things happen, like the integer values go crazy.
EVENTS:
unit dies
Conditions
Unit = Main Objective for victory
ACTIONS
General - Pick each integer from 1 to 14, and do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
((Picked integer) is in Ancient Imperium) == True
(Status of player (Picked integer)) == Playing
(Picked integer) != Computer minion
Then
Bank - Open bank "baseshipcommandersplayerstats" for player (Picked integer)
Variable - Modify Number of Wins[(Picked integer)]: + (1 + (Load "wins" of section "record" from bank (Last opened bank) as integer value))
Bank - Store integer Number of Wins[(Picked integer)] as "wins" of section "record" in bank (Last opened bank)
Bank - Save bank (Last opened bank)
General - Wait 4.0 Game Time seconds
Game - End game in Victory for player (Picked integer) (Show dialogs, Show score screen)
Else
As you can see I try storing the bank before the game ends and what it causes is the integers to be stored in an infinite loop. It slowly increases until it becomes -1. It basically goes nuts. In my integer loop, I am running the test by myself, but it should go through each player who is on the appropriate team. I also make sure to leave out the computer player. In my case integer 1 should be the only one that actually meets the conditions and it should only do it once.
Okay so I've got the wins and losses showing up properly now, I had to change it to this in the integer loop:
<br /> Variable - Modify Number of Wins[(Picked integer)]: + 1
Bank - Open bank "baseshipcommandersplayerstats" for player (Picked integer)
Bank - Store integer Number of Wins[(Picked integer)] as "wins" of section "record" in bank (Last opened bank)
Bank - Save bank (Last opened bank)
General - Wait 2.0 Game Time seconds
Game - End game in Victory for player (Picked integer) (Show dialogs, Show score screen)<br /><br />Seems trying to do the math at the same time made it all funky, and there were some other anomalies. (As there always are)<br /><br />Anyway, now I can't get it to work when a player leaves the game or disconnects to count as a "LOSS".<br /><br /><br />
For the new people to banks like myself, I have solved this problem!
So if a player leaves the game, the bank already recorded the number of games but does not record leaving as a loss. To fix this, I simply run a comparison of the variables wins and losses at the beginning of the game. If they don't match, I add +1 to the loss so the next time the player logs into the game, it will update their status accordingly. Tested it and it works perfectly!
I also added that signature function to the bank to prevent tampering with. Seems to work alright for me.
I also added that signature function to the bank to prevent tampering with. Seems to work alright for me.
It is nothing more than a well known SHA-1 checksum of a string built from the banks contents. Very easy to cheat and some people even made programs to sign any bank file.
Also nothing stops players deleting their bank file, resetting wins/losses to 0. For this reason you want the data in the banks to be nothing more than stats.
True enough, although 90% of people probably won't even bother messing around with it. Its the 10% you have to worry about.
I'm mostly using it to create an "Auto balance team" function. As a possible solution to "stacked teams". It will never be perfect, but it can improve the stacked teams probably a bit. Some auto balancing is better then no auto balancing.
With regards to recording games left, I've experimented with this a little. I've used a trigger with event "Player Leaves Game" with any. The trigger adds 1 to the games left variable and stores it to the player's bank. In my test runs, I tried leaving the game through standard methods and it worked. I also tried killing the SC2.exe process as well as performing a soft reboot and the bank saved correctly each time. I didn't try a hard reboot or disconnecting my internet access. Additionally, I can't remember if I performed these tests online or just offline.
As far as autobalancing, it's definitely something that takes a lot of planning. My current autobalance method uses players' scores (a formula of their lifetime stats) and tries to even the scores out over 2 teams. First it find the scores for all players and assigns the top player to team A and the 2nd highest score player to team B. Each team has a max of 5 players, so, after much consideration, I decided to simply calculate every possible team combination and go with the combination that most closely balances things. If we account for the possibility of uneven teams, the total number of team combinations is C(8,4) + C(8,3) = 126; this is totally reasonable.
Autobalance will probably be one of your biggest headaches through development. As @ImperialGood said, there's really no way to secure players' banks 100% of the time. Any obfuscation, encryption, or validation schemes for banks you come up with can be defeated. It takes virtually no skill to find your bank and delete it. You can see how this might affect game balance if someone who's been around for a while suddenly shows up with low or no stats and gets placed as a noob by autobalance. If you come up with any good autobalance schemes though, I'd love to hear them.
Good luck!
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Can someone tell me why this code doesn't seem to work right?
It gets stuck at the number 2.
I will also add that I use the exact same expression at map init to record the number of games played and that works fine.
I'd first try changing the bank before the player leaves the game.
Custom Campaign Initiative | Mapster Community Project: Data Wizards
Starcraft II: Unsung Rebels, a custom campaign for Starcraft II
SC2Saver, a way to create saved games via trigger
Frustrated with the editor and would like answers in real time? Join the SC2Mapster Discord!
I figured as much, I was hoping to avoid this sort of thing. I have the victory conditions set in a pick each integer loop. Runs through every player in the game and checks victory conditions after the key unit dies. Problem is when I try it in the loop, all kinds of crazy things happen, like the integer values go crazy.
As you can see I try storing the bank before the game ends and what it causes is the integers to be stored in an infinite loop. It slowly increases until it becomes -1. It basically goes nuts. In my integer loop, I am running the test by myself, but it should go through each player who is on the appropriate team. I also make sure to leave out the computer player. In my case integer 1 should be the only one that actually meets the conditions and it should only do it once.
Okay so I've got the wins and losses showing up properly now, I had to change it to this in the integer loop:
For the new people to banks like myself, I have solved this problem!
So if a player leaves the game, the bank already recorded the number of games but does not record leaving as a loss. To fix this, I simply run a comparison of the variables wins and losses at the beginning of the game. If they don't match, I add +1 to the loss so the next time the player logs into the game, it will update their status accordingly. Tested it and it works perfectly!
I also added that signature function to the bank to prevent tampering with. Seems to work alright for me.
It is nothing more than a well known SHA-1 checksum of a string built from the banks contents. Very easy to cheat and some people even made programs to sign any bank file.
Also nothing stops players deleting their bank file, resetting wins/losses to 0. For this reason you want the data in the banks to be nothing more than stats.
True enough, although 90% of people probably won't even bother messing around with it. Its the 10% you have to worry about.
I'm mostly using it to create an "Auto balance team" function. As a possible solution to "stacked teams". It will never be perfect, but it can improve the stacked teams probably a bit. Some auto balancing is better then no auto balancing.
In reply to onlyleviathan:
Good luck!