Creating a shop script

From Platinum Arts Sandbox Free 3D Game Maker
Jump to: navigation, search

This is a shop example script for you to edit to your liking.


     "on_start" = [
        money = 0
        pie = 0
        sword = 0
        treasure = 0
        ]
   
     "level_trigger_1" = [ money = ( + $money 5 )
        echo "You got 5 moneys."
        ]
   
     "level_trigger_2" = "showgui Shopkeeper"
     newgui Shopkeeper [
        guitext "What're ya buyin, stranger?" chat
        guibar
        guilist [
           guibutton "Pie: 10 moneys" [
              if ( > $money 9 ) [
                 money = ( - $money 10 )
                 pie = ( + $pie 1 )
              ]
           ]
   
           guibar
           guibutton "Sword: 20 moneys" [
              if ( > $money 19 ) [
                 money = ( - $money 20 )
                 sword = ( + $sword 1 )
                 ]
              ]
 
           guibar
           guibutton "Treasure: 40 moneys" [
              if ( > $money 39 ) [
                 money = ( - $money 40 )
                 treasure = ( + $treasure 1 )
                 ]
              ]
        ]
     ]
  
     newgui Inventory [
     guibutton "Back" "cleargui 1"
     guibar
     guitext ( format "You have %1 moneys in your wallet." $money )
     guitext ( format "You have %1 pies.  Yum." $pie )
     guitext ( format "You have %1 swords.  Not that you can use them..." $sword )
     guitext ( format "You have %1 treasures.  Lucky you!" $treasure )
     ]
   
     newgui main [
        guilist [
           guilist [
              guibutton "Inventory" "showgui Inventory"
           ]
        ]
        guibar
        @main
     ]

To create a nicer, graphic version of this shop script and inventory, you can use the third parameter of guibutton or the second parameter of guitext. This parameter determines the small icon that is in front of the text you specified. By default these icons must be in data/hud/xxx/icons, where xxx is the hud's version number you are using.

Create small 128x128 pixel PNG images about your objects, like the pie, or money, or sword. Put it in the directory data/hud/xxx/icons/inventory. Use these images the following way:

     guitext ( format "You have %1 moneys in your wallet." $money ) "inventory/money.png"

or

           guibutton "Pie: 10 moneys" [
              if ( > $money 9 ) [
                 money = ( - $money 10 )
                 pie = ( + $pie 1 )
              ]
           ] "inventory/pie.png"

To determine what xxx is, just use these new tags in your game script, and try it out. If Sandbox doesn't find the image you specified, it will give an error message, which contains the correct path to the icons directory.

You can also replace the "chat" icon with the icon of the person, you are speaking with. The makers of the heads-up display (hud) have thought of it, because there are robochimp and ogre icons in the data/hud/2.3/icons directory. If you are using an ogre model as your shopkeeper, you can use the shop script this way:

        guitext "What're ya buyin, stranger?" ogre

Nicer, isn't it?