PDA

View Full Version : [Essentials tutorial] Register multiple items


FL
July 28th, 2013, 06:13 AM
Essentials has the feature of register a item with a key (F5). This tutorial explain how to add more keys simultaneous. In this example I gonna add F4 and F3, but I teach how to add others.

At PokemonControls script section

As F4 and F3 aren't mapped in input, we need to map. Before line

when Input::F5

add

when Input::F3
return [0x72] # F3
when Input::F4
return [0x73] # F4

The order doens't matter if is in the "case" statement. The 0x72 and 0x73 are the F3/F4 codes in keyboard (there's a list here (http://irrlicht.sourceforge.net/docu/_keycodes_8h_source.html)). Before line:

F5 = 25

add

F3 = 31
F4 = 32

The order and the code doens't matter if they are in the module Input. Just make sure that the numbers (31 and 32) aren't the same as other constants in this module. If the F3 and F4 keys are mapped, we don't have to do the two above code changes. Before line

LeftMouseKey = 1

add

ITEMKEYS = [Input::F5,Input::F4,Input::F3]
ITEMKEYSNAMES = [_INTL("F5"),_INTL("F4"),_INTL("F3")]

These two arrays store all the key that you can register items. If you wish to add more keys, just include in these two arrays, map in input (if the keys aren't mapped) and add an icon. Note about keys that do other things, so if you add the F8 (button that take screenshots) every time that you hits F8 you take a screenshot AND do the effects of a registered key.

The picture that appears at right of the item name at bag is named bagRegX.png in folder Graphics\Pictures, where X is the array index starting in 0, so in this example we need the bagReg0.png (F5), bagReg1.png (F4) and bagReg2.png (F3).

At Scene_Map script section

Change:

if Input.trigger?(Input::F5)
unless pbMapInterpreterRunning?
$PokemonTemp.keyItemCalling = true if $PokemonTemp
end
end

to

unless pbMapInterpreterRunning?
for keyNumber in 0...Input::ITEMKEYS.size
if Input.trigger?(Input::ITEMKEYS[keyNumber]) && $PokemonTemp
$PokemonTemp.keyItemCalling = keyNumber
end
end
end

Change

$PokemonTemp.keyItemCalling=false
$game_player.straighten
Kernel.pbUseKeyItem

to

$game_player.straighten
Kernel.pbUseKeyItem($PokemonTemp.keyItemCalling)
$PokemonTemp.keyItemCalling=nil

At PokemonField script section

Change

def pbUseKeyItem
if $PokemonBag.registeredItem==0
Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
else
Kernel.pbUseKeyItemInField($PokemonBag.registeredItem)
end
end

to

def pbUseKeyItem(itemKeyNumber)
if $PokemonBag.registeredItem[itemKeyNumber]==nil
Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
else
Kernel.pbUseKeyItemInField($PokemonBag.registeredItem[itemKeyNumber])
end
end

At PokemonMap script section

Change

@keyItemCalling=false

to

@keyItemCalling=nil

At PokemonBag script section

Change

if @bag.registeredItem==@bag.pockets[self.pocket][index][0]
pbDrawImagePositions(self.contents,[
["Graphics/Pictures/bagReg",rect.x+rect.width-58,ypos+4,0,0,-1,-1]
])
end

to

i = @bag.registeredItem.index(@bag.pockets[self.pocket][index][0])
if i
pbDrawImagePositions(self.contents,[
[sprintf("Graphics/Pictures/bagReg#{i}"),rect.x+rect.width-58,ypos+4,0,0,-1,-1]
])
end

Change

attr_reader :registeredItem

to

def registeredItem
# The below line is to this change don't mess with existing saves
@registeredItem = [@registeredItem] if !@registeredItem.is_a?(Array)
while @registeredItem.size<Input::ITEMKEYS.size
@registeredItem.push(nil)
end
return @registeredItem
end

Change

@registeredItem=0

to

@registeredItem=[]

Change

def pbRegisterKeyItem(item)
if item!=@registeredItem
@registeredItem=item
else
@registeredItem=0
end
end

to

def pbRegisterKeyItem(item,itemKeyNumber)
index = registeredItem.index(item)
registeredItem[index]=nil if index # remove duplicates
registeredItem[itemKeyNumber]=item if !index || index!=itemKeyNumber
end

Change

@registeredItem=0 if @registeredItem==item && pbQuantity(item)<=0

to

index = registeredItem.index(item)
registeredItem[index]=nil if index && pbQuantity(item)<=0

Change

if @bag.registeredItem==item
commands[cmdRegister=commands.length]=_INTL("Deselect")
elsif pbIsKeyItem?(item) && ItemHandlers.hasKeyItemHandler(item)
commands[cmdRegister=commands.length]=_INTL("Register")
end


to

commands[cmdRegister=commands.length]=_INTL("Register") if pbIsKeyItem?(item) && ItemHandlers.hasKeyItemHandler(item)

Change

@bag.pbRegisterKeyItem(item)

to

registerCommands = Input::ITEMKEYSNAMES + [_INTL("Back")]
registerCommand = @scene.pbShowCommands(
_INTL("Choose a key.",itemname),registerCommands)
@bag.pbRegisterKeyItem(item,registerCommand) if registerCommand!=-1 && registerCommand!=registerCommands.size

Maruno
July 28th, 2013, 07:34 AM
Personally I think it'd be easier to make F5 open a menu listing all the registered items, and then choose one of them to use.

venom12
July 28th, 2013, 08:02 AM
Yah i also think about the open list something like in Pokemon BW. Btw good tutorial :)

Black Eternity
July 28th, 2013, 07:57 PM
Personally I would rather use FL's method, in the sense that if I just wanted to use Super Rod over and over, it's just a press of a button. With the menu idea, I would have to keep opening the menu and select what I want, with his method you are completely eliminating more key presses.

thor348
July 28th, 2013, 10:13 PM
At Scene_Map script section

Change

def pbUseKeyItem
if $PokemonBag.registeredItem==0
Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
else
Kernel.pbUseKeyItemInField($PokemonBag.registeredItem)
end
end

to

def pbUseKeyItem(itemKeyNumber)
if $PokemonBag.registeredItem[itemKeyNumber]==nil
Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
else
Kernel.pbUseKeyItemInField($PokemonBag.registeredItem[itemKeyNumber])
end
end



This is found in PokemonField, not Scene_Map.

But excellent job on this, I like having multiple buttons to register items.

FL
August 3rd, 2013, 03:01 PM
Personally I think it'd be easier to make F5 open a menu listing all the registered items, and then choose one of them to use.I didn't think this list before. Your way is less practic and less confusing. I prefer my way, but maybe I implements yours in the future.

This is found in PokemonField, not Scene_Map.

But excellent job on this, I like having multiple buttons to register items.Thanks! I make a mistake while copying/pasting, now it's fixed.

lauerolus
August 4th, 2013, 11:02 AM
Honestly I prefer separate buttons. I have a whole keyboard and 1-10 just waiting to be used.

I'm going to go crazy with this, thanks for posting it!

Rayd12smitty
August 5th, 2013, 04:52 PM
So I tried this with using Number keys 1,2, and 3 instead, and my game keeps crashing. (script taking too long) whenever I open the bag, and the game just freezes when I try pressing 1, 2, or 3. I followed your directions exactly, other than switching 1,2 and 3 wherever it said f5, f3, and f4. I looked up the key codes and they are (0x31) (0x32) and (0x33). Any idea what might be going wrong? Here is the controls script where it is changed.


module Input
DOWN = 2
LEFT = 4
RIGHT = 6
UP = 8
A = 11
B = 12
C = 13
X = 14
Y = 15
Z = 16
L = 17
R = 18
SHIFT = 21
CTRL = 22
ALT = 23
One = 31
Two = 32
Three = 33
F5 = 25
F6 = 26
F7 = 27
F8 = 28
F9 = 29
ITEMKEYS = [Input::One,Input::Two,Input::Three]
ITEMKEYSNAMES = [_INTL("One"),_INTL("Two"),_INTL("Three")]
LeftMouseKey = 1


and


when Input::One
return [0x31] # One
when Input::Two
return [0x32] # Two
when Input::Three
return [0x33] # Three
when Input::F5
return [0x74] # F5


I am using Essentials Version 11 still so that may be part of/all of the problem. I don't plan on switching to Version 12, at least not yet, so I would be really happy if someone could help me.

FL
August 8th, 2013, 03:22 PM
A trivia: I spend more time detailing the steps of where copy/paste the code than making the feature itself.
So I tried this with using Number keys 1,2, and 3 instead, and my game keeps crashing. (script taking too long) whenever I open the bag, and the game just freezes when I try pressing 1, 2, or 3. I followed your directions exactly, other than switching 1,2 and 3 wherever it said f5, f3, and f4. I looked up the key codes and they are (0x31) (0x32) and (0x33). Any idea what might be going wrong? Here is the controls script where it is changed.


module Input
DOWN = 2
LEFT = 4
RIGHT = 6
UP = 8
A = 11
B = 12
C = 13
X = 14
Y = 15
Z = 16
L = 17
R = 18
SHIFT = 21
CTRL = 22
ALT = 23
One = 31
Two = 32
Three = 33
F5 = 25
F6 = 26
F7 = 27
F8 = 28
F9 = 29
ITEMKEYS = [Input::One,Input::Two,Input::Three]
ITEMKEYSNAMES = [_INTL("One"),_INTL("Two"),_INTL("Three")]
LeftMouseKey = 1


and


when Input::One
return [0x31] # One
when Input::Two
return [0x32] # Two
when Input::Three
return [0x33] # Three
when Input::F5
return [0x74] # F5


I am using Essentials Version 11 still so that may be part of/all of the problem. I don't plan on switching to Version 12, at least not yet, so I would be really happy if someone could help me.I believe that this have nothing about the Essentials Version, you probably miss something. I tests in a old Essentials version with these numbers and them are working! Try to change to F5, F4 and F3 and test before changing to numbers.

Rayd12smitty
December 1st, 2013, 07:14 PM
Hello again... So I am using essentials Version 12.2 and have followed your steps EXACTLY, double checking 2 or 3 times. Everything we have matches perfectly. Whenever I try pressing F3-F5, the game crashes saying the script is taking too long. If I even have a key item in the bag, registered or not, and try to open the bag, the game crashes. Any ideas?

venom12
December 2nd, 2013, 02:06 AM
Hello again... So I am using essentials Version 12.2 and have followed your steps EXACTLY, double checking 2 or 3 times. Everything we have matches perfectly. Whenever I try pressing F3-F5, the game crashes saying the script is taking too long. If I even have a key item in the bag, registered or not, and try to open the bag, the game crashes. Any ideas?

I used this in Essentials 12.2 and followed tutorial step by step and it is working fine for me. Try again on clean script.

Rayd12smitty
December 2nd, 2013, 06:01 PM
I used this in Essentials 12.2 and followed tutorial step by step and it is working fine for me. Try again on clean script.

So weird:/ I just downloaded Essentials 13 so I'm going to test it on that before doing any other changes, see if it works, and then add my other script changes one by one to see which one is messing it up, if any.