RMMV Weapon will add a random skill from a pool / Yanfly Item Core

Klammsi

Veteran
Veteran
Joined
Nov 19, 2016
Messages
93
Reaction score
10
First Language
English
Primarily Uses
Hey everyone,

Hope you are all well.

I was hoping I can pick your brains.

In my project I have a Staff as one of the weapon types that can be equipped by the mage class. When equipped with a staff the mage will get access to "Staff Skills".

Now that's all quite straight forward but what I am struggling with is the next part.

I would like the "Staff Skills" to be picked from a random pool of skills.

Now I have already done a little research and found that with Yanfly's Item Core Plugin, link to plugin here : http://www.yanfly.moe/wiki/Item_Core_(YEP)
you can create "Independent Items". Those independent items can have this java script function:

<On Creation Eval>
item.price = baseItem.price;
item.price += Math.floor(Random() * 100);
</On Creation Eval>

which allows you to assign traits to the item on creation.

What I am struggling with is to write the JavaScript code as my knowledge is limited I am afraid.

I guess I would have to declare a variable that contains the pool of skills that can be picked from and then choose a random one...

If anybody could point me into the right direction I would be grateful.
Thank you in advance!!
 

Johnny_Ray

Also known as Toby Yasha
Veteran
Joined
Sep 11, 2019
Messages
124
Reaction score
115
First Language
English
Primarily Uses
RMMV
So you have multiple characters that can/are mages ?
And you want to have the staff to give access to 1 random skill from staff skills forever(per staff) or do you want the staff to randomly give access to 1 skill per turn?
 

Klammsi

Veteran
Veteran
Joined
Nov 19, 2016
Messages
93
Reaction score
10
First Language
English
Primarily Uses
Hey @Johnny_Ray,

Yes there are multiple characters in the game that can be mages. All of them will be able to equip Staffs. When a staff is equipped the mages will have access to the skill type "Staff Skills" during combat. When the staff is unequipped he will loose access to "Staff Skills"
This mechanic is all set up and it works fine.

What I am struggling is the randomization part.
Weapons are categorized in 5 tiers in my game. So what I would like to do for the Staffs are:
Tier Normal = 1 random Staff Skill
Tier Rare = 2 random Staff Skills
Tier Unique = 3 random Staff Skills
Tier Epic = 4 random Staff Skill
Tier Legendary = 5 random Staff Skill

So rather then creating lots and lots of different Staffs for the individual tiers,
I would like to have 1 Staff per tier and use a JavaScript function to give them a random skill.
Randomization is a big part of my game. I am using a random loot system etc.

So every time the player finds a staff it will be a different one.
That's why I was looking to do it with the function mentioned in the message above from Yanflys Item Core but I dont know how to set up the Java Script Code.

I hope this makes sense :)
 

Johnny_Ray

Also known as Toby Yasha
Veteran
Joined
Sep 11, 2019
Messages
124
Reaction score
115
First Language
English
Primarily Uses
RMMV
Hey @Johnny_Ray,

Yes there are multiple characters in the game that can be mages. All of them will be able to equip Staffs. When a staff is equipped the mages will have access to the skill type "Staff Skills" during combat. When the staff is unequipped he will loose access to "Staff Skills"
This mechanic is all set up and it works fine.

What I am struggling is the randomization part.
Weapons are categorized in 5 tiers in my game. So what I would like to do for the Staffs are:
Tier Normal = 1 random Staff Skill
Tier Rare = 2 random Staff Skills
Tier Unique = 3 random Staff Skills
Tier Epic = 4 random Staff Skill
Tier Legendary = 5 random Staff Skill

So rather then creating lots and lots of different Staffs for the individual tiers,
I would like to have 1 Staff per tier and use a JavaScript function to give them a random skill.
Randomization is a big part of my game. I am using a random loot system etc.

So every time the player finds a staff it will be a different one.
That's why I was looking to do it with the function mentioned in the message above from Yanflys Item Core but I dont know how to set up the Java Script Code.

I hope this makes sense :)
I think an important part that i've forgotten to ask about is:
Is there some class changing involved?
Are they mages by default and/or are separate actors?
If they are unique separate actors that are mages can you tell how many there are?
 

Klammsi

Veteran
Veteran
Joined
Nov 19, 2016
Messages
93
Reaction score
10
First Language
English
Primarily Uses
There is no class changing involved. mages will always be mages regardless if they are equipped with a staff or not.

Well, the main character can be a mage (the player can choose between 4 different classes)
Besides the main Character there will most likely be 3-4 more Actors that will be mages.
 

Johnny_Ray

Also known as Toby Yasha
Veteran
Joined
Sep 11, 2019
Messages
124
Reaction score
115
First Language
English
Primarily Uses
RMMV
@Klammsi sorry for late response but i think i've finally figured this one out,so:
Staff Tier 1 is simple:
JavaScript:
<Custom On Equip Eval>
// Modify actor(number) to whatever you need.
if (user == $gameActors.actor(1)) {
// Modify var min with starting skill and var max with last possible skill.
var min = 110;
var max = 121;
var skill = Math.floor(Math.random()*(max-min+1))+min;
user.learnSkill(skill);
// add as many else if statements as you need , don't forget to replace actor(number)
} else if (user == $gameActors.actor(2)) {
var min = 110;
var max = 121;
var skill = Math.floor(Math.random()*(max-min+1))+min;
user.learnSkill(skill);
}
</Custom On Equip Eval>

<Custom On Remove Equip Eval>
// Here we remove the skills for the user so he can equip other stuff and not have his skills
user.forgetSkill(110);
user.forgetSkill(111);
user.forgetSkill(112);
user.forgetSkill(113);
user.forgetSkill(114);
user.forgetSkill(115);
user.forgetSkill(116);
user.forgetSkill(117);
user.forgetSkill(118);
user.forgetSkill(119);
user.forgetSkill(120);
user.forgetSkill(121);
</Custom On Remove Equip Eval>

JavaScript:
<Custom On Equip Eval>
if (user == $gameActors.actor(1)) {
var min = 110;
var max = 121;
// this below is so the actor doesn't get the same skill twice (fireball and fireball for example)
do {
// add as many var skill with a number next to the as many skills you want for the user
var skill = Math.floor(Math.random()*(max-min+1))+min;
var skill2 = Math.floor(Math.random()*(max-min+1))+min;
// don't forget to add your new var skill with a number and with a == in the } while ()
} while(skill == skill2);
// here the user learns the skills , add your var with number in the learnSkill(here)
user.learnSkill(skill);
user.learnSkill(skill2);
} else if (user == $gameActors.actor(2)) {
var min = 110;
var max = 121;
do {
var skill = Math.floor(Math.random()*(max-min+1))+min;
var skill2 = Math.floor(Math.random()*(max-min+1))+min;
} while(skill == skill2);
user.learnSkill(skill);
user.learnSkill(skill2);
}
</Custom On Equip Eval>

<Custom On Remove Equip Eval>
user.forgetSkill(110);
user.forgetSkill(111);
user.forgetSkill(112);
user.forgetSkill(113);
user.forgetSkill(114);
user.forgetSkill(115);
user.forgetSkill(116);
user.forgetSkill(117);
user.forgetSkill(118);
user.forgetSkill(119);
user.forgetSkill(120);
user.forgetSkill(121);
</Custom On Remove Equip Eval>

You put the formula on the staff's notetag box on bottom right corner

I'm not 100% if this is perfect so feel free to tell me if something's wrong or if you didn't understand something.



IMPORTANT: You have to get waynee95 plugins for this to work.
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
964
Reaction score
616
First Language
English
Primarily Uses
RMMV
Okay, so I'd seen this topic a few days ago, and I meant to mess around a bit with an <On Creation Eval> to try to sort this out for you, mostly because I know you can do it.

I finally got a chance, and here's what you do.

First, you make an array, and in that array, store the skill Ids you want the weapon to randomly pick from.
var skills = [4, 5, 9]
Then you randomly pick one of those skills from the array.
var rdmId = skills[Math.floor(Math.random()*3)]
Then you create a trait object to add the skill to the item:
var trait = {code: 43, dataId: rdmId, value: 1}
Then you apply a trait to the item, to grant that skill on the item.
item.traits.push(trait)

To find out what the trait code was, I just added a skill to an item in the database and then checked the item from the console to see what trait was added. Code 43 is apparently add skill, the dataId is the skill Id, and I'm going to assume value 1 probably doesn't mean anything in this case.

This gives us the following on creation tag:
Code:
<On Creation Eval>
var skills = [4, 5, 9]
var rdmId = skills[Math.floor(Math.random()*3)]
var trait = {code: 43, dataId: rdmId, value: 1}
item.traits.push(trait)
</On Creation Eval>
Which randomly assigns either skill 4, 5, or 9 to the item on creation, meaning every new acquisition of it will have one of those three skills on it.

To have an item that has more than one of those skills on it, you'd need to remove the selected skill from the pool, so that it doesn't pick the same skill multiple times:

Code:
<On Creation Eval>
var skills = [4, 5, 9, 11, 15, 61]
var rdmId = Math.floor(Math.random()*skills.length)
var trait = {code: 43, dataId: skills[rdmId], value: 1}
skills.splice(rdmId, 1)
item.traits.push(trait)
rdmId = Math.floor(Math.random()*skills.length)
trait = {code: 43, dataId: skills[rdmId], value: 1}
skills.splice(rdmId, 1)
item.traits.push(trait)
</On Creation Eval>
This one is a bit more complicated, so I'll go over it again.
The first half is still the definitions, this time we have a pool of 6 skills. I changed rdmId to only be the numbers now, instead of the skillIds from the pool, this is so I can reuse the variable to remove it from the pool after. I also changed it so that it multiplies the random number by the length of the pool, rather than manually putting in the length of the pool. In the trait, we changed from just using the value: rdmId to value: skills[rdmId]. It is the same value, it's just written differently.

After a skill has been put into a trait, it is removed from the pool by splicing it out. The above tag adds two random skills from the pool and will not duplicate them. Repeat it as many times as you want, as long as you don't exceed the number of skills in the pool.
 
Last edited:

Edgeklinge

Villager
Member
Joined
Oct 24, 2016
Messages
21
Reaction score
10
First Language
English
Primarily Uses
Okay, so I'd seen this topic a few days ago, and I meant to mess around a bit with an <On Creation Eval> to try to sort this out for you, mostly because I know you can do it.

I finally got a chance, and here's what you do.

First, you make an array, and in that array, store the skill Ids you want the weapon to randomly pick from.
var skills = [4, 5, 9]
Then you randomly pick one of those skills from the array.
var rdmId = skills[Math.floor(Math.random()*3)]
Then you create a trait object to add the skill to the item:
var trait = {code: 43, dataId: rdmId, value: 1}
Then you apply a trait to the item, to grant that skill on the item.
item.traits.push(trait)

To find out what the trait code was, I just added a skill to an item in the database and then checked the item from the console to see what trait was added. Code 43 is apparently add skill, the dataId is the skill Id, and I'm going to assume value 1 probably doesn't mean anything in this case.

This gives us the following on creation tag:
Code:
<On Creation Eval>
var skills = [4, 5, 9]
var rdmId = skills[Math.floor(Math.random()*3)]
var trait = {code: 43, dataId: rdmId, value: 1}
item.traits.push(trait)
</On Creation Eval>
Which randomly assigns either skill 4, 5, or 9 to the item on creation, meaning every new acquisition of it will have one of those three skills on it.

To have an item that has more than one of those skills on it, you'd need to remove the selected skill from the pool, so that it doesn't pick the same skill multiple times:

Code:
<On Creation Eval>
var skills = [4, 5, 9, 11, 15, 61]
var rdmId = Math.floor(Math.random()*skills.length)
var trait = {code: 43, dataId: skills[rdmId], value: 1}
skills.splice(rdmId, 1)
item.traits.push(trait)
rdmId = Math.floor(Math.random()*skills.length)
trait = {code: 43, dataId: skills[rdmId], value: 1}
skills.splice(rdmId, 1)
item.traits.push(trait)
</On Creation Eval>
This one is a bit more complicated, so I'll go over it again.
The first half is still the definitions, this time we have a pool of 6 skills. I changed rdmId to only be the numbers now, instead of the skillIds from the pool, this is so I can reuse the variable to remove it from the pool after. I also changed it so that it multiplies the random number by the length of the pool, rather than manually putting in the length of the pool. In the trait, we changed from just using the value: rdmId to value: skills[rdmId]. It is the same value, it's just written differently.

After a skill has been put into a trait, it is removed from the pool by splicing it out. The above tag adds two random skills from the pool and will not duplicate them. Repeat it as many times as you want, as long as you don't exceed the number of skills in the pool.
Hello, how do you code a description for "that random skill which got added" in equipment box? Preferably using <info eval> and msg core or something?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
3,178
Reaction score
1,876
First Language
English
Primarily Uses
RMMV
Hello, how do you code a description for "that random skill which got added" in equipment box? Preferably using <info eval> and msg core or something?
You could change the info of the item by using the \V escape code and storing the description in a game variable.

Then, in your Info Eval, you check for the presence of a skill-granting trait on the weapon. If it has it, you set the variable in your info box equal to a string that talks about having the skill; else, set the variable equal to the info string you'd display for the item normally.
 

Edgeklinge

Villager
Member
Joined
Oct 24, 2016
Messages
21
Reaction score
10
First Language
English
Primarily Uses
You could change the info of the item by using the \V escape code and storing the description in a game variable.

Then, in your Info Eval, you check for the presence of a skill-granting trait on the weapon. If it has it, you set the variable in your info box equal to a string that talks about having the skill; else, set the variable equal to the info string you'd display for the item normally.
tbh i have no idea what you're trying to say since i'm a total noob in custom javascript. can u please help me :kaoswt:
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
3,178
Reaction score
1,876
First Language
English
Primarily Uses
RMMV
tbh i have no idea what you're trying to say since i'm a total noob in custom javascript. can u please help me :kaoswt:
Yeah, but you should really post your own thread asking for help with it instead of someone else's year-old thread on a different topic :wink:
 

Latest Threads

Latest Posts

Latest Profile Posts

I have uploaded my Pastel Life tileset to MV resources on the forum.
The set is made to be Easy to Edit and absolutely Child Friendly.

The set is far from finished, so there will be updated coming up...
Here is a little preview, though.
Should've seen this coming, but if I wanted players crafting equipment, I should also have a bestiary ready.

C'mon Marx, you played Monster Hunter...!
After a long absence I am back
Sigh gonna have to scrap a big thing for my battle system but that's fine, I can event it all just gonna take more time than I'd like. But that just leaves room for more cosmetic stuff so it's not the worst thing in the world.
Falling Crew1.png

the four main characters falling into a pocket dimension known as Escape Space.

Forum statistics

Threads
118,551
Messages
1,116,901
Members
155,588
Latest member
Pinnam
Top