Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Item_ID

Status
Not open for further replies.

BlueByt3

Villager
Xy$
0.00
Hi there,

I wanna apologies beforehand because I will use your help a lot I suppose.

So I was trying something to decrease workload ...instead of using 1 million common events for 1 million items to use and event on each specific one - i wanted to use 1 common event for 1million items. J/k but many items.

So I wanted something like:

Use item -> check item id

switch case item id 0005

add party member x

switchase item id 0006

add party member y

etc

So what I did so far was make the items to key items and use the event block "choose item: Keyitem, Item-Check ( for variable name")
then I would need some sort of variable to save an item_id in to check if item-check is identical with the variable for each of the items I put into the game. I dont know how to check for item-ids in scripts.

Can you help me out?

Thanks a lot

BlueByt3
 
So you need the item that was used to call the common event?

Why don't you pop this piece of code (download the js, put it into your js/plugins folder and enable in RPG Maker MV with the green symbol at the top). Just change the first number to a variable you'd like it to be stored in and that should mean that the variable becomes the item that was triggered.

Code:
Game_Battler.prototype.useItem = function(item) {
    if (DataManager.isSkill(item)) {
        this.paySkillCost(item);
    } else if (DataManager.isItem(item)) {
        $gameVariables.setValue(1, item.id); //Set the first number to a varible
        this.consumeItem(item);
    }
};
https://mega.nz/#!mNczTSrD!MqIfhaJJzl2ZB6_Or0t1TxCMyZoq7AmEOYJCzCjvaXw

See this line: $gameVariables.setValue(1, item.id); ?

Change the 1 to a variable number you'd like to store it.

If that isn't what you needed maybe I misunderstand.
 

BlueByt3

Villager
Xy$
0.00
Hey, thanks for your fast reply. I will try this after work - but from the looks I am not sure if it does what I want it to do.

Simply put:

I want to get item_id of the item I used (in or out of combat). So I can save it into a variable and then use the variable to check it with other variables.

Greetz
BlueByt3
 
Yeah that should do it then. Just change the number to the variable then use conditional branches or cases as suggested.

That piece of code simply put when you use an item stores the item id in the var so in theory that should be it. If you also need to get other information from the item database just give me a shout and I'll grab the code for that.
 

BlueByt3

Villager
Xy$
0.00
Thanks a lot kind sir, Lord Bones. I will test it and get back to you later.
[doublepost=1460658811,1460629481][/doublepost]Hi, I still don't get what I should put instead of the 1 and what this function actually does. Is it right to assume that it doesnt matter what function as long as it calls on an item that is used and writes its variable? Well ...and yea I guess i actually need to have the Item.ID of the used items and the item.id of all items I created beforehand in variables so I can go and make a comparison.

I want the user to use different items to call different party members. But I only want to use 1 common event for all items and in that common event I want to compare the item used with all the variables I setup beforehand with the item.ids of created items and then I want to add different party members depending on the item used...I am sorry if me repeating myself is redudant, but i am not good with coding and I know when I get the knack of it I will ask less questions....

can you explain the function too...(sorry for the trouble) :(

Thx beforehand

BlueByt3
 
You know the variables:

That's the number to change it to.
In your common event then put something like this:


It basically set the var to the last item used. If the var was lets say 15 it'd show text with the item_id of the item used. Obviously this is to show you, use case with the number like you suggested.

Update: Once you have gotten to this stage tell me about how you want this party member thing to work.
 
Last edited:

BlueByt3

Villager
Xy$
0.00
lol it worked...i did not use it as plugin but as script direct in the common event - whats the difference? shouldnt it work the same only that plugin is like some kind of include...
 
The difference just is that you know the code has ran because if let's say you changed it on an event in a map, if that code didn't run that playthrough it wouldn't necessarily change the global event. Plugins are just a safe was to know the code has run.

If you've run it in the common event you might find that it runs after the first time but not the first because the code overrides a function.

Did you say something about party members? You want to know what party member too or something?

If so here:
Code:
$gameVariables.setValue(1, $gameParty._lastItem._itemId);
$gameVariables.setValue(1, $gameParty._targetActorId);
This is much smaller, found a var in the $gameParty... you can just pop this at the top of your common event. Then use condition branches / case :)
 
Last edited:
Awesome! You might want to use the slightly shorter code I wrote in the previous comment (it won't really matter which) and the text thing was only the test it out ;)

Anyway you're welcome!
 

BlueByt3

Villager
Xy$
0.00
$gameVariables.setValue(1, $gameParty._targetActorId);

what does it do? :)

I need something else. I only want the main-actor to be able to call 1-2 more companions. So i have to remove actor 2 + 3 whenever they either die or when an item to call another member is used =/...i cannot limit actors because I use monsters to call as actors already...

 
Last edited:
The code essentially is just shorter because I was going the long way around something that RPG Maker keeps a record of. So you can delete the plugin and just have this at the top of your event:
Code:
$gameVariables.setValue(1, $gameParty._lastItem._itemId);
$gameVariables.setValue(1, $gameParty._targetActorId);
Now in order to do the only person able to call the others, I'm gathering it's not a consumable? If so see the footer of this if not then look below at how you might do this. Assume that ItemID is the last item ID and Actor Id is the last actor to use it. These are the first and second lines of the code. Lets say you only want actor 1 to be able to do it.

Lets go through this.
  • You don't need the plugin with this, this is everything.
  • Start with the script in the common event.
  • Change the first one to where you want to store the item id
  • Change the second to where you want to change the actor id

  • Then check to see if the right actor used the scroll. If not play a bad sound.
  • Now if this is a consumable give them it back

  • Next in the else (the are the actor you're looking for is the right one), remove the party members.
  • Next check which scroll with the item id, and then add the party members. (Do some code)

Does this make sense?

If many actors are able to summon it you can make a sort of kind of 'or' using a switch I can teach you that if you don't know what I mean.

Post Script: The new code will stop any other plugin messing with this and vice versa.
 

BlueByt3

Villager
Xy$
0.00
Thats pretty cool, I think I get it and will try it out in short. I've should've come up with that conditional branch for checking the actor id to see if he is allowed to use the item.

I think the problem is still, if I make it like this it keeps increasing the party size still. You know what I mean? I want to exchange the 2nd actor and for some classes even the 3rd (are able to summoner 2 monsters) and I do not want to add:

Remove Actor 2 (Example you did with Sila)
Remove Actor 3
Remove Actor 4
Remove Actor 5

I do not want to remove them single-handly I need some kind of do while that increases actor ID while it removes monsters from actor id 2 till x, like above - Because I will use a lot of different monsters and want to keep the code clean :P.

The script itself should work, thanks a lot.
I kinda thought that only those 2 lines are neccessary - I was kinda confused with all the other lines but I assumed you took some snippet because you did not know the direct way to call on last_item_used. Thanks a lot for your efforts so far - you helping me understanding this a lot. I appreciate that.
 
Okay, this required a plugin so see the code below or download the js.
JavaScript:
function LB_PartyMembersRemove(ids){
    if(!ids){console.log("No Ids found");}
    var spliceList = new Array;
    ids = String(ids);
    if(ids.search(",") == -1 && ids.search("-") == -1){ ids = parseInt(ids);
        for (i = 0; i < $gameParty._actors.length; i++) {
            if(ids == $gameParty._actors[i]){
                $gameParty._actors.splice(i,1);
            }
        }
    } else if(ids.search(",") != -1) {
        ids_array = ids.split(",");
        for (i = 0; i < $gameParty._actors.length; i++) {
            for (i2 = 0; i2 < ids_array.length; i2++) {
                if(ids_array[i2] == $gameParty._actors[i]){
                    $gameParty._actors.splice(i,1);
                }
            }
        }
    } else if(ids.search("-") != -1) {
        ids_array = ids.split("-");
        idNumberOne = parseInt(ids_array[0]);
        idNumberTwo = parseInt(ids_array[1]);
        if(idNumberOne > idNumberTwo){maxNumber = idNumberOne; minNumber = idNumberTwo;} else {maxNumber = idNumberTwo; minNumber = idNumberOne;}
        for (i = $gameParty._actors.length - 1; i > -1; i--) {
            if(parseInt($gameParty._actors[i]) <= maxNumber && parseInt($gameParty._actors[i]) >= minNumber){
                $gameParty._actors.splice(i,1);
            }
        }
       
    }
    LB_UpdateFormation();
}

function LB_UpdateFormation(){
    //Just setup the main player sprite
    $gamePlayer._characterName = $gameActors._data[$gameParty._actors[0]]._characterName; //This is the image
    $gamePlayer._characterIndex = $gameActors._data[$gameParty._actors[0]]._characterIndex; //This is which of the image sections
    //Make the characters blank to start with:
    $gamePlayer._followers._data[0]._characterName = ""; $gamePlayer._followers._data[1]._characterName = ""; $gamePlayer._followers._data[2]._characterName = "";
    if($gameParty._actors.length > 1){ //Then setup party member 2
        $gamePlayer._followers._data[0]._characterName = $gameActors._data[$gameParty._actors[1]]._characterName;
        $gamePlayer._followers._data[0]._characterIndex = $gameActors._data[$gameParty._actors[1]]._characterIndex;
    }
    if($gameParty._actors.length > 2){  //Then setup party member 3
        $gamePlayer._followers._data[1]._characterName = $gameActors._data[$gameParty._actors[2]]._characterName;
        $gamePlayer._followers._data[1]._characterIndex = $gameActors._data[$gameParty._actors[2]]._characterIndex;
    }
    if($gameParty._actors.length > 3){ //Then setup party member and 4
        $gamePlayer._followers._data[2]._characterName = $gameActors._data[$gameParty._actors[3]]._characterName;
        $gamePlayer._followers._data[2]._characterIndex = $gameActors._data[$gameParty._actors[3]]._characterIndex;
    }
}
https://mega.nz/#!mNczTSrD!MqIfhaJJzl2ZB6_Or0t1TxCMyZoq7AmEOYJCzCjvaXw

So here's how you use it:
Call this script in your common event where you want the command to remove actors / party members:
LB_PartyMembersRemove("1");
See the 1? Well in there you put the actor ids found in the database. Now you don't just have to write one in there these are the options:
  • If you write a number that one will be removed
  • If you write it with commas in between e.g. "1,3,5,6" any of those actors will be removed but not the ones in between.
  • If you write it with a dash in there e.g. "1-3" it'll remove any actor id between 1 and 3, so 1, 2 and 3.
Will this work or at least be part of the way there?
 

BlueByt3

Villager
Xy$
0.00
Wow. This is your own plugin? Much amaze! This work perfectly fine for my needs. I could use this to remove the party members like shown in the Picture. Also I managed to get the else-branch working with the add item from the game variable...now I know how this works too. Everything works fine so far and I think I can use this common-event in the future to add character and class-specific summoning options too. This is awesome.



Also, when do you tend to use plugins, and when do you just use Script Blocks - or basically, do you sometimes tend to just use javascript instead of rpg maker commands and just make a call on the functions afterwards in rpg maker?


I suppose I do not need the second part of your plugin with update formation, but leaving it in the plugin won't hurt - maybe ill need it some time.

Hey, I just checked and I think, I cannot summon in battle -maybe because he cannot read actor-ID, what do you think?
 
Last edited:
I used to be all about the event system back when I used xp however now I'm the exact opposite, even text is going to call a script. To be honest the current game I'm making only uses events as ways to call scripts and images on the tileset. However that's because of how lazy I am... I could make a single plugin that'd allow me to do a lot of tasks once. That and the rpg maker variable system is quite awful including there being no logical operators or like an else if with out a lot more work than just writing it.

The second part of the plugin is required to have the appropriate actor and followers on the screen. It basically manually updates it.

In terms of summoning in battle I'm actually not sure, my guess is there's a separate array that is edited when you go into battle that'll probably take a little more time so I'll get back to you, edit this post and drop a message when I figure it out.

Update: Hey, just looked at the battle system with my script and it works? I was able to remove a party member and able to summon a party member. I summoned them using the event system method but removed them using the script. If you're having issues my guess is you're using some other system? If so if you could let me know so I can recreate the same conditions because right now it works lol.

Update2:
Okay I've gotten it to work. Now I decided to make this more of a complete plugin. So see the code and the JS from mega. This is now the finished product provided there aren't any errors.
JavaScript:
//=============================================================================
/*:
* @plugindesc v1.00 Item Use Common Event system
* @author TheLordBones
*
* @param ItemID Var
* @desc Which varible do you want the ItemID stored in?                          .
* Default: 1
* @default 1
*
* @param ActorID Var
* @desc The actor using the item var.                        .
* Default: 2
* @default 2
*
* @param TargetID Var
* @desc In Battle there's also a target ID                       .
* Default: 3
* @default 3
*
*
* @param TargetNotEqualActor
* @desc If you want it to not log if the target of the item doesn't equal the actor using it. true or false.                  .
* Default: false
* @default false
*
*
* @param DebugMode
* @desc Developer Use                 .
* Default: false
* @default false
*
* @help
* Set the values to vars you'd like the value to be stored. If you don't want it
* to be stored in general, put -1 or leave it blank.
*/
//=============================================================================
var parms = PluginManager.parameters("ItemUseCommon");
var LB_storeItemId = Number(parms['ItemID Var'] || -1);;
var LB_storeActorId = Number(parms['ActorID Var'] || -1);;
var LB_storeTargetId = Number(parms['TargetID Var'] || -1);;
var LB_storeActorTargetSetting = String(parms['TargetNotEqualActor'] || false);
if(LB_storeActorTargetSetting == "true"){ LB_storeActorTargetSetting = true; } else { LB_storeActorTargetSetting = false;}
var LB_storeActorDebugMode = String(parms['DebugMode'] || false);
if(LB_storeActorDebugMode == "true"){ LB_storeActorDebugMode = true; } else { LB_storeActorDebugMode = false;}

if(LB_storeItemId < -1 || LB_storeItemId > 5000 || LB_storeItemId == 0){ console.log("Please define LB_storeItemId");}
if(LB_storeActorId < -1 || LB_storeActorId > 5000 || LB_storeActorId == 0){ console.log("Please define LB_storeActorId");}
if(LB_storeTargetId < -1 || LB_storeTargetId > 5000 || LB_storeTargetId == 0){ console.log("Please define LB_storeTargetId");}

var LB_targetActor = 0;
var LB_Item = 0;
var LB_inBattle = false;

function LB_PartyMembersRemove(ids){
    if(!ids){console.log("No Ids found");}
    var spliceList = new Array;
    ids = String(ids);
    if(ids.search(",") == -1 && ids.search("-") == -1){ ids = parseInt(ids);
        for (i = 0; i < $gameParty._actors.length; i++) {
            if(ids == $gameParty._actors[i]){
                $gameParty._actors.splice(i,1);
            }
        }
    } else if(ids.search(",") != -1) {
        ids_array = ids.split(",");
        for (i = 0; i < $gameParty._actors.length; i++) {
            for (i2 = 0; i2 < ids_array.length; i2++) {
                if(ids_array[i2] == $gameParty._actors[i]){
                    $gameParty._actors.splice(i,1);
                }
            }
        }
    } else if(ids.search("-") != -1) {
        ids_array = ids.split("-");
        idNumberOne = parseInt(ids_array[0]);
        idNumberTwo = parseInt(ids_array[1]);
        if(idNumberOne > idNumberTwo){maxNumber = idNumberOne; minNumber = idNumberTwo;} else {maxNumber = idNumberTwo; minNumber = idNumberOne;}
        for (i = $gameParty._actors.length - 1; i > -1; i--) {
            if(parseInt($gameParty._actors[i]) <= maxNumber && parseInt($gameParty._actors[i]) >= minNumber){
                $gameParty._actors.splice(i,1);
            }
        }
   
    }
    LB_UpdateFormation();
}

function LB_UpdateFormation(){
    //Just setup the main player sprite
    $gamePlayer._characterName = $gameActors._data[$gameParty._actors[0]]._characterName; //This is the image
    $gamePlayer._characterIndex = $gameActors._data[$gameParty._actors[0]]._characterIndex; //This is which of the image sections
    //Make the characters blank to start with:
    $gamePlayer._followers._data[0]._characterName = ""; $gamePlayer._followers._data[1]._characterName = ""; $gamePlayer._followers._data[2]._characterName = "";
    if($gameParty._actors.length > 1){ //Then setup party member 2
        $gamePlayer._followers._data[0]._characterName = $gameActors._data[$gameParty._actors[1]]._characterName;
        $gamePlayer._followers._data[0]._characterIndex = $gameActors._data[$gameParty._actors[1]]._characterIndex;
    }
    if($gameParty._actors.length > 2){  //Then setup party member 3
        $gamePlayer._followers._data[1]._characterName = $gameActors._data[$gameParty._actors[2]]._characterName;
        $gamePlayer._followers._data[1]._characterIndex = $gameActors._data[$gameParty._actors[2]]._characterIndex;
    }
    if($gameParty._actors.length > 3){ //Then setup party member and 4
        $gamePlayer._followers._data[2]._characterName = $gameActors._data[$gameParty._actors[3]]._characterName;
        $gamePlayer._followers._data[2]._characterIndex = $gameActors._data[$gameParty._actors[3]]._characterIndex;
    }
}

function LB_UpdateVaribles(actorId,itemId,targetId,inBattleCommon){
    if($gameParty._inBattle == true && !inBattleCommon){ //BattleCommon stops the function running in the common event during battles.
        //Start by ensuring we have values.
        if(!actorId){ if(LB_storeActorDebugMode == true){console.log("ItemUseCommonError - actorId not sent"); } return false; }
        if(!itemId){ if(LB_storeActorDebugMode == true){console.log("ItemUseCommonError - itemId not sent");} return false; }
        if(!targetId){ if(LB_storeActorDebugMode == true){console.log("ItemUseCommonError - targetId not sent");} targetId =  actorId;}
        //Start by storing the item ID
        if(LB_storeItemId != -1){ //-1 means don't set.
            $gameVariables.setValue(LB_storeItemId, itemId);
        }
        if(LB_storeActorTargetSetting != true || LB_storeActorTargetSetting == true && actorId == targetId){ //Need to double check target settings
            if(LB_storeActorId != -1){ //-1 means don't set.
                $gameVariables.setValue(LB_storeActorId, actorId);
            }
            if(LB_storeTargetId != -1){ //-1 means don't set.
                $gameVariables.setValue(LB_storeTargetId, targetId);
            }
        } else {
            if(LB_storeActorId != -1){ //-1 means don't set.
                $gameVariables.setValue(LB_storeActorId, 9001);
            }
            if(LB_storeTargetId != -1){ //-1 means don't set.
                $gameVariables.setValue(LB_storeTargetId, 9001);
            }
        }
    } else if($gameParty._inBattle == false){
        if(LB_storeItemId != -1){ //-1 means don't set.
            $gameVariables.setValue(LB_storeItemId, $gameParty._lastItem._itemId);
        }
        if(LB_storeActorId != -1){//-1 means don't set.
            $gameVariables.setValue(LB_storeActorId, $gameParty._targetActorId);
        }
        if(LB_storeTargetId != -1){ //-1 means don't set.
            $gameVariables.setValue(LB_storeTargetId, $gameParty._targetActorId);
        }
    }
}

BattleManager.startAction = function() {
    var subject = this._subject;
    var action = subject.currentAction();
    var targets = action.makeTargets();
    this._phase = 'action';
    this._action = action;
    this._targets = targets;
    if(subject._actorId >= 1 && action._subjectActorId >= 1){ //If there are vars
        LB_UpdateVaribles(subject._actorId,action._item._itemId,$gameParty._actors[action._targetIndex]);//Run the setter
    }
    subject.useItem(action.item());
    this._action.applyGlobal();
    this.refreshStatus();
    this._logWindow.startAction(subject, action, targets);
};
https://mega.nz/#!TJ0XiRLJ!3rzjwJeddNa3hylt194b9khSUUoc-4uECC7iW45wTtk

This has to be named ItemUseCommon.js in your plugins folder.

Once you've installed it you're going to want to customise things:

  • ItemID Var is the variable you'd like the ItemID to be stored within. -1 means you don't want that to be stored
  • ActorID Var is the variable you'd like the ActorID to be stored within. -1 means you don't want that to be stored
  • TargetID Var is the variable you'd like the TargetID to be stored within. -1 means you don't want that to be stored
  • Target Not Equal Actor means if the target and the actor don't match then set them both to 9001.
Let me explain the TargetID. Within a battle there were two things I could get, the person using the item and who they were using the item on. I store the person using the item as the ActorID and the person they're using it on as TargetID. Now if you don't mind whether or not they use the item on themselves or someone else then leave this to false. If you want them only to ever use this item on themselves then define this as true. In the event that they use the item on someone else and that is true it'll set the Actor and Target to 9001.

Outside of battle ActorID and TargetID equal one another.

Now on to the common event:
The very top of your script should now read:
JavaScript:
LB_UpdateVaribles(-1,-1,-1,true);
Delete the other code with the variables from there completely. This will be the function to set these now.

Use of the function 'LB_PartyMembersRemove' has not changed so continue to use that as before.

Hopefully that works please get back to me if not, and you're welcome lol

Update... I've lost count: If this works, I might post it up publically it's not like it's public now but it's now like a thing that might be useful for others because it's pretty open.

Update 4: You reported a problem I couldn't find. See the mega link to a project.
It seems to work for me but not you, this makes me wonder what battle plugins you have
https://mega.nz/#!fINixJDC!EDc3grziS0yCxi5cYSR7OsSxCuuBc_Un5o1lsnUuDmc

Ohh try running my script at the top then at the bottom, might be an issue with the side view battlers. One of them might work.

Update 5: This is now fixed so targetID = actorID if targetID is undefined. The link has been updated.
 
Last edited:

BlueByt3

Villager
Xy$
0.00
I use side-view battle system that comes with RPG Maker MV. No further plugins, so far.

Here Some Pseudo Code:

Code:
Variables:
0001 Item-ID
0002 Actor-ID
0003 Target-ID

Skript: LB_UpdateVaribles(-1,-1,-1, true);
Text
Item ID: \v[0001]
Actor ID: \v[0002]
Target ID: \v[0003]

If Actor ID=1
{
Skript: LB_PartyMemerRemove("2-100");

If Item-ID=5
{
Add GrpMember Slime
}
If Item-ID=6
{
Add GrpMember XY
}
{
If Item-ID=7
{
Add GrpMember YZ
}
}
Else
{
Text: You got to be the hero to use this item.
Skript:$gameParty.gainItem($dataItems[$gameVariables.value(1)],1);
}
}
This thing works out of combat. But in combat it goes the else path and returns 0 0 0 as Variables or when I summoned a monster out of combat and try to summon another with another item it returns a wrong Actor ID/Target ID /Item ID example " 8 4 4" ( I got no Item with ID 8)
Out of combat I get the Items back with the commands in the else-branch. In combat I do not.

Something is messy with my variables in fight....

I tried running
Code:
Skript: LB_UpdateVaribles(-1,-1,-1, true);
at the top and bottom of this common event. Same result.
 
Last edited:
Just would like to mention I skyped / teamviewered into BlueByt3's computer and found a minor error when TargetID was undefined by the Battle script if it matched the actor. I fixed this on his version and in the answer.

This is all solved now I believe.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm closing thread due to being addressed & solved if for any reason you would like it re-opened please report the post.
 
Status
Not open for further replies.
Top