Tutorial-Blog There and Back Again: Making Camp with an Item
Official Content Discussion ThreadsI perhaps got a little silly with the title of this one.
I think the title is great!
This tutorial made my jaw hit the floor...to learn that I can implement my own custom notetags is a very interesting idea.
@xDRAGOONx Yeah, I was trying to find a way to get my idea working well and kind of stumbled into the idea of using notetags for it. I've played around with custom item notetags before, but this was my first try with map notetags so I was glad I was able to find something that works.
I was hoping that people would find the info useful, it'll be cool to see what other people come up with. 😉
I was hoping that people would find the info useful, it'll be cool to see what other people come up with. 😉
@hiddenone I really like this idea. No use for it in any of my current projects but I like items that do unusual things like this. One to tuck into the back pocket for later. ^_^
Yeah, I think to me that was the highlight of the tutorial. Even I was like "why have I never thought of doing this".
Interestingly enough I use this idea for my world map when the player checks the map. So with some extension you can use this idea in other creative ways too.
So your comment about custom item notetags got me thinking about the way I currently handle giving away a random item, it's easy enough because I have all my items grouped together by tier. But let's say I wanted to award a random type of weapon, i.e. a random sword from all the sword-type weapons. I know I could manually define the new array of swords, but I am interested in using js and a custom notetag on each sword to not have to do it manually.
I was looking at the Array.prototype.map() method but I couldn't quite figure out which function to pass...I can reference an individual item's notedata with $dataItems[1].note, but haven't been able to figure out how to check the entire $dataItems array.
I was trying a for loop:
but I was getting a 'cannot read property "note" of null.
So I tried:
-Pre-Post Edit-
I realized that using Yanfly's item core extends $dataItems.length beyond 2000 and that is where the null was coming from.
Using:
I was able to create a new array that contains the item Id's of any item with <array test> in it's notetag!
Now, I can give my items, weapons and armors custom notetags to group them together in various ways and award them accordingly!
While I still fully support organizing the database, this will definitely add a dynamic layer to my project, thanks again!
Also, I realize that I could probably do the random sword-type reward without the custom notetag, considering the nature of the preexisting weapon types, but that was just a simple example to make it easier to realize. My current thoughts on how to implement this align more with the idea of making 'sub-categories' such as:
I also see this being a great way to have loot pools that award random loot but remove the item from the pool after awarding it.
These tutorials are absolutely helping me expand my knowledge and abilities!
I was trying a for loop:
JavaScript:
for (var i = 1; i < $dataItems.length; i ++) { var note = $dataItems[i].note;}
So I tried:
JavaScript:
for (var i = 1; i < $dataItems.length; i ++) { if ($dataItems[i].note !== null) {var note = $dataItems[i].note;}}
-Pre-Post Edit-
I realized that using Yanfly's item core extends $dataItems.length beyond 2000 and that is where the null was coming from.
Using:
JavaScript:
for (var i = 1; i < 2001; i ++) {
if ($dataItems[i].note !== null) {
var note = $dataItems[i].note;
if (note.includes('array test>')) {
array.push($dataItems[i].id)}
}
};
I was able to create a new array that contains the item Id's of any item with <array test> in it's notetag!
Thank you for the inspiration‼
Now, I can give my items, weapons and armors custom notetags to group them together in various ways and award them accordingly!
While I still fully support organizing the database, this will definitely add a dynamic layer to my project, thanks again!
Also, I realize that I could probably do the random sword-type reward without the custom notetag, considering the nature of the preexisting weapon types, but that was just a simple example to make it easier to realize. My current thoughts on how to implement this align more with the idea of making 'sub-categories' such as:
- Items that could be secondary fishing rewards, such as seaweed or wood,
- Ingredients from a particular dish or crafting recipe,
- Linking particular gems to particular ores as potential secondary rewards when mining,
- The party leaders preferred food, giving incentive to swap leaders.
I also see this being a great way to have loot pools that award random loot but remove the item from the pool after awarding it.
These tutorials are absolutely helping me expand my knowledge and abilities!
-UPDATE-
I thought I'd drop back by and share the result of what I have been working on in regards to utilizing custom notetags. I would like to preface this by saying that I have only recently started really getting into the js of MV so while this might not be perfect, I am happy with my progress so far. That being said, I am completely open to any and all criticism, advice, suggestions, all of it. Honestly, that's why I am here. Anyway, here is the code I came up with:
JavaScript:
/*----------------------------------------------------------
* These strings are used to denote members of a loot array.
* ---------------------------------------------------------*/
ThreeSixNine.lootStrings = [
'<harvestLoot>', '<harvestHerb>', '<harvestCook>',
'<fishingLoot>', '<dayOcean>', '<nightOcean>',
'<dayRiver>', '<nightRiver>', '<dayLake>',
'<nightLake>', '<dayCave>', '<nightCave>',
'<miningLoot>', '<tier1>', '<tier2>', '<tier3>',
'<diggingLoot>', '<dirt>', '<sand>', '<grass>','<cave>'
];
/*----------------------------------------------------------
* buildLoot loops over $dataItems searching the notebox
* for the strings. The loot array variable Ids are exactly
* 600 more than the matching lootStrings index.
* $gameVariables.value(600) is storing the <harvestLoot>
* item Ids, and so on.
-----------------------------------------------------------*/
ThreeSixNine.buildLoot = function (variable) {
var loot = [];
var item = $dataItems;
for (var i = 1; i < 2001; i++) {
if (item[i].note !== null && item[i].note.includes(ThreeSixNine.lootStrings[variable - 600])) {
loot.push(item[i].id);
$gameVariables.setValue(variable, loot);
}
}
};
/*----------------------------------------------------------
* Provides the buildLoot function with its (variable) arg
-----------------------------------------------------------*/
ThreeSixNine.initializeLootArrays = function () {
for (var i = 600; i < 621; i++) {
ThreeSixNine.buildLoot(i);
}
};
/*----------------------------------------------------------
* Awards a random item from a supplied loot array.
* I am using $gameMapInterpreter so mogHunter's treasure
* pop-up will work with through a script call.
-----------------------------------------------------------*/
ThreeSixNine.getRandomLoot = function(array, type, num) {
var loot = $gameVariables.value(array);
var length = loot.length;
var id = Math.floor(Math.random() * length);
var itemId = $gameVariables.value(array)[id];
var incDec = 0; //0 for increase, 1 for decrease
var constVar = type || 0; //0 for constant, 1 for variable
var value = num || 1; //Constant Value or Variable Id
$gameMap._interpreter._params = [itemId, incDec, constVar, value];
$gameMap._interpreter.command126();
};
It did not worked for me at first, it's why I use ctrl C ctrl V, and it came with “ quotes, but you must use this " quotes. If someone got the same problem, just change from “ to " in the script call.
Thx for the guide.
Thx for the guide.
The notetag thing is really cool :0 is there a VX Ace equivalent?
Original thread: https://forums.rpgmakerweb.com/threads/there-and-back-again-making-camp-with-an-item.134022/