Hey there, i'm looking for a chest script. Or a inventory script eitheir way
What I want it to do is-
Once the hero gets so close to this box, and pressed said key, it will check his inventory for all items that are needed to complete the level/game. If the player has all of them, it will come up with a finish screen, if not, it tells him he doesn't have the required items.
I've experimented with many things and could find nothing that worked as effective as I would like it to.
Offline
Babado wrote:
Hey there, i'm looking for a chest script. Or a inventory script eitheir way
What I want it to do is-
Once the hero gets so close to this box, and pressed said key, it will check his inventory for all items that are needed to complete the level/game. If the player has all of them, it will come up with a finish screen, if not, it tells him he doesn't have the required items.
I've experimented with many things and could find nothing that worked as effective as I would like it to.
Hey there Babado!
You need to make a script on the chest sprite which will check to see if the player if close enough and the key is pressed. (Note that if you're game is using scrolling then this may not work correctly)
Forever if (Distance to [player] is less than (<) 50 AND key [x] is pressed
You can replace the '50' with whatever distance fits your game.
After this you need to check if the player has all of the items, the best way to do this is to add collected items to a list. You can create a list called 'inventory' and when the player collects an item, then the item is added to the inventory list. You can then check if the player has the items by putting an 'if else' statement in the script above.
IF 'inventory' contains [Sword] and 'inventory' contains [Potion of Healing]
Broadcast [Display Win Screen]
ELSE
think [I might need more items to complete this quest...] for (5) secs
I hope this works and also makes sense to you
Good luck!
(Note - if anyone can replace my Script with Scratchblocks then please take the time to do so! - Prestige)
Offline
Prestige wrote:
Babado wrote:
Hey there, i'm looking for a chest script. Or a inventory script eitheir way
What I want it to do is-
Once the hero gets so close to this box, and pressed said key, it will check his inventory for all items that are needed to complete the level/game. If the player has all of them, it will come up with a finish screen, if not, it tells him he doesn't have the required items.
I've experimented with many things and could find nothing that worked as effective as I would like it to.Hey there Babado!
![]()
You need to make a script on the chest sprite which will check to see if the player if close enough and the key is pressed. (Note that if you're game is using scrolling then this may not work correctly)
Forever if (Distance to [player] is less than (<) 50 AND key [x] is pressed
You can replace the '50' with whatever distance fits your game.
After this you need to check if the player has all of the items, the best way to do this is to add collected items to a list. You can create a list called 'inventory' and when the player collects an item, then the item is added to the inventory list. You can then check if the player has the items by putting an 'if else' statement in the script above.
IF 'inventory' contains [Sword] and 'inventory' contains [Potion of Healing]
Broadcast [Display Win Screen]
ELSE
think [I might need more items to complete this quest...] for (5) secs
I hope this works and also makes sense to you![]()
Good luck!
(Note - if anyone can replace my Script with Scratchblocks then please take the time to do so! - Prestige)
Anyway to include more than one and? I have about four items I need to store
Offline
Sure! You can stack and's infinitely. In the 2 spaces in each AND, just add another AND until you have as many as you need
Offline
Prestige wrote:
Sure! You can stack and's infinitely. In the 2 spaces in each AND, just add another AND until you have as many as you need
![]()
Thanks, one more question. I have two items called "Wood" both the same. If I set it to pick up both wood, will it realize that they only have one? Or will it cause problems as they are named the same?
Forever if
Distance to hero
less than 50
AND
Doesn't work, I can't put a and in the less than box without it not working.
Last edited by Babado (2012-04-24 17:01:13)
Offline
Babado wrote:
Thanks, one more question. I have two items called "Wood" both the same. If I set it to pick up both wood, will it realize that they only have one? Or will it cause problems as they are named the same?
Forever if
Distance to hero
less than 50
AND
Doesn't work, I can't put a and in the less than box without it not working.
If you have 2 items called the same name, it could cause an issue, you may need to calle them 'wood1' and 'wood2' and check for both. If you don't want to do this, you could set up a script where it checks each of the items individually and counts them.
To do this, create 2 new variables called 'counter' and 'tally'.
Then this script:
(when distance to player < 50 AND key 'x' pressed etc)
set counter to 1
set tally to 0
[REPEAT (length of 'inventory')
[if item counter of inventory = wood
change tally by 1]
if tally = 2
broadcast win
ELSE
broadcast 'need more stuff'
change counter by 1 ]
Oh, and you need to put the distance to thing in the lesser than box, and then the lesser than box in the AND box
<(distance to [x]) < [50]>AND if key 'x' pressed
Offline