PowerCards API Script on Roll20 and a YouTube Channel?

So I ran across a Roll20 API script called PowerCards, which lets you create nicely formatted output cards for abilities and attacks. Stuff like this:

I really like this kind of thing, as it add some flare to the game beyond the fairly simply built-in die rolls.

I wanted to add a few features to the script, and the author had long since stopped supporting and updating it, so I contacted him about taking it over. He was agreeable, and I’ve released two updates to the script so far (You can find the current thread atΒ https://app.roll20.net/forum/post/6264588/script-powercards-3-thread-5). A couple of the changes involve a system that lets you specify video and audio effects based on character attributes instead of baking them into your PowerCard macros. That way you can use generic macros and still have customized effects.

This system is hard to describe in text, though, and one of the users in the tread above was looking for a better way to understand it.

So, armed with nothing except my headset and some free software I found online, I started up a youtube channel and recorded a demo. I don’t have a professional mike, and I’ve never done any video recording before, but I think it came out well enough to do the job. You can find my new channel here :Β https://www.youtube.com/channel/UC4-KDSu0CE_DRasvXqVKA9g

and the video itself (right now, it’s the only thing on the channel!) is here :Β https://www.youtube.com/watch?v=JwUkdO-F3LQ&t=134s

Oblivion Modding and Steam – Fixing with Powershell

This is just a quick note, as I spent WAY too long trying to figure out why pretty much any of the Oblivion mods I was trying to install that were supposed to override textures weren’t working. I had the ArchiveInvalidationInvalidated mod installed, and nothing I tried worked.

As it turns out, the Steam install of Oblivion does weird things with the dates of the BSA files that are part of the retail package and DLCs. This causes the mod files to appear older than the BSA files, so they don’t load.

So, time for a quick PowerShell fix. Open PowerShell and go to your Oblivion data folder:

cd \Program Files (x86)\Steam\SteamApps\Common\Oblivion\Data

and run the following command:

dir *.bsa | % { $_.CreationTime = '1/1/2006 10:05'; $_.LastWriteTime = '1/1/2006 10:05' }

This will set the creation and last update time for all of your BSA to 2006, which should be well old enough for the mod files to take precedence.

 

Powershell Match 3 Game

I was playing around in Powershell over the Christmas weekend, and put together a simple “Match 3” style game utilizing the same RawUI style techniques I used in my Powershell Snake Game.

A version of a "match-3" style game written using RawUI in Powershell.

A version of a “match-3” style game written using RawUI in Powershell.

Why a PowerShell Match 3 game? Why not! πŸ™‚ Actually, I was watching a youtube video series on creating a match 3 game with Unity, and the essentials of the way matches are checked for are similar to what is shown in this series.

Being Unity, however, the game in that series relies on the Unity physics engine and collision detection to move pieces around and determine what pieces are next to each other. Obviously, we don’t have a physics engine in Powershell!

The game features a hilight you can move around with the W, A, S, and D keys, using the arrow keys to indicate you want to swap pieces in that direction. Pieces fade when matched, and the falling of pieces above them is animated. New pieces will appear in the empty spots at the top of a column.

The one thing it doesn’t do right now is verify that there are matches on the board that are available to make. I’m considering adding this, but I’m already pushing the performance limits as it is, and checking the board for possible matches can be pretty intensive πŸ™‚

Download the Powershell Match 3 Script

The script is available via the button above. Try it out, and let me know what you think, or any improvements you come up with!

Two columns of matched pieces (white and magenta) are fading out

Two columns of matched pieces (white and magenta) are fading out

 

 

A PowerShell Snake Game

As a network administrator, PowerShell is just one of those tools that, once you use it, you can never imagine doing a lot of admin tasks without it.

Interested in Powershell games? Check out my new Powershell Match Three game

 

Given it’s similar structure to other languages, I picked up on PowerShell pretty quickly, and while doodling around with it decided to try using it for something for which it was really never intended. After all PowerShell is awesome for automating data loading, updating Active Directory attributes, generating reports or extracting data to build a dynamic HTML snippet to be served up by a web page, but there are GAMES to be considered!

So here is my PowerShell game. The classic “Snake” computer game, allowing you to use the arrow keys on the keyboard to hunt down and eat apples (stunningly represented by a red @ sign – I know, the graphics are impressive!)

Powershell_Snake

 

Below is the (fairly heavily commented) result (along with a .ZIP file to download the script at the bottom of the page in case copying and pasting from a website isn’t for you – and does that ever work right?)

The script utilizes PowerShell’s RawUI functionality to position the cursor to write individual characters. Each segment of the snake’s body is stored in an array, but when the snake moves forward, the only “drawing” that takes place is to remove the last block of the tail and draw the new head block.

In most games, you would clear and redraw the entire screen after every frame, but given the interpreted nature of PowerShell, it just isn’t fast enough to do that. Even this method is pushing it once the snake grows a bit. Things get slower over time as more blocks need to be checked to determine if the snake has run into itself. The code here could be improved upon – for example, it should be possible to determine a general slowdown rate as the snake grows and adjust the sleep near the end of the script (that delays between each frame) to eliminate at least some of the lag. Since this was a project for an hour of free time, I didn’t go that far with it.

Update: See the comments for Dave Wyatt’s update that changes the way the tail is checked for his and removes the slowdown completely πŸ™‚

I do have a couple more ideas for games that could be written in PowerShell when considering the speed restrictions, so we’ll just have to see if they every make it into .PS1 files. In the mean time, enjoy chasing the apple…

#requires -version 2

#
# Powershell Snake Game
# Author : Kurt Jaegers
#

#
# Draws the snake to the screen, including cleaning up the last segment of the tail
#
function DrawTheSnake
{
 
  # Erase the tail segment that is disappearing
  $rui.cursorposition = $tail[0]
  write-host -foregroundcolor white -backgroundcolor black -NoNewline " " 
 
  # Shift all of the tail segments down one
  for ($i=0; $i -lt ($tailLength - 1); $i++)
  {
    $tail[$i].x = $tail[$i+1].x
    $tail[$i].y = $tail[$i+1].y
  }
 
  # Set the last segment of the tail to the current position
  $tail[-1].x = $coord.x
  $tail[-1].y = $coord.y
  
  # Draw all segments of the snake  
  for ($i=0; $i -lt $tailLength; $i++)
  {
    $rui.cursorposition = $tail[$i]
    write-host -foregroundcolor white -backgroundcolor white -NoNewline " "
  }

}


#
# Generate a random location for the apple, making sure it isnt inside the snake
#
function MoveTheApple
{ 
  $ok = $true;
  do 
  {
    $script:apple.x = get-random -min 2 -max ($rui.WindowSize.width - 2)
    $script:apple.y = get-random -min 2 -max ($rui.WindowSize.height - 2)
    $ok=$true
    for ($i=0; $i -lt $tailLength; $i++)
    {
      if (($tail[$i].x -eq $apple.x) -and ($tail[$i].y -eq $apple.y))
      {
        $ok=$false;
      }
    }
  } While (!$ok)
}

#
# Draw the apple to the screen
#
function DrawTheApple
{
  $rui.CursorPosition = $apple
  write-host -foregroundcolor red -backgroundcolor black "@"
}

#
# Check to see if the snake hits the apple
#
function CheckAppleHit
{
  # if the x/y of the head matches the x/y of the apple, we hit the apple
  if (($tail[-1].x -eq $apple.x) -and ($tail[-1].y -eq $apple.y))
  {
    # relocate the apple
    MoveTheApple
    
    $score += 500
    
    # Add to the snake's length
    $script:tailLength++
    $script:tail += new-object System.Management.Automation.Host.Coordinates
    $script:tail[-1].x = $coord.x
    $script:tail[-1].y = $coord.y
  }
}

#
# Check to see if the snake's head hits the walls of the screen
#
function CheckWallHits
{
  if (($coord.x -eq 0) -or ($coord.y -eq 0) -or ($coord.x -eq $host.ui.rawui.windowsize.width-1) -or ($coord.y -eq $host.ui.rawui.windowsize.height-1))
  {
    cls
    write-host -foregroundcolor red "You lost! Score was $score"
    exit
  }
}


#
# Draw a fence around the edges of the screen
#
function DrawScreenBorders
{
  $cur = new-object System.Management.Automation.Host.Coordinates
  $cur.x=0
  $cur.y=0
  
  for ($x=0; $x -lt $host.ui.rawui.windowsize.width; $x++)
  {
    $cur.x=$x
    $cur.y=0
    $host.ui.rawui.cursorposition = $cur
    write-host -foregroundcolor black -backgroundcolor white -nonewline "#"

    $cur.y=$host.ui.rawui.windowsize.height-1
    $host.ui.rawui.cursorposition = $cur
    write-host -foregroundcolor black -backgroundcolor white -nonewline "#"
    
  }
  
  for ($y=0; $y -lt $host.ui.rawui.windowsize.height-1; $y++)
  {
    $cur.y=$y
    $cur.x=0
    $host.ui.rawui.cursorposition = $cur
    write-host -foregroundcolor black -backgroundcolor white -nonewline "#"

    $cur.x=$host.ui.rawui.windowsize.width-1
    $host.ui.rawui.cursorposition = $cur
    write-host -foregroundcolor black -backgroundcolor white -nonewline "#"
    
  }  
}

function CheckSnakeBodyHits
{
  for ($i=0; $i -lt $tailLength -1; $i++)
  {
    if (($tail[$i].x -eq $coord.x) -and ($tail[$i].y -eq $coord.y))
    {
      cls
      write-host -foregroundcolor red "You lost! Score was $score"
      exit
    }
  }
}

# ---------------------------------
# ---------------------------------
# Main script block starts here
# ---------------------------------
# ---------------------------------

# Grab UI objects and set some colors
$ui=(get-host).ui
$rui=$ui.rawui
$rui.BackgroundColor="Black"
$rui.ForegroundColor="Red"
cls

# write out lines to make sure the buffer is big enough to cover the screen
for ($i=0; $i -lt $rui.screensize.height; $i++)
{
  write-host "" 
}
$coord = $rui.CursorPosition
$save = $coord
$cs = $rui.cursorsize
$rui.cursorsize=0
$score = 0

$done = $false

$before = 0
$after  = 15
$dir = 0

$coord.X = $rui.screensize.width/2
$coord.y = $rui.screensize.height/2

$coord.x = 80
$coord.Y = 15
$apple = new-object System.Management.Automation.Host.Coordinates
DrawScreenBorders;
MoveTheApple;

$tail = @()
$tailLength = 5

for ($i=0; $i -lt $tailLength; $i++)
{
  $tail += new-object System.Management.Automation.Host.Coordinates
  $tail[$i].x = $coord.x
  $tail[$i].y = $coord.y
}

while (!$done)
{
  
  if ($rui.KeyAvailable)
  {
    $key = $rui.ReadKey()
    if ($key.virtualkeycode -eq -27)
    {
      $done=$true
    }
    if ($key.keydown)
    {
      # Left
      if ($key.virtualkeycode -eq 37)
      {
        $dir=0
      }   
      # Up
      if ($key.virtualkeycode -eq 38)
      {
        $dir=1
      } 
      # Right
      if ($key.virtualkeycode -eq 39)
      {
        $dir=2
      }
      # Down
      if ($key.virtualkeycode -eq 40)
      {
        $dir=3
      }
    }
  }
  
  if ($dir -eq 0)
  { 
    $coord.x--;
  }
  
  if ($dir -eq 1)
  {
    $coord.y--;
  }
  
  if ($dir -eq 2)
  {
    $coord.x++;
  }
  
  if ($dir -eq 3)
  {
    $coord.y++;
  }

  DrawTheApple;
  DrawTheSnake;
  CheckWallHits;
  CheckSnakeBodyHits;
  CheckAppleHit;

    
  start-sleep -mil 100
  
  $score += $tailLength;
  
}

$rui.cursorsize=$cs

Download Snake.zip – PowerShell Snake Game

  • Advertisement