Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // READ THE COMMENTS BEFORE USING THIS!!
- // 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.
- // if you code wit classes, you'll need to edit thigns a bit.
- // if you code on frames, this may not work - its written assuming your game is all on one frame.
- // 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.
- // it looks complicated, but just follow the instructions carefully and its simple :)
- // highlighted lines are where you need to edit
- // BEFORE YOU USE THE CODE
- // you need a movieclip at _root.inv.inventory
- // items in the inventory should be named item0, item1, item2, etc.
- // so the path to your second item would be _root.inv.inventory.item1
- // 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.
- // 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.
- // this movieclip will show the item the player is currently holding
- // REQUIRED FUNCTIONS
- // these go on _root
- // do not edit them!
- function holdingitem(number) {
- // this is for when the player takes an item from the inventory
- for (i=0; i<_root.inventory.maxitems; i++) {
- _root.["invdisplay.item" + i]._visible = false;
- _root["inventory.inv.item" + i]._alpha = 100;
- }
- _root["_root.invdisplay.item" + number]._visible = true;
- _root["_root.inventory.inv.item" + number]._alpha = 50;
- _root.itemheld = number;
- }
- function replaceitem() {
- // this is called when you replace an item
- for (i=0; i<_root.inventory.maxitems; i++) {
- _root["invdisplay.item" + i]._visible = false;
- _root["inventory.inv.item" + i]._alpha = 100;
- }
- _root.itemheld = -1;
- }
- function itemget(number) {
- // this is for picking an item up and putting it in the inventory
- eval("_root.inventory.inv.item" + number)._visible = true;
- _root.inventory.invhilight2._visible = true;
- }
- onSelfEvent (enterFrame) {
- // this is so that the inventory display follows the mouse around
- _root.invdisplay._x = _root._xmouse;
- _root.invdisplay._y = _root._ymouse;
- }
- // INVENTORY MOVIECLIP
- // put this on the inventory movieclip (not inventory.inv)
- // edit the highlighted line only!
- // all this is for is to hide every item the player hasn't collected.
- onClipEvent (load) {
- invopen = 0;
- otheropen = 0;
- // number of items you have in total for the whole game. remember you start counting at 0.
- maxitems = 5;
- for (i = 0; i < maxitems; i++) {
- _root["inv.item" + i]._visible = false;
- }
- }
- // ON ITEMS IN THE INVENTORY
- // 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.
- on (press) {
- if (_root.itemheld !=4) {
- _root.holdingitem(4);
- }
- else {
- _root.replaceitem();
- }
- }
- // ON INVDISPLAY
- // hide items on load. dont edit this.
- onSelfEvent (load) {
- for (i = 0; i<_root.inventory.maxitems; i++) {
- _root["item" + i]._visible = false;
- }
- }
- // ITEM COLLECTION
- // put this on your items in the game, where the player wil lbe picking them up.
- // you may need to edit this depending if you use buttons, movieclips, whatever.
- // 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.
- on (press){
- _visible=false;
- // put the number of the item here, eg this is for item0
- _root.itemget(0);
- }
- // VARIABLES & USE
- // Set _root.itemheld to -1 at the start of your movie.
- // _root.itemheld is set to the number of the item the player is holding, and bcak to -1 when they replace it.
- // Lets say item2 is a key and we want to check if the player is holding it whne they try to unlock a door:
- if(_root.itemheld==2){
- _root.replaceitem;
- blah blah open the door :)
- }
- // OTHER
- // 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).
- // if you want items to vanish after using them, set their visibility or alpha in trhe inventory AFTER you call replaceitem()
- // 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
- // feel free to edit it however you like, i'm sure a more advanced programmer than me would laugh at it anyway ;D
- // the fact thatit works is good enough for me though :)
- // if you need more help with it go ahead and ask.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement