RMMV Adding a function/property to all armors/weapons? (SOLVED)

Status
Not open for further replies.

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
163
First Language
Swedish
Primarily Uses
N/A
Been trying to figure out how to do this, but trying to find a constructor or similar with $dataWeapons[2].__proto__ didn't yield any results. In the rpgmanagers.js I also cannot find any class or similar that adds functions to items. Checking the weapons.json was also fruitless as it only stores actual data.

So I am wondering where the functions that exist in an item comes from?

Any help or suggestions is appreciated!

Best regards,
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
6,011
Reaction score
5,976
First Language
English
Primarily Uses
RMMZ
You would add new properties in the database loading functions, generally, since equipment data all comes from the json files. Equipment-based functions are usually defined on Game_Actor. Can you give me an example of a function you think works otherwise?
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
163
First Language
Swedish
Primarily Uses
N/A
You would add new properties in the database loading functions, generally, since equipment data all comes from the json files. Equipment-based functions are usually defined on Game_Actor. Can you give me an example of a function you think works otherwise?
I sadly have no functions in mind, I was primarly assuming that there should be some. I have several, but I have had a feeling that they are all from plugins. Such as cerArmorPenFlat(). This being from a plugin.

So if I wanted to add say:
getParam() to all items?

JavaScript:
Items.prototype.getParam = function(id) {
    if (BISH.itemHasParam(BISH.ItemParamNames[id]))
            return {BISH.ItemParamNames[id], BISH.ItemParamValues[id]} ;   
    }
}

What would be the best way to do this? Just loop through $dataWeapons and $dataArmors?

best regards,
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
6,011
Reaction score
5,976
First Language
English
Primarily Uses
RMMZ
I would add it as a function to DataManager. That's where functions like isWeapon and isArmor are defined.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
163
First Language
Swedish
Primarily Uses
N/A
I would add it as a function to DataManager. That's where functions like isWeapon and isArmor are defined.
Hm... How would I add in such a way that it can be called like: $dataWeapons[x].getParam(id)? I tried $dataWeapons[x].isWeapon, but it does not exist. No surprise there, but that's why I am asking if there is a better way than looping to add the function to each item?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
37,938
Reaction score
10,520
First Language
German
Primarily Uses
RMMV
I think you make wrong assumptions on how the engine works.

No weapon in the game has any function at all. All equipment (and that includes weapons) is nothing but an add-on to the actor. Equipping a weapon (or anything else) does nothing but add values to the actor itself.
As such you need to define whatever new parameter you want on the actor, and the weapon will only tell the engine "add number n to the actor parameter x".

Same with any new function or property - they should be added to the actor, and the equipment is only there as a condition or modifier.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
6,011
Reaction score
5,976
First Language
English
Primarily Uses
RMMZ
Hm... How would I add in such a way that it can be called like: $dataWeapons[x].getParam(id)? I tried $dataWeapons[x].isWeapon, but it does not exist. No surprise there, but that's why I am asking if there is a better way than looping to add the function to each item?
DataManager is a singleton class; its functions can be called without instantiating it. So you would use that to add/call your function:

JavaScript:
DataManager.getParam = function(typeId, itemId, paramId) {
    if (typeId === 0) return $dataWeapons[itemId].params[paramId];
    if (typeId === 1) return $dataArmors[itemId].params[paramId];
}

Then you'd do something like DataManager.getParam(1, 5, 3) to get the attack power of armor 5.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
163
First Language
Swedish
Primarily Uses
N/A
I think you make wrong assumptions on how the engine works.

No weapon in the game has any function at all. All equipment (and that includes weapons) is nothing but an add-on to the actor. Equipping a weapon (or anything else) does nothing but add values to the actor itself.
As such you need to define whatever new parameter you want on the actor, and the weapon will only tell the engine "add number n to the actor parameter x".

Same with any new function or property - they should be added to the actor, and the equipment is only there as a condition or modifier.
Ah alright...
I guess I will be looping it in then, or using the DataManager as in Trihans example. Thanks! :)

DataManager is a singleton class; its functions can be called without instantiating it. So you would use that to add/call your function:

JavaScript:
DataManager.getParam = function(typeId, itemId, paramId) {
    if (typeId === 0) return $dataWeapons[itemId].params[paramId];
    if (typeId === 1) return $dataArmors[itemId].params[paramId];
}

Then you'd do something like DataManager.getParam(1, 5, 3) to get the attack power of armor 5.
Thanks, now I understand how you meant, I think. As I understand it, I could just use BISH instead of DataManager? There is no specific benefit for what I want for using the DataManager class right?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,555
Reaction score
5,321
First Language
English
Primarily Uses
RMMV
I tried $dataWeapons[x].isWeapon, but it does not exist.
I don't understand what that would do. If you're looking inside $dataWeapons, then you already know it's a weapon. Why would you need this?

The closest thing to what you're describing is in the EquipItem class, EquipItem.eTypeId where 0: Weapon 1: Shield 2: Head 3: Body 4: Accessory
Hm... How would I add in such a way that it can be called like: $dataWeapons[x].getParam(id)?
Again, why do you need this? There's already a Weapon.params array that stores how much the weapon modifies each parameter by. Why do you need to turn it into a function and loop through anything?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
6,011
Reaction score
5,976
First Language
English
Primarily Uses
RMMZ
Ah alright...
I guess I will be looping it in then, or using the DataManager as in Trihans example. Thanks! :)


Thanks, now I understand how you meant, I think. As I understand it, I could just use BISH instead of DataManager? There is no specific benefit for what I want for using the DataManager class right?
Yes, there's no reason you have to use DataManager. You can use your own encapsulating class if you'd prefer. Though ATT_Turan is right in that this currently seems redundant if it's nothing more than you've asked for here as that functionality already exists on equipment.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
163
First Language
Swedish
Primarily Uses
N/A
I don't understand what that would do. If you're looking inside $dataWeapons, then you already know it's a weapon. Why would you need this?

The closest thing to what you're describing is in the EquipItem class, EquipItem.eTypeId where 0: Weapon 1: Shield 2: Head 3: Body 4: Accessory

Again, why do you need this? There's already a Weapon.params array that stores how much the weapon modifies each parameter by. Why do you need to turn it into a function and loop through anything?
In response to the first part:
It was just a test based on one of @Trihan 's suggestions.
I tried $dataWeapons[x].isWeapon in order to see if the DataManager function isWeapon would be attached to $dataWeapons, just like it would if it was a constructor. So I had no interest in the actual isWeapon(). It was just to see if adding something to DataManager would also add it to all current and potential items. Want to add that I did not think it would work that way.

In response to the next:
Yes, there is a rather lackluster param that holds a total of 8 params, then we have traits, which is rather lackluster again... Some confusion may arrive from the fact that I never use another term rather than "params". I do actually mean all parameters, traits and custom attributes(elementAmplify).

I am making an array that holds all the different values along with the names of each parameter. Then I can make easier comparisons equipment comparisons. I have SRD_EquipCompareUpgrade, but it only works in Equipment, not in shop. Which tbh, makes it rather pointless. And I've tried to find something that does this, but I've found nothing.
1634753684988.png
And this Window above, shows very little relevant information. How are the player to know that they'll get +15% Magic reflect, or that it increases the hit rating by 6%?

And I spent about 5+ hours trying to implement the Window_StatCompare into Scene_Shop, but I've had hardly any success. I've asked in another thread how to refresh another Window based on when you select a new item in the Window_ShopBuy. And @caethyril has answered that question rather well I believe, I've yet to try and implement it so I don't know. @caethyril 's answer will help me quite a bit in my efforts anyway.

And I haven't written the reason for why I am asking these questions as I haven't found it to be relevant, and seeing how I've posted about 4 threads relating to my main objective but that touch on different subjects, I feel posting the entire description of what I am doing and why seems like a bit of time waste for everyone :p

But in the end, I do not believe there is an effective plugin that performs comparisons, equally, on all different Scenes. And I also believe that these plugins slow down the game as they prepare for to many things. Whenever I change item in Scene_Equip I get a lag spike, as it goes over all the functions. I feel it'd be better to just get the equipped item, and compare it to the selected item, using nothing more than the parameter value.

But in the real end, I see it as a challenge to make these things. I evolve as a programmer when I try to figure out what is going on. So even though there may be a plugin that does this, I prefer to learn to do it myself as well. Even though I do use a lot of plugins :)

Best regards,
Bishiba
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
163
First Language
Swedish
Primarily Uses
N/A
Yes, there's no reason you have to use DataManager. You can use your own encapsulating class if you'd prefer. Though ATT_Turan is right in that this currently seems redundant if it's nothing more than you've asked for here as that functionality already exists on equipment.
See above :)
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
6,011
Reaction score
5,976
First Language
English
Primarily Uses
RMMZ
See above :)
I mean you COULD do something like

$dataWeapons[x].isWeapon = DataManager.isWeapon($dataWeapons[x]) but that's obviously rather redundant.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
163
First Language
Swedish
Primarily Uses
N/A
I mean you COULD do something like

$dataWeapons[x].isWeapon = DataManager.isWeapon($dataWeapons[x]) but that's obviously rather redundant.
Hahaha xD Beautiful :p You can look at something I did in my code just now, felt awkward when I put in there, but eeh, I don't know how else to get the index number in that instance :) It's the last function below. See the line:
JavaScript:
var id = item.paramsName.indexOf(item.paramsName[index]);

JavaScript:
BISH.setItemFunctions = function(item) {
    item.hasTrait = function() {
        console.log(item.traits.length);
        return item.traits.length > 0 ? true : false;
    }

    item.setTrait = function(index, code, dataId) {
        for (let i = 0; i < item.traits.length; i++) {
            console.log(i);
            if (item.traits[i].code == code)
                if (item.traits[i].dataId == dataId) {
                    item.paramsValue[index] = item.traits[i].value;
                    return true;
                }
        }
        return false;
    }

    item.getParam = function(index) { //index of .paramsName or param name.
        if (typeof index == "string")
            index = item.paramsName.indexOf(index);
        var name = item.paramsName[index];
        var value = item.paramsValue[index];
        var id = item.paramsName.indexOf(item.paramsName[index]);
        return {id, name, value};
    }

}

But here is the current functions that I am adding to the item. Just gonna have to add two functions for adding "Attack element" and for adding "Add Skill".
Currently you get this response with the following command:
1634756697007.png
So, exactly what I want :)
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
10,103
Reaction score
6,392
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

i think this girl has to be my favorite though :)
62702017_JJKXazrs2LInoZh.png
Wouldn't you know it? Every woman that is interested in me on FB is a bot. Maybe I should respond with 000100100011. If u r willing to date women on FB something has definitely went wrong with your life.
Hello world !! I've created a logo design for my game, I'm calling it "Soup Quest" (It was honestly the best I could come up with <:]) !!
[IMG]https://media.discordapp.net/attachments/866542330286178344/1076307540528332830/Soup_Quest_Game_Logo.png?width=473&height=473[/IMG]
P.S. ty to the person who told me about the "purple text not mixing well with dark mode". I'll be careful on using colored text in the future !!
woootbm wrote on TheAM-Dol's profile.
On your last stream you were talking about dev's who remake or remaster the same game rather than moving on. Does this happen a lot? Me and Tony were thinking of covering a game that did this. We're baffled by the idea and wanted to investigate the game.
...Damn it has been a hot minute since I was here. How y'all doing, how's life been?

Forum statistics

Threads
129,745
Messages
1,204,783
Members
170,832
Latest member
GoonyMandolin
Top