PDA

View Full Version : How to change Equipped Weapons?



MasterSwordUltima
07-22-2014, 07:48 AM
So what would be the correct syntax to change Link's equipped weapons? I have the quest rule set so that you can equip any weapon to either A or B. I would also like to know how you can return the value of what is in item slot A and B.

item script ItemSelector{
void run(int a, int b){

int a_equip;
int b_equip;

a_equip = GetEquipmentA();
b_equip = GetEquipmentB();

if (a_equip == b){
Link->SelectAWeapon(b);
}

if (b_equip == b){
Link->SelectBWeapon(b);
}
}
}


That's just me dickin' around, trying to figure it out. Also when using SelectAWeapon() and SelectBWeapon() - what is it referencing exactly? The item number itself, or the order number of the items in the inventory?

CaRmAgE
07-22-2014, 10:49 AM
Link->Select?Weapon() accepts a direction for the subscreen cursor to move, not an item id or subscreen index. So, unfortunately, you'll have to cycle through all the items Link has until the correct ones are selected. Tested this in ZC; works rather well.

item script ItemSelector{
// int a: Item ID that button 'A' should be set to
// int b: Item ID that button 'B' should be set to
void run(int a, int b){
if (a == GetEquipmentB()){
// 'B' currently has the item needed on 'A', so move it out of the way.
Link->SelectBWeapon(DIR_RIGHT);
if(a == GetEquipmentB()){
// Link only has two items to choose from. Don't know how to handle this case.
Quit();
}
}
int a_equip = GetEquipmentA();
if(Link->Item[a]){ // Make sure Link has the item in question
while (a != GetEquipmentA()){
// Cycle through the items until the correct item for 'A' is found
Link->SelectAWeapon(DIR_RIGHT);
if(a_equip == GetEquipmentA()){
// Item not found. Subscreen not setup correctly!
break;
}
}
}
if (a == b){
// You can't set both slots to the same item.
Quit();
}
int b_equip = GetEquipmentB();
if(Link->Item[b]){ // Make sure Link has the item in question
while (b != GetEquipmentB()){
// Cycle through the items until the correct item for 'B' is found
Link->SelectBWeapon(DIR_RIGHT);
if(b_equip == GetEquipmentB()){
// Item not found. Subscreen not setup correctly!
break;
}
}
}
}
}

The only case this script can't handle properly is when Link only has two items to equip and you want to swap them. I don't know if it is possible to do that short of temporarily giving Link a third item that's on the subscreen, then taking it away when you're done. Also, this script assumes that pressing right repeatedly will move the cursor over every item in the subscreen, so if you somehow designed your subscreen to not work like that, then I apologize. This should at least be a good starting point, though.

MasterSwordUltima
07-22-2014, 11:02 AM
So there's no way to change a specific weapon in a particular slot through zscript? Because that's what I'm after.

CaRmAgE
07-22-2014, 12:17 PM
Well, in that case, I have no clue. :shrug: (Admittedly, I am also interested to know if this is possible.)

CJC
07-22-2014, 02:38 PM
Actually SUCCESSOR solved this.

First, check that Link actually owns the weapon you're looking for.
Then, run a loop that keeps selecting in a single direction (He used right) until the current weapon selected matches the one you are looking for.


If you don't check that Link owns the item, though... infinite loops might occur.

SUCCESSOR
07-22-2014, 05:27 PM
I have functions for these... hold on.

//Changes B to specified item
void SetItemB(int it)
{
//save current item to mark where we started
int storeB = GetEquipmentB();

//move to next item before checking conditions
do Link->SelectBWeapon(DIR_RIGHT);

//if Item B is the right item or the item we started at stop
while(GetEquipmentB() != it && storeB != GetEquipmentB())
}

//Change A to specified item
void SetItemA(int it)
{
//save current item to mark where we started
int storeA = GetEquipmentA();

//move to next item before checking conditions
do Link->SelectAWeapon(DIR_RIGHT);

//stop if Item A is the right item or the item we started at
while(GetEquipmentA() != it && storeA != GetEquipmentA())
}

MoscowModder brought up a possible issue of all items not all being accessible on some custom subscreens by moving through them to the right. I didn't think that was possible but then again I don't make custom subscreens.

SUCCESSOR
07-22-2014, 05:59 PM
I would also like to know how you can return the value of what is in item slot A and B.

Also when using SelectAWeapon() and SelectBWeapon() - what is it referencing exactly? The item number itself, or the order number of the items in the inventory?

Items in A and B are stored in Link->Equipment. Check std_functions to see which portions of it the GetEquipment functions grab.

The item select function just moves through the currently selectable items in the subscreen left or right. I don't know if Up or Down do anything at all. Up and down may work as they should in the subscreen. I have never tried. I have no idea how ZC organizes item that link currently has.

MasterSwordUltima
07-22-2014, 07:26 PM
I found Zoria's ItemHandling.zh and it adds some functions for SetItemA and SetItemB - which is super handy. What I'm trying to achieve is; dummy items are used to represent different versions of candles in the subscreen - when a dummy item is used it will remove all instances of the candle, then add that specific level candle, and then replace the ItemA or ItemB (depending on which slot the dummy item is in) with the candle class item.

My issue with the subscreen selection setup is that the candle itemclass itself should not be directly selectable on the subscreen.

CJC
07-22-2014, 09:54 PM
That is going to run you into some major problems, unfortunately, as the item must be able to be selected in the subscreen for the SetItemA and SetItemB functions to work.

You may have to script a custom subscreen for your actual inventory (and override the Start button with it), and then use the built-in subscreen as a dumping ground for all the effect items that you then manage with SetItemA and SetItemB. Messy.

I had planned something like this, but only generically (It was going to be Super Metroid-style item selection, pressing start changes the icon highlight by adding an item and switches the item in the subscreen with the SetItem property, all while disabling the actual subscreen).


I'm not sure where you'd start, honestly. Maybe Saffith has some wisdom on the matter.

SUCCESSOR
07-23-2014, 06:17 AM
I found Zoria's ItemHandling.zh and it adds some functions for SetItemA and SetItemB - which is super handy. What I'm trying to achieve is; dummy items are used to represent different versions of candles in the subscreen - when a dummy item is used it will remove all instances of the candle, then add that specific level candle, and then replace the ItemA or ItemB (depending on which slot the dummy item is in) with the candle class item.

My issue with the subscreen selection setup is that the candle itemclass itself should not be directly selectable on the subscreen.

I love how PureZC members just seem to love using my functions in their headers without giving me any credit or even headsup. I don't ask for credit. I don't even feel the need for people to ask me if it's okay to use my scripts that I've shared publicly for their own purposes(to date bigjoe is the only person that has done this, i think, good man). It's the decent thing to do, though. Isn't it? It is a little funny hearing people talk about headers I never heard of and finding out they contain my code.

Anyway. If you don't want any actual candle items selectable then simply don't have them in the subscreen when the scripts aren't using them. You will still need a spot for them so that they are selectable or else they can't be used. That's just how ZC works.

I did essentially the same thing as you are doing. Yours simply has a couple more steps. Basically:

Dummy item used -> trigger ffc -> ffc gives candle item that corresponds with dummy item -> switch equipped dummy item with real item -> set proper input for item to be used
-> wait a frame for the input to take effect (may need to disable other inputs) -> switch back to dummy item - > take away real item.

That should be the gist of it. Obviously, you may have more going on or approach it a little different. You may be able to pull it off with just item scripts since triggering the real item could trigger another item script to carry out the rest of the steps(since items scripts only last one frame). If you want I can send you the prototype i made for 4 item slots(if I can find it). It was kinda hacked together and involved a custom subscreen, but it all worked with few exceptions(mostly it didn't account for expendable items).

MasterSwordUltima
07-23-2014, 08:03 AM
Nah, don't worry about sending me anything - but thanks for the offer. I'd rather not bust out a whole custom subscreen just for two items. The gist was that one candle had a red flame, and the other had a blue flame - which would work in tandem for puzzles. I guess I can just set L or R to swap the candle colors around instead.

Thanks everyone for your help with this. Hopefully someday I'll be much better at ZScript's syntax.

SUCCESSOR
07-23-2014, 11:06 AM
Nah, don't worry about sending me anything - but thanks for the offer. I'd rather not bust out a whole custom subscreen just for two items. The gist was that one candle had a red flame, and the other had a blue flame - which would work in tandem for puzzles. I guess I can just set L or R to swap the candle colors around instead.

Thanks everyone for your help with this. Hopefully someday I'll be much better at ZScript's syntax.

I wasn't saying you had to make a custom subscreen. The only reason I had to script a subscreen for mine was because there is no way to setup a way to select items for extra item slots in the built in subscreen. The way you were wanting to do it would be simple. The only thing I would see that might need customizing in the subscreen is moving the candle item so that it isn't always a noticeable empty spot.

It's not really Zscript that you have to learn it's the quirks and limitations of ZC itself and then finding ways to work around them.

If you don't go the whole item swapping route The candle has to be easiest item to script from scratch.

MasterSwordUltima
07-23-2014, 12:18 PM
OMG - so I was informed (on purezc, lol) that if you add a new item with an unused itemclass (z89, z90, etc) for each item - then use the item override selection (select which specific item) - and bam. Now I have both candles as selectable items. Works for swords and boomerangs and everything upgradable.

The irony of how simple this was is really something.

SUCCESSOR
07-23-2014, 03:58 PM
OMG - so I was informed (on purezc, lol) that if you add a new item with an unused itemclass (z89, z90, etc) for each item - then use the item override selection (select which specific item) - and bam. Now I have both candles as selectable items. Works for swords and boomerangs and everything upgradable.

The irony of how simple this was is really something.

Sorry, I figurde you knew about how that worked and it wasn't what you needed.

MasterSwordUltima
07-24-2014, 05:54 AM
Nope, I always assumed it worked backwards from how it actually works. (I thought it sort of added that custom item class to whichever item class you selected - BUT IT'S NOT, derp).

CJC
07-24-2014, 05:51 PM
I love how PureZC members just seem to love using my functions in their headers without giving me any credit or even headsup. I don't ask for credit. I don't even feel the need for people to ask me if it's okay to use my scripts that I've shared publicly for their own purposes(to date bigjoe is the only person that has done this, i think, good man). It's the decent thing to do, though. Isn't it? It is a little funny hearing people talk about headers I never heard of and finding out they contain my code.
That's not fair, I gave you credit for the functions in my quest and in this very thread! :P

Anyways, I also did not know that custom item classes could be used in this fashion, hence why I assumed a custom subscreen was needed. This is...surprisingly useful.

SUCCESSOR
07-24-2014, 11:16 PM
That's not fair, I gave you credit for the functions in my quest and in this very thread! :P

I meant asking permission to use a script that I shared publicly. All the Scripts I was involved with with you already implied permission.