Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // READ THE COMMENTS BEFORE USING THIS!!
  2. // this is originally written & compiled in Swishscript 2. I've converted it to AS2 (its almost the same) but you may still find minor errors in it. If so just edit til it works.
  3. // if you code wit classes, you'll need to edit thigns a bit.
  4. // if you code on frames, this may not work - its written assuming your game is all on one frame.
  5. // if you code on frames, then stop doing that and write your next game on one frame only. its a lot easier from a coding point of view.
  6. // it looks complicated, but just follow the instructions carefully and its simple :)
  7. // highlighted lines are where you need to edit
  8.  
  9. // BEFORE YOU USE THE CODE
  10. // you need a movieclip at _root.inv.inventory
  11. // items in the inventory should be named item0, item1, item2, etc.
  12. // so the path to your second item would be _root.inv.inventory.item1
  13. // this is annoying if you only have a few items in your game, but for Sleeping Beauty I had 30+, and this way I could loop through them without knowing what each one was named.
  14.  
  15. // next make another movieclip called invdisplay, on the root again. put a copy of all your inventory items in here, with the same name as they have in the inventory. centre each one and set the registration point to centre as well.
  16. // this movieclip will show the item the player is currently holding
  17.  
  18. // REQUIRED FUNCTIONS
  19. // these go on _root
  20. // do not edit them!
  21.  
  22. function holdingitem(number) {
  23. // this is for when the player takes an item from the inventory
  24.     for (i=0; i<_root.inventory.maxitems; i++) {
  25.        _root.["invdisplay.item" + i]._visible = false;
  26.        _root["inventory.inv.item" + i]._alpha = 100;
  27.     }
  28.     _root["_root.invdisplay.item" + number]._visible = true;
  29.     _root["_root.inventory.inv.item" + number]._alpha = 50;
  30.     _root.itemheld = number;
  31.  
  32. }
  33. function replaceitem() {
  34. // this is called when you replace an item
  35.     for (i=0; i<_root.inventory.maxitems; i++) {
  36.         _root["invdisplay.item" + i]._visible = false;
  37.       _root["inventory.inv.item" + i]._alpha = 100;
  38.     }
  39.     _root.itemheld = -1;
  40. }
  41.  
  42. function itemget(number) {
  43. // this is for picking an item up and putting it in the inventory
  44.     eval("_root.inventory.inv.item" + number)._visible = true;
  45.     _root.inventory.invhilight2._visible = true;
  46. }
  47.  
  48. onSelfEvent (enterFrame) {
  49. // this is so that the inventory display follows the mouse around
  50.     _root.invdisplay._x = _root._xmouse;
  51.     _root.invdisplay._y = _root._ymouse;
  52. }
  53.  
  54. // INVENTORY MOVIECLIP
  55. // put this on the inventory movieclip (not inventory.inv)
  56. // edit the highlighted line only!
  57. // all this is for is to hide every item the player hasn't collected.
  58.  
  59. onClipEvent (load) {
  60.     invopen = 0;
  61.     otheropen = 0;
  62. // number of items you have in total for the whole game. remember you start counting at 0.
  63.     maxitems = 5;
  64.     for (i = 0; i < maxitems; i++) {
  65. _root["inv.item" + i]._visible = false;
  66.     }
  67. }
  68.  
  69. // ON ITEMS IN THE INVENTORY
  70. // put this code on each item in the inventory. edit the highlighted lines with the number from the name of the item, eg this code goes on _root.inventory.inv.item4.
  71.  
  72. on (press) {
  73.  if (_root.itemheld !=4) {
  74.         _root.holdingitem(4);
  75.     }
  76.     else {
  77.         _root.replaceitem();
  78.     }
  79. }
  80.  
  81. // ON INVDISPLAY
  82. // hide items on load. dont edit this.
  83.  
  84. onSelfEvent (load) {
  85.     for (i = 0; i<_root.inventory.maxitems; i++) {
  86.         _root["item" + i]._visible = false;
  87.     }
  88. }
  89.  
  90.  
  91. // ITEM COLLECTION
  92. // put this on your items in the game, where the player wil lbe picking them up.
  93. // you may need to edit this depending if you use buttons, movieclips, whatever.
  94. // its written assuming? your item is in its own movieclip, eg _root.yourlevel1.itemclip.item0. if this isn't the case you may find it makes your whole movie vanish! edit as required or put items in movieclips.
  95.  
  96. on (press){
  97. _visible=false;
  98. // put the number of the item here, eg this is for item0
  99.  _root.itemget(0);
  100. }
  101.  
  102. // VARIABLES & USE
  103. // Set _root.itemheld to -1 at the start of your movie.
  104. // _root.itemheld is set to the number of the item the player is holding, and bcak to -1 when they replace it.
  105. // Lets say item2 is a key and we want to check if the player is holding it whne they try to unlock a door:
  106.  
  107. if(_root.itemheld==2){
  108. _root.replaceitem;
  109. blah blah open the door :)
  110. }
  111.  
  112. // OTHER
  113. // use _root.replaceitem() to to put any held items back in the inventory. you can call this even if they're not holding anytihng (for example, I use it whe speech plays, so that there's no items on screen while there's dialogue going on).
  114. // if you want items to vanish after using them, set their visibility or alpha in trhe inventory AFTER you call replaceitem()
  115. // this code isn';t perfect or the most efficient it could be. i improve it a little each new time i use it, but it could stil lbe a lot better
  116. // feel free to edit it however you like, i'm sure a more advanced programmer than me would laugh at it anyway ;D
  117. // the fact thatit works is good enough for me though :)
  118. // if you need more help with it go ahead and ask.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement