FANDOM


Explanation on how to add new items to in-game shops, and tweak their price and rarity.

Creating a new itemEdit

You will need a new item to add to the shop. The easiest way to do this is to start by making a new sprite. If it is to be a held object, you will want to make a sprite of it for both facing left and facing right.. Then duplicate an object similar to the one you want to make renaming it to your object. Make sure your object has the parent of oItem, and alter the creation script to give it a description and price when you find it in the shop. Let's say you want a new weapon which we'll call oBazooka. It will have the same properties of the shotgun, but shoot bombs.(Note: the specifics of making new effects for the item are not covered here, merely it's creation.)


We duplicate the object oShotgun, then under the creation event we will set the description and price. Here you will see:

type = "Shotgun"; 
makeActive(); 
setCollisionBounds(-4, -4, 4, 4); 
cost = 15000; 
buyMessage = "A SHOTGUN FOR $" + string(cost) + ".";

For this tutorial we will change only the type, cost, and buy message. makeActive is important to the coding of the game engine, and collisionBounds should be fine unless you make an item much larger or smaller than what you copied.

So in our new object we will change the code under the create event to read:

type = "Bazooka";
makeActive ();
setCollisionBounds (-4, -4, 4, 4);
cost = 25000;
buyMessage = "A BAZOOKA FOR $" + string(cost) + ".";

Now it's a bit more expensive than the shotgun, and will be described as a bazooka.

In the step event, you should have a code that reads:

if (held)
{
   if (oPlayer1.facing == 18) sprite_index = sBazookaLeft;
   else sprite_index = sBazookaRight;
}

This will change the direction it faces when you turn around, that's why you need a left and right facing sprite.

Changes to item scriptsEdit

You will want to add it to the scrHoldItem script, this will tell the game to put it in your hand when it is picked up. To do this simply open the Character subfolder under Scripts, and find scrHoldItem. Here you will see a list of any items that appear in the item box in your HUD when they are held (rocks, guns, etc.), simply add a new line to read:

else if (itemType == "Bazooka") holdItem = instance_create(x, y, oBazooka);

Another relevant script would be the one dealing with stolen items. Find the scrStealItem script in the same folder. Again the easiest way to add your item is to copy an existing one, and once again the shotgun is a good example.

else if (holdItem.type == "Shotgun" and holdItem.cost > 0)
{
   holdItem.cost = 0;
   holdItem.forSale = false;
   //disp = instance_create(holdItem.x, holdItem.y-14, oItemsGet);
   playSound(global.sndPickup);
   global.message = "YOU GOT A SHOTGUN!";
   global.message2 = "";
   global.messageTimer = 120;
}

Copy paste it to the bottom, or somewhere relevant you will remember (the else if statement makes it irrelevant where in the list the object is). Then change the variables to match your new item:

else if (holdItem.type == "Bazooka" and holdItem.cost > 0)
{
   holdItem.cost = 0;
   holdItem.forSale = false;
   //disp = instance_create(holdItem.x, holdItem.y-14, oItemsGet);
   playSound(global.sndPickup);
   global.message = "YOU GOT A BAZOOKA!";
   global.message2 = "";
   global.messageTimer = 120;
}

Finally in the main scripts folder, open scrDrawHUD. Scroll down until you see a line reading:

draw_sprite(sHoldItemIcon, -1, 8, 24);
   if (oPlayer1.pickupItemType!= "")

With a lot of else if statements following it. Here you can set the sprite for your object to be drawn in the held item box on the HUD. Simply add a new line to the bottom with your items parameters:

else if (oPlayer1.pickupItemType== "Bazooka") draw_sprite(sBazookaRight, -1, 8+8, 24+8);


Adding the itemEdit

Now, you can add it fairly easily to an existing shop. Open the Level generation folder in the Scripts folder. Look for scrShopItemsGen, and scroll down to the shop you want (weapon shop in this case) Then copy the code for the last item on the list and paste it directly under:

}
else if (shopType == "Weapon")
{
   m = 20;
   while (true)
   {
       n = rand(1,4);
       if (m <= 0) { obj = instance_create(xpos+8, ypos+10, oBombBag); break; }
       else if (rand(1,12)==1)
       {
           if (not instance_exists(oWebCannon)) { obj = instance_create(xpos+8, ypos+12, oWebCannon); break; }
       }
       else if (rand(1,5)==1)
       {
           if (not instance_exists(oShells)) { obj = instance_create(xpos+8, ypos+12, oShells); break; }
       }
       else if (rand(1,6)==1) { obj = instance_create(xpos+8, ypos+10, oBombBox); break; }
       else if (n == 1)
       {
           if (not instance_exists(oPistol)) { obj = instance_create(xpos+8, ypos+12, oPistol); break; }
       }
       else if (n == 2)
       {
           if (not instance_exists(oMachete)) { obj = instance_create(xpos+8, ypos+12, oMachete); break; }
       }
       else if (n == 3) { obj = instance_create(xpos+8, ypos+10, oBombBag); break; }
       else if (n == 4)
       {
           if (not instance_exists(oBow)) { obj = instance_create(xpos+8, ypos+12, oBow); break; }
       }
       {//copied bow code and pasted under it
           if (not instance_exists(oBow)) { obj = instance_create(xpos+8, ypos+12, oBow); break; }    
       }
       m -= 1;
   }
}

Now just change the specifics to your item:

{
        if (not instance_exists(oBazooka)) { obj = instance_create(xpos+8, ypos+12, oBazooka); break; }
       }

You could also give it a random chance to appear, as the first few items do, to make it more common. To do that just replace the "if (not instance_exists" part with "else if (rand (x,y) =z)". Where x= the lowest random number, y=the highest random number, and z=the number that must be returned to create the instance.

Then run a number of tests to see if it shows up as frequently as you like, is the price you want, correct text displayed and so on.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.