👍

Reminder - Keep Daily Backups

When working on a strategy game with a kit as big as the Complete Kit - always keep a working daily backup! Save yourself the trouble of rolling-back changes and losing work.

What is the shield?

In popular free-to-play city building games, players can purchase a shield element which protects their base from attacks for a certain period of time and costs a large amount of rare currency. This helps developers monetize their battle strategy games with additional ways to spend real currency in the game.

As part of the early release schedule we've included the Player Base Shield feature. As of now, this is purely decorative. The HUD menu item and the store menu are included for developers to use if they would like.

1113

Store shield menu. Click to view larger.

Want to use player shields in your game?

As a quick work around to activate shields for player bases - connect the store buttons to deduct the gem amounts and then save the values to the Player save file. For example:

###Shield###
SHIELD_STATUS
ON
SHIELD_TIME_LENGTH
6 hours
SHIELD_START_TIME
11/11/2016 11:59 GMT

For example, added to the end of an example player map file.

###StartofFile###
###PosStruct###
Weapon,ArcherTower,160,2,1024,452.5
Weapon,Cannon,186,2,384,0
Building,Barrel,190,3,-768,362
Building,Vault,192,3,0,362
###GridStruct###
###Construction###
###Removables###
###RemovableTimers###
###Numerics###
193,185,189
0.00,0
0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0
###Stats###
193,1326,1,0,0,100,100000,97400,85,505000,505000,500,True,True,True,True,True
11/11/2016 3:49:16 PM
###Shield###
SHIELD_STATUS
ON
SHIELD_TIME_LENGTH
6 hours
SHIELD_START_TIME
11/11/2016 11:59 GMT
###EndofFile###

After that, we recommend editing the Stats.cs script to display this shield data from the player ID. Edit the SaveLoad scripting to load the shield value like the player status are imported on load. After - you should see the shield value added to the HUD among the other player stats after load:

603

Shield HUD example. Click to view larger.

📘

Remember to update the UI with ((Stats)stats).UpdateUI();

The kit is optimized so that UI updates are not occurring regularly without purpose. If you ever update the stats in any of your scripting - make sure to add ((Stats)stats).UpdateUI(); at the end to make sure your changes are visible.

Online Server Sync - PvP Shielded Player Avoidance (PHP)

The following is an example of additional PHP code for get_match.php (part of the Online Server Sync demo scripts) to check if a player map has a shield active, and if so, has the shield time passed?

<?


// Instructions:
// Integrate the following code into the random player map locator function
// Return the player map if no shield is active, otherwise loop to the next
//

// What player file are you checking?
$random_player_data_file = "random_player_data.txt"; //e.g. XaG13gajd.txt

// Function to get the line after
function getLineAfter($file_path, $line) {
    $lines = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    if (($key = array_search($line, $lines)) !== false && isset($lines[$key + 1])) {
        return $lines[$key + 1];
    }
    return null;
}
// End of function




// Check player data for shield line
if(getLineAfter($random_player_data_file, 'SHIELD_STATUS')=="ON"){
  
  
  // Get the variables after (lenght of time purchased and the start time
  $shield_length = getLineAfter($random_player_data_file, 'SHIELD_TIME_LENGTH');
  $shield_start_time = getLineAfter($random_player_data_file, 'SHIELD_START_TIME');
  
  
  // Calculate time
  $time = strtotime($shield_start_time); 	// Convert start time of the shield
	$when_does_the_shield_end = strtotime('+'.$shield_length, $time); // Convert ending time of the shield
  
  
  // Check if the time has passed
  if (time() > $when_does_the_shield_end) {
    //
    // shield is done -- player can be attacked - return the player data 
    // 
	} else {
    //
    // shield is still active - loop to check next player
    //
  }
  
}


?>

With the existing Unity scripting in the Complete Kit - nothing additional is necessary to begin testing shields in your game other than connecting the buttons to Player save data as mentioned above.