Guest User

Untitled

a guest
Mar 19th, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $folders = Get-ChildItem .\Universe\Scenarios | ?{ $_.PSIsContainer }
  2. $players = @{}
  3.  
  4. function getIni
  5. {
  6.     param (
  7.     [parameter(mandatory=$true,position=0)][String]$FilePath
  8.     )
  9.     $Ini = @{}
  10.  
  11.     if(Test-Path -Path $FilePath)
  12.     {
  13.         Get-Content $FilePath | foreach {
  14.             $line = $_.split("=")
  15.             $Ini.($line[0].Trim()) = $line[1].Trim()
  16.         }
  17.     }
  18.     return $Ini
  19. }
  20.  
  21. function getReputation
  22. {
  23.     param (
  24.     [parameter(mandatory=$true,position=0)]$PlayerFolder
  25.     )
  26.     [double]$rv = -99999
  27.     [string]$repFilePath = $PlayerFolder + '\Reputation.txt'
  28.     if(Test-Path -Path $repFilePath)
  29.     {
  30.         $repIni = getIni $repFilePath
  31.         [double]$rv = [convert]::ToDouble($repIni.'rep')
  32.     }
  33.     return $rv
  34.  
  35.    
  36. }
  37.  
  38. function setReputation
  39. {
  40.     param (
  41.     [parameter(mandatory=$true,position=0)]$PlayerFolder,
  42.     [parameter(mandatory=$true,position=1)][double]$newRep
  43.     )
  44.  
  45.     [string]$repFilePath = $PlayerFolder + '\Reputation.txt'
  46.     if(Test-Path -Path $repFilePath)
  47.     {
  48.         $rawS = (get-content $repFilePath) -replace "rep =.*", "rep = $newRep"
  49.         $rawS | Out-File $repFilePath
  50.     }
  51. }
  52.  
  53.  
  54. function checkReputation
  55. {
  56.  
  57.     foreach ($player in $players.Values)
  58.     {
  59.         $currentRep = getReputation $player.myFolder
  60.  
  61.         if($currentRep -lt $player.reputation)
  62.         {
  63.             setReputation $player.myFolder $lastRep
  64.         }
  65.     }
  66.    
  67. }
  68.  
  69.  
  70. $i = 0
  71. foreach ($folder in $folders)
  72. {
  73.     $rep = getReputation $folder.FullName
  74.     if($rep -ne -99999)
  75.     {
  76.         $player = [pscustomobject]@{myFolder=$folder.FullName; reputation=$rep}
  77.         #$players.Add($folder.Name [$i] = $player
  78.         $players.Add($folder.Name, $player)
  79.         $i++
  80.     }
  81.  
  82. }
  83.  
  84. While(1){
  85.  
  86. checkReputation
  87. sleep(5)
  88. }
Add Comment
Please, Sign In to add comment