• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Error] When I Edit The Trainers, It makes Giving Items Crash The Game

4
Posts
4
Years
  • Age 35
  • Seen Apr 25, 2021
I trying to add a teacher trainer but when I add a trainer with teacher class, but when i do get a bug that makes it so when is given the player a item crash the game.

I would show screenshots but i don't have need amount of posts...

When it's a multiple items...

---------------------------
Pokemon Essentials
---------------------------
Script 'Interpreter' line 276: RuntimeError occurred.

Script error within event 14 (coords 14,14), map 2 ():

Exception: NoMethodError

Message: PField_Field:1407:in `pbReceiveItem'undefined method `getNamePlural' for PBItems:Class

***Full script:

Kernel.pbReceiveItem(:POKEBALL,5)


Interpreter:243:in `pbExecuteScript'

(eval):1:in `pbExecuteScript'

Interpreter:1606:in `eval'

Interpreter:243:in `pbExecuteScript'

Interpreter:1606:in `command_355'

Interpreter:494:in `execute_command'

Interpreter:193:in `update'

Interpreter:106:in `loop'

Interpreter:198:in `update'

Scene_Map:163:in `update'


---------------------------
OK
---------------------------


Single items

---------------------------
Pokemon Essentials
---------------------------
Script 'Interpreter' line 276: RuntimeError occurred.

Script error within event 13 (coords 13,16), map 2 ():

Exception: NoMethodError

Message: PItem_Bag:150:in `pbStoreItem'undefined method `length' for nil:NilClass

***Full script:

Kernel.pbItemBall(:POTION)


Interpreter:243:in `pbExecuteScript'

PField_Field:1365:in `pbItemBall'

(eval):1:in `pbExecuteScript'

Interpreter:1606:in `eval'

Interpreter:243:in `pbExecuteScript'

Interpreter:1606:in `command_355'

Interpreter:494:in `execute_command'

Interpreter:193:in `update'

Interpreter:106:in `loop'

Interpreter:198:in `update'


---------------------------
OK
---------------------------

Also the Teacher trainer type is also a bit messy. when i edit the type is there but can't edit it and when I add the Teacher it says it is not there in the trainer type list...
 
1,680
Posts
8
Years
  • Age 24
  • Seen today
<snipped>
Hey Kashuti! welcome to Pokecommunity!

I moved your post here, the the Pokemon Essentials section, that's where you can get help!

Your line numbers don't really match up properly. Did you change the number of pockets or perhaps one of your items has an invalid pocket number?
That other error is strange. PBItems.getNamePlural should be defined in the compiler, so I'm not sure why that isn't there.

What version of Essentials are you on? I'm kind of lost now.
 
Last edited:
4
Posts
4
Years
  • Age 35
  • Seen Apr 25, 2021
Thanks for moving the tread, I'm On version 17.2

remember editing pockets on 1 attempt i did but I don't think have?

Here is My PScreen_Bag...

class Window_PokemonBag < Window_DrawableCommand
attr_reader :pocket
attr_accessor :sorting

def initialize(bag,filterlist,pocket,x,y,width,height)
@bag = bag
@filterlist = filterlist
@pocket = pocket
@sorting = false
@adapter = PokemonMartAdapter.new
super(x,y,width,height)
@selarrow = AnimatedBitmap.new("Graphics/Pictures/Bag/cursor")
@swaparrow = AnimatedBitmap.new("Graphics/Pictures/Bag/cursor_swap")
self.windowskin = nil
end

def dispose
@swaparrow.dispose
super
end

def pocket=(value)
@pocket = value
@item_max = (@filterlist) ? @filterlist[@pocket].length+1 : @bag.pockets[@pocket].length+1
self.index = @bag.getChoice(@pocket)
end

def page_row_max; return PokemonBag_Scene::ITEMSVISIBLE; end
def page_item_max; return PokemonBag_Scene::ITEMSVISIBLE; end

def item
return 0 if @filterlist && !@filterlist[@pocket][self.index]
thispocket = @bag.pockets[@pocket]
item = (@filterlist) ? thispocket[@filterlist[@pocket][self.index]] : thispocket[self.index]
return (item) ? item[0] : 0
end

def itemCount
return (@filterlist) ? @filterlist[@pocket].length+1 : @bag.pockets[@pocket].length+1
end

def itemRect(item)
if item<0 || item>=@item_max || item<self.top_item-1 ||
item>self.top_item+self.page_item_max
return Rect.new(0,0,0,0)
else
cursor_width = (self.width-self.borderX-(@column_max-1)*@column_spacing) / @column_max
x = item % @column_max * (cursor_width + @column_spacing)
y = item / @column_max * @row_height - @virtualOy
return Rect.new(x, y, cursor_width, @row_height)
end
end

def drawCursor(index,rect)
if self.index==index
bmp = (@sorting) ? @swaparrow.bitmap : @selarrow.bitmap
pbCopyBitmap(self.contents,bmp,rect.x,rect.y+2)
end
end

def drawItem(index,count,rect)
textpos = []
rect = Rect.new(rect.x+16,rect.y+16,rect.width-16,rect.height)
ypos = rect.y+4
thispocket = @bag.pockets[@pocket]
if index==self.itemCount-1
textpos.push([_INTL("CLOSE BAG"),rect.x,ypos,false,self.baseColor,self.shadowColor])
else
item = (@filterlist) ? thispocket[@filterlist[@pocket][index]][0] : thispocket[index][0]
baseColor = self.baseColor
shadowColor = self.shadowColor
if @sorting && index==self.index
baseColor = Color.new(224,0,0)
shadowColor = Color.new(248,144,144)
end
textpos.push(
[@adapter.getDisplayName(item),rect.x,ypos,false,baseColor,shadowColor]
)
if !pbIsImportantItem?(item) # Not a Key item or HM (or infinite TM)
qty = (@filterlist) ? thispocket[@filterlist[@pocket][index]][1] : thispocket[index][1]
qtytext = _ISPRINTF("x{1: 3d}",qty)
xQty = rect.x+rect.width-self.contents.text_size(qtytext).width-16
textpos.push([qtytext,xQty,ypos,false,baseColor,shadowColor])
end
if pbIsImportantItem?(item)
if @bag.pbIsRegistered?(item)
pbDrawImagePositions(self.contents,[
["Graphics/Pictures/Bag/icon_register",rect.x+rect.width-72,ypos+4,0,0,-1,24]
])
elsif pbCanRegisterItem?(item)
pbDrawImagePositions(self.contents,[
["Graphics/Pictures/Bag/icon_register",rect.x+rect.width-72,ypos+4,0,24,-1,24]
])
end
end
end
pbDrawTextPositions(self.contents,textpos)
end

def refresh
@item_max = itemCount()
self.update_cursor_rect
dwidth = self.width-self.borderX
dheight = self.height-self.borderY
self.contents = pbDoEnsureBitmap(self.contents,dwidth,dheight)
self.contents.clear
for i in 0...@item_max
next if i<self.top_item-1 || i>self.top_item+self.page_item_max
drawItem(i,@item_max,itemRect(i))
end
drawCursor(self.index,itemRect(self.index))
end

def update
super
@uparrow.visible = false
@downarrow.visible = false
end
end



#===============================================================================
# Bag visuals
#===============================================================================
class PokemonBag_Scene
ITEMLISTBASECOLOR = Color.new(88,88,80)
ITEMLISTSHADOWCOLOR = Color.new(168,184,184)
ITEMTEXTBASECOLOR = Color.new(248,248,248)
ITEMTEXTSHADOWCOLOR = Color.new(0,0,0)
POCKETNAMEBASECOLOR = Color.new(88,88,80)
POCKETNAMESHADOWCOLOR = Color.new(168,184,184)
ITEMSVISIBLE = 7

def pbUpdate
pbUpdateSpriteHash(@sprites)
end

def pbStartScene(bag,choosing=false,filterproc=nil,resetpocket=true)
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z = 99999
@bag = bag
@choosing = choosing
@filterproc = filterproc
pbRefreshFilter
lastpocket = @bag.lastpocket
numfilledpockets = @bag.pockets.length-1
if @choosing
numfilledpockets = 0
if @filterlist!=nil
for i in [email protected]
numfilledpockets += 1 if @filterlist.length>0
end
else
for i in [email protected]
numfilledpockets += 1 if @bag.pockets.length>0
end
end
lastpocket = (resetpocket) ? 1 : @bag.lastpocket
if (@filterlist && @filterlist[lastpocket].length==0) ||
(!@filterlist && @bag.pockets[lastpocket].length==0)
for i in [email protected]
if @filterlist && @filterlist.length>0
lastpocket = i; break
elsif !@filterlist && @bag.pockets.length>0
lastpocket = i; break
end
end
end
end
@bag.lastpocket = lastpocket
@sliderbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_slider"))
@pocketbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_pocket"))
@sprites = {}
@sprites["background"] = IconSprite.new(0,0,@viewport)
@sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
pbSetSystemFont(@sprites["overlay"].bitmap)
@sprites["bagsprite"] = IconSprite.new(30,20,@viewport)
@sprites["pocketicon"] = BitmapSprite.new(186,32,@viewport)
@sprites["pocketicon"].x = 0
@sprites["pocketicon"].y = 224
@sprites["leftarrow"] = AnimatedSprite.new("Graphics/Pictures/leftarrow",8,40,28,2,@viewport)
@sprites["leftarrow"].x = -4
@sprites["leftarrow"].y = 76
@sprites["leftarrow"].visible = (!@choosing || numfilledpockets>1)
@sprites["leftarrow"].play
@sprites["rightarrow"] = AnimatedSprite.new("Graphics/Pictures/rightarrow",8,40,28,2,@viewport)
@sprites["rightarrow"].x = 150
@sprites["rightarrow"].y = 76
@sprites["rightarrow"].visible = (!@choosing || numfilledpockets>1)
@sprites["rightarrow"].play
@sprites["itemlist"] = Window_PokemonBag.new(@bag,@filterlist,lastpocket,168,-8,314,40+32+ITEMSVISIBLE*32)
@sprites["itemlist"].viewport = @viewport
@sprites["itemlist"].pocket = lastpocket
@sprites["itemlist"].index = @bag.getChoice(lastpocket)
@sprites["itemlist"].baseColor = ITEMLISTBASECOLOR
@sprites["itemlist"].shadowColor = ITEMLISTSHADOWCOLOR
@sprites["itemicon"] = ItemIconSprite.new(48,Graphics.height-48,-1,@viewport)
@sprites["itemtext"] = Window_UnformattedTextPokemon.new("")
@sprites["itemtext"].x = 72
@sprites["itemtext"].y = 270
@sprites["itemtext"].width = Graphics.width-72-24
@sprites["itemtext"].height = 128
@sprites["itemtext"].baseColor = ITEMTEXTBASECOLOR
@sprites["itemtext"].shadowColor = ITEMTEXTSHADOWCOLOR
@sprites["itemtext"].visible = true
@sprites["itemtext"].viewport = @viewport
@sprites["itemtext"].windowskin = nil
@sprites["helpwindow"] = Window_UnformattedTextPokemon.new("")
@sprites["helpwindow"].visible = false
@sprites["helpwindow"].viewport = @viewport
@sprites["msgwindow"] = Window_AdvancedTextPokemon.new("")
@sprites["msgwindow"].visible = false
@sprites["msgwindow"].viewport = @viewport
pbBottomLeftLines(@sprites["helpwindow"],1)
pbDeactivateWindows(@sprites)
pbRefresh
pbFadeInAndShow(@sprites)
end

def pbEndScene
pbFadeOutAndHide(@sprites)
pbDisposeSpriteHash(@sprites)
@sliderbitmap.dispose
@pocketbitmap.dispose
@viewport.dispose
end

def pbDisplay(msg,brief=false)
UIHelper.pbDisplay(@sprites["msgwindow"],msg,brief) { pbUpdate }
end

def pbConfirm(msg)
UIHelper.pbConfirm(@sprites["msgwindow"],msg) { pbUpdate }
end

def pbChooseNumber(helptext,maximum,initnum=1)
return UIHelper.pbChooseNumber(@sprites["helpwindow"],helptext,maximum,initnum) { pbUpdate }
end

def pbShowCommands(helptext,commands,initcmd=0)
return UIHelper.pbShowCommands(@sprites["helpwindow"],helptext,commands,initcmd) { pbUpdate }
end

def pbRefresh
# Set the background image
@sprites["background"].setBitmap(sprintf("Graphics/Pictures/Bag/bg_#{@bag.lastpocket}"))
# Set the bag sprite
fbagexists = pbResolveBitmap(sprintf("Graphics/Pictures/Bag/bag_#{@bag.lastpocket}_f"))
if $Trainer.isFemale? && fbagexists
@sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.lastpocket}_f")
else
@sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.lastpocket}")
end
# Draw the pocket icons
@sprites["pocketicon"].bitmap.clear
if @choosing && @filterlist
for i in [email protected]
if @filterlist.length==0
@sprites["pocketicon"].bitmap.blt(6+(i-1)*22,6,
@pocketbitmap.bitmap,Rect.new((i-1)*20,28,20,20))
end
end
end
@sprites["pocketicon"].bitmap.blt(2+(@sprites["itemlist"].pocket-1)*22,2,
@pocketbitmap.bitmap,Rect.new((@sprites["itemlist"].pocket-1)*28,0,28,28))
# Refresh the item window
@sprites["itemlist"].refresh
# Refresh more things
pbRefreshIndexChanged
end

def pbRefreshIndexChanged
itemlist = @sprites["itemlist"]
overlay = @sprites["overlay"].bitmap
overlay.clear
# Draw the pocket name
pbDrawTextPositions(overlay,[
[PokemonBag.pocketNames[@bag.lastpocket],94,180,2,POCKETNAMEBASECOLOR,POCKETNAMESHADOWCOLOR]
])
# Draw slider arrows
showslider = false
if itemlist.top_row>0
overlay.blt(470,16,@sliderbitmap.bitmap,Rect.new(0,0,36,38))
showslider = true
end
if itemlist.top_item+itemlist.page_item_max<itemlist.itemCount
overlay.blt(470,228,@sliderbitmap.bitmap,Rect.new(0,38,36,38))
showslider = true
end
# Draw slider box
if showslider
sliderheight = 174
boxheight = (sliderheight*itemlist.page_row_max/itemlist.row_max).floor
boxheight += [(sliderheight-boxheight)/2,sliderheight/6].min
boxheight = [boxheight.floor,38].max
y = 54
y += ((sliderheight-boxheight)*itemlist.top_row/(itemlist.row_max-itemlist.page_row_max)).floor
overlay.blt(470,y,@sliderbitmap.bitmap,Rect.new(36,0,36,4))
i = 0; while i*16<boxheight-4-18
height = [boxheight-4-18-i*16,16].min
overlay.blt(470,y+4+i*16,@sliderbitmap.bitmap,Rect.new(36,4,36,height))
i += 1
end
overlay.blt(470,y+boxheight-18,@sliderbitmap.bitmap,Rect.new(36,20,36,18))
end
# Set the selected item's icon
@sprites["itemicon"].item = itemlist.item
# Set the selected item's description
@sprites["itemtext"].text = (itemlist.item==0) ? _INTL("Close bag.") :
pbGetMessage(MessageTypes::ItemDescriptions,itemlist.item)
end

def pbRefreshFilter
@filterlist = nil
return if !@choosing
if @filterproc!=nil
@filterlist = []
for i in [email protected]
@filterlist = []
for j in [email protected].length
@filterlist.push(j) if @filterproc.call(@bag.pockets[j][0])
end
end
else
end
end

# Called when the item screen wants an item to be chosen from the screen
def pbChooseItem
@sprites["helpwindow"].visible = false
itemwindow = @sprites["itemlist"]
thispocket = @bag.pockets[itemwindow.pocket]
swapinitialpos = -1
pbActivateWindow(@sprites,"itemlist"){
loop do
oldindex = itemwindow.index
Graphics.update
Input.update
pbUpdate
if itemwindow.sorting && itemwindow.index>=thispocket.length
itemwindow.index = (oldindex==thispocket.length-1) ? 0 : thispocket.length-1
end
if itemwindow.index!=oldindex
# Move the item being switched
if itemwindow.sorting
thispocket.insert(itemwindow.index,thispocket.delete_at(oldindex))
end
# Update selected item for current pocket
@bag.setChoice(itemwindow.pocket,itemwindow.index)
pbRefresh
end
if itemwindow.sorting
if Input.trigger?(Input::A) ||
Input.trigger?(Input::C)
itemwindow.sorting = false
pbPlayDecisionSE
pbRefresh
elsif Input.trigger?(Input::B)
curindex = itemwindow.index
thispocket.insert(swapinitialpos,thispocket.delete_at(itemwindow.index))
itemwindow.index = swapinitialpos
itemwindow.sorting = false
pbPlayCancelSE
pbRefresh
end
else
# Change pockets
if Input.trigger?(Input::LEFT)
newpocket = itemwindow.pocket
loop do
newpocket = (newpocket==1) ? PokemonBag.numPockets : newpocket-1
break if !@choosing || newpocket==itemwindow.pocket
if @filterlist; break if @filterlist[newpocket].length>0
else; break if @bag.pockets[newpocket].length>0
end
end
if itemwindow.pocket!=newpocket
itemwindow.pocket = newpocket
@bag.lastpocket = itemwindow.pocket
thispocket = @bag.pockets[itemwindow.pocket]
pbPlayCursorSE
pbRefresh
end
elsif Input.trigger?(Input::RIGHT)
newpocket = itemwindow.pocket
loop do
newpocket = (newpocket==PokemonBag.numPockets) ? 1 : newpocket+1
break if !@choosing || newpocket==itemwindow.pocket
if @filterlist; break if @filterlist[newpocket].length>0
else; break if @bag.pockets[newpocket].length>0
end
end
if itemwindow.pocket!=newpocket
itemwindow.pocket = newpocket
@bag.lastpocket = itemwindow.pocket
thispocket = @bag.pockets[itemwindow.pocket]
pbPlayCursorSE
pbRefresh
end
# elsif Input.trigger?(Input::F5) # Register/unregister selected item
# if !@choosing && itemwindow.index<thispocket.length
# if @bag.pbIsRegistered?(itemwindow.item)
# @bag.pbUnregisterItem(itemwindow.item)
# elsif pbCanRegisterItem?(itemwindow.item)
# @bag.pbRegisterItem(itemwindow.item)
# end
# pbPlayDecisionSE
# pbRefresh
# end
elsif Input.trigger?(Input::A) # Start switching the selected item
if !@choosing
if thispocket.length>1 && itemwindow.index<thispocket.length &&
!POCKETAUTOSORT[itemwindow.pocket]
itemwindow.sorting = true
swapinitialpos = itemwindow.index
pbPlayDecisionSE
pbRefresh
end
end
elsif Input.trigger?(Input::B) # Cancel the item screen
pbPlayCancelSE
return 0
elsif Input.trigger?(Input::C) # Choose selected item
pbPlayDecisionSE
return itemwindow.item
end
end
end
}
end
end



#===============================================================================
# Bag mechanics
#===============================================================================
class PokemonBagScreen
def initialize(scene,bag)
@bag = bag
@scene = scene
end

def pbStartScreen
@scene.pbStartScene(@bag)
item = 0
loop do
item = @scene.pbChooseItem
break if item==0
cmdRead = -1
cmdUse = -1
cmdRegister = -1
cmdGive = -1
cmdToss = -1
cmdDebug = -1
commands = []
# Generate command list
commands[cmdRead = commands.length] = _INTL("Read") if pbIsMail?(item)
if ItemHandlers.hasOutHandler(item) || (pbIsMachine?(item) && $Trainer.party.length>0)
if ItemHandlers.hasUseText(item)
commands[cmdUse = commands.length] = ItemHandlers.getUseText(item)
else
commands[cmdUse = commands.length] = _INTL("Use")
end
end
commands[cmdGive = commands.length] = _INTL("Give") if $Trainer.pokemonParty.length>0 && pbCanHoldItem?(item)
commands[cmdToss = commands.length] = _INTL("Toss") if !pbIsImportantItem?(item) || $DEBUG
if @bag.pbIsRegistered?(item)
commands[cmdRegister = commands.length] = _INTL("Deselect")
elsif pbCanRegisterItem?(item)
commands[cmdRegister = commands.length] = _INTL("Register")
end
commands[cmdDebug = commands.length] = _INTL("Debug") if $DEBUG
commands[commands.length] = _INTL("Cancel")
# Show commands generated above
itemname = PBItems.getName(item) # Get item name
command = @scene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
if cmdRead>=0 && command==cmdRead # Read mail
pbFadeOutIn(99999){
pbDisplayMail(PokemonMail.new(item,"",""))
}
elsif cmdUse>=0 && command==cmdUse # Use item
ret = pbUseItem(@bag,item,@scene)
# ret: 0=Item wasn't used; 1=Item used; 2=Close Bag to use in field
break if ret==2 # End screen
@scene.pbRefresh
next
elsif cmdGive>=0 && command==cmdGive # Give item to Pokémon
if $Trainer.pokemonCount==0
@scene.pbDisplay(_INTL("There is no Pokémon."))
elsif pbIsImportantItem?(item)
@scene.pbDisplay(_INTL("The {1} can't be held.",itemname))
else
pbFadeOutIn(99999){
sscene = PokemonParty_Scene.new
sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
sscreen.pbPokemonGiveScreen(item)
@scene.pbRefresh
}
end
elsif cmdToss>=0 && command==cmdToss # Toss item
qty = @bag.pbQuantity(item)
if qty>1
helptext = _INTL("Toss out how many {1}?",PBItems.getNamePlural(item))
qty = @scene.pbChooseNumber(helptext,qty)
end
if qty>0
itemname = PBItems.getNamePlural(item) if qty>1
if pbConfirm(_INTL("Is it OK to throw away {1} {2}?",qty,itemname))
pbDisplay(_INTL("Threw away {1} {2}.",qty,itemname))
qty.times { @bag.pbDeleteItem(item) }
@scene.pbRefresh
end
end
elsif cmdRegister>=0 && command==cmdRegister # Register item
if @bag.pbIsRegistered?(item)
@bag.pbUnregisterItem(item)
else
@bag.pbRegisterItem(item)
end
@scene.pbRefresh
elsif cmdDebug>=0 && command==cmdDebug # Debug
command = 0
loop do
command = @scene.pbShowCommands(_INTL("Do what with {1}?",itemname),[
_INTL("Change quantity"),
_INTL("Make Mystery Gift"),
_INTL("Cancel")
],command)
case command
### Cancel ###
when -1, 2
break
### Change quantity ###
when 0
qty = @bag.pbQuantity(item)
itemplural = PBItems.getNamePlural(item)
params = ChooseNumberParams.new
params.setRange(0,BAGMAXPERSLOT)
params.setDefaultValue(qty)
newqty = Kernel.pbMessageChooseNumber(
_INTL("Choose new quantity of {1}.",itemplural),params) { @scene.pbUpdate }
if newqty>qty
@bag.pbStoreItem(item,newqty-qty)
elsif newqty<qty
@bag.pbDeleteItem(item,qty-newqty)
end
@scene.pbRefresh
break if newqty==0
### Make Mystery Gift ###
when 1
pbCreateMysteryGift(1,item)
end
end
end
end
@scene.pbEndScene
return item
end

def pbDisplay(text)
@scene.pbDisplay(text)
end

def pbConfirm(text)
return @scene.pbConfirm(text)
end

# UI logic for the item screen for choosing an item.
def pbChooseItemScreen(proc=nil)
oldlastpocket = @bag.lastpocket
oldchoices = @bag.getAllChoices
@scene.pbStartScene(@bag,true,proc)
item = @scene.pbChooseItem
@scene.pbEndScene
@bag.lastpocket = oldlastpocket
@bag.setAllChoices(oldchoices)
return item
end

# UI logic for withdrawing an item in the item storage screen.
def pbWithdrawItemScreen
if !$PokemonGlobal.pcItemStorage
$PokemonGlobal.pcItemStorage = PCItemStorage.new
end
storage = $PokemonGlobal.pcItemStorage
@scene.pbStartScene(storage)
loop do
item = @scene.pbChooseItem
break if item==0
commands = [_INTL("Withdraw"),_INTL("Give"),_INTL("Cancel")]
itemname = PBItems.getName(item)
command = @scene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
if command==0 # Withdraw
qty = storage.pbQuantity(item)
if qty>1 && !pbIsImportantItem?(item)
qty = @scene.pbChooseNumber(_INTL("How many do you want to withdraw?"),qty)
end
if qty>0
if [email protected]?(item,qty)
pbDisplay(_INTL("There's no more room in the Bag."))
else
dispqty = (pbIsImportantItem?(item)) ? 1 : qty
itemname = PBItems.getNamePlural(item) if dispqty>1
pbDisplay(_INTL("Withdrew {1} {2}.",dispqty,itemname))
if !storage.pbDeleteItem(item,qty)
raise "Can't delete items from storage"
end
if [email protected](item,qty)
raise "Can't withdraw items from storage"
end
end
end
elsif command==1 # Give
if $Trainer.pokemonCount==0
@scene.pbDisplay(_INTL("There is no Pokémon."))
return 0
elsif pbIsImportantItem?(item)
@scene.pbDisplay(_INTL("The {1} can't be held.",itemname))
else
pbFadeOutIn(99999){
sscene = PokemonParty_Scene.new
sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
if sscreen.pbPokemonGiveScreen(item)
# If the item was held, delete the item from storage
if !storage.pbDeleteItem(item,1)
raise "Can't delete item from storage"
end
end
@scene.pbRefresh
}
end
end
end
@scene.pbEndScene
end

# UI logic for depositing an item in the item storage screen.
def pbDepositItemScreen
@scene.pbStartScene(@bag)
if !$PokemonGlobal.pcItemStorage
$PokemonGlobal.pcItemStorage = PCItemStorage.new
end
storage = $PokemonGlobal.pcItemStorage
item = 0
loop do
item = @scene.pbChooseItem
break if item==0
qty = @bag.pbQuantity(item)
if qty>1 && !pbIsImportantItem?(item)
qty = @scene.pbChooseNumber(_INTL("How many do you want to deposit?"),qty)
end
if qty>0
if !storage.pbCanStore?(item,qty)
pbDisplay(_INTL("There's no room to store items."))
else
dispqty = (pbIsImportantItem?(item)) ? 1 : qty
itemname = (dispqty>1) ? PBItems.getNamePlural(item) : PBItems.getName(item)
pbDisplay(_INTL("Deposited {1} {2}.",dispqty,itemname))
if [email protected](item,qty)
raise "Can't delete items from bag"
end
if !storage.pbStoreItem(item,qty)
raise "Can't deposit items to storage"
end
end
end
end
@scene.pbEndScene
end

# UI logic for tossing an item in the item storage screen.
def pbTossItemScreen
if !$PokemonGlobal.pcItemStorage
$PokemonGlobal.pcItemStorage = PCItemStorage.new
end
storage = $PokemonGlobal.pcItemStorage
@scene.pbStartScene(storage)
loop do
item = @scene.pbChooseItem
break if item==0
if pbIsImportantItem?(item)
@scene.pbDisplay(_INTL("That's too important to toss out!"))
next
end
qty = storage.pbQuantity(item)
itemname = PBItems.getName(item)
itemnameplural = PBItems.getNamePlural(item)
if qty>1
[email protected](_INTL("Toss out how many {1}?",itemnameplural),qty)
end
if qty>0
itemname = itemnameplural if qty>1
if pbConfirm(_INTL("Is it OK to throw away {1} {2}?",qty,itemname))
if !storage.pbDeleteItem(item,qty)
raise "Can't delete items from storage"
end
pbDisplay(_INTL("Threw away {1} {2}.",qty,itemname))
end
end
end
@scene.pbEndScene
end
end

Also My PItem_Bag...

#===============================================================================
# The Bag object, which actually contains all the items
#===============================================================================
class PokemonBag
attr_accessor :lastpocket
attr_reader :pockets

def self.pocketNames
return pbPocketNames
end

def self.numPockets
return self.pocketNames.length-1
end

def initialize
@lastpocket = 1
@pockets = []
@choices = []
for i in 0..PokemonBag.numPockets
@pockets = []
@choices = 0
end
@registeredItems = []
@registeredIndex = [0,0,1]
end

def rearrange
if (@pockets.length-1)!=PokemonBag.numPockets
newpockets = []
for i in 0..PokemonBag.numPockets
newpockets = []
@choices = 0 if !@choices
end
nump = PokemonBag.numPockets
for i in 0...[@pockets.length,nump].min
for item in @pockets
p = pbGetPocket(item[0])
newpockets[p].push(item)
end
end
@pockets = newpockets
end
end

def clear
for pocket in @pockets
pocket.clear
end
end

def pockets
rearrange
return @pockets
end

def maxPocketSize(pocket)
maxsize = MAXPOCKETSIZE[pocket]
return -1 if !maxsize
return maxsize
end

# Gets the index of the current selected item in the pocket
def getChoice(pocket)
if pocket<=0 || pocket>PokemonBag.numPockets
raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect))
end
rearrange
return [@choices[pocket],@pockets[pocket].length].min || 0
end

# Sets the index of the current selected item in the pocket
def setChoice(pocket,value)
if pocket<=0 || pocket>PokemonBag.numPockets
raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect))
end
rearrange
@choices[pocket] = value if value<=@pockets[pocket].length
end

def getAllChoices
ret = @choices.clone
for i in [email protected]; @choices = 0; end
return ret
end

def setAllChoices(choices)
@choices = choices
end

def pbQuantity(item)
if item.is_a?(String) || item.is_a?(Symbol)
item = getID(PBItems,item)
end
if !item || item<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
return 0
end
pocket = pbGetPocket(item)
maxsize = maxPocketSize(pocket)
maxsize = @pockets[pocket].length if maxsize<0
return ItemStorageHelper.pbQuantity(@pockets[pocket],maxsize,item)
end

def pbHasItem?(item)
return pbQuantity(item)>0
end

def pbCanStore?(item,qty=1)
if item.is_a?(String) || item.is_a?(Symbol)
item = getID(PBItems,item)
end
if !item || item<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
return false
end
pocket = pbGetPocket(item)
maxsize = maxPocketSize(pocket)
maxsize = @pockets[pocket].length+1 if maxsize<0
return ItemStorageHelper.pbCanStore?(@pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty)
end

def pbStoreAllOrNone(item,qty=1)
if item.is_a?(String) || item.is_a?(Symbol)
item = getID(PBItems,item)
end
if !item || item<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
return false
end
pocket = pbGetPocket(item)
maxsize = maxPocketSize(pocket)
maxsize = @pockets[pocket].length+1 if maxsize<0
return ItemStorageHelper.pbStoreAllOrNone(@pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty)
end

def pbStoreItem(item,qty=1)
if item.pbIsZCrystal?(item)
return true
end
if item.is_a?(String) || item.is_a?(Symbol)
item = getID(PBItems,item)
end
if !item || item<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
return false
end
pocket = pbGetPocket(item)
maxsize = maxPocketSize(pocket)
maxsize = @pockets[pocket].length+1 if maxsize<0
return ItemStorageHelper.pbStoreItem(@pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty,true)
end

def pbChangeItem(olditem,newitem)
if olditem.is_a?(String) || olditem.is_a?(Symbol)
olditem = getID(PBItems,olditem)
end
if newitem.is_a?(String) || newitem.is_a?(Symbol)
newitem = getID(PBItems,newitem)
end
if !olditem || olditem<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",olditem))
return false
elsif !newitem || newitem<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",newitem))
return false
end
pocket = pbGetPocket(olditem)
maxsize = maxPocketSize(pocket)
maxsize = @pockets[pocket].length if maxsize<0
ret = false
for i in 0...maxsize
itemslot = @pockets[pocket]
if itemslot && itemslot[0]==olditem
itemslot[0] = newitem
ret = true
end
end
return ret
end

def pbChangeQuantity(pocket,index,newqty=1)
return false if pocket<=0 || pocket>self.numPockets
return false if @pockets[pocket].length<index
newqty = [newqty,maxPocketSize(pocket)].min
@pockets[pocket][index][1] = newqty
return true
end

def pbDeleteItem(item,qty=1)
if item.is_a?(String) || item.is_a?(Symbol)
item = getID(PBItems,item)
end
if !item || item<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
return false
end
pocket = pbGetPocket(item)
maxsize = maxPocketSize(pocket)
maxsize = @pockets[pocket].length if maxsize<0
ret = ItemStorageHelper.pbDeleteItem(@pockets[pocket],maxsize,item,qty)
return ret
end

def registeredItems
@registeredItems = [] if !@registeredItems
if @registeredItem && @registeredItem>0 && [email protected]?(@registeredItem)
@registeredItems.push(@registeredItem)
@registeredItem = nil
end
return @registeredItems
end

def registeredItem; redisteredItems; end

def pbIsRegistered?(item)
registeredlist = self.registeredItems
return registeredlist.include?(item)
end

# Registers the item in the Ready Menu.
def pbRegisterItem(item)
if item.is_a?(String) || item.is_a?(Symbol)
item = getID(PBItems,item)
end
if !item || item<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
return
end
registeredlist = self.registeredItems
registeredlist.push(item) if !registeredlist.include?(item)
end

# Unregisters the item from the Ready Menu.
def pbUnregisterItem(item)
if item.is_a?(String) || item.is_a?(Symbol)
item = getID(PBItems,item)
end
if !item || item<1
raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
return
end
registeredlist = self.registeredItems
if registeredlist.include?(item)
for i in 0...registeredlist.length
if registeredlist==item
registeredlist = nil
break
end
end
registeredlist.compact!
end
end

def registeredIndex
@registeredIndex = [0,0,1] if !@registeredIndex
return @registeredIndex
end
end



#===============================================================================
# The PC item storage object, which actually contains all the items
#===============================================================================
class PCItemStorage
MAXSIZE = 50 # Number of different slots in storage
MAXPERSLOT = 999 # Max. number of items per slot

def initialize
@items = []
# Start storage with a Potion
if hasConst?(PBItems,:POTION)
pbStoreItem(getConst(PBItems,:POTION))
end
end

def [](i)
@items
end

def length
@items.length
end

def empty?
return @items.length==0
end

def clear
@items.clear
end

def getItem(index)
return (index<0 || index>[email protected]) ? 0 : @items[index][0]
end

def getCount(index)
return (index<0 || index>[email protected]) ? 0 : @items[index][1]
end

def pbQuantity(item)
return ItemStorageHelper.pbQuantity(@items,MAXSIZE,item)
end

def pbCanStore?(item,qty=1)
return ItemStorageHelper.pbCanStore?(@items,MAXSIZE,MAXPERSLOT,item,qty)
end

def pbStoreItem(item,qty=1)
return ItemStorageHelper.pbStoreItem(@items,MAXSIZE,MAXPERSLOT,item,qty)
end

def pbDeleteItem(item,qty=1)
return ItemStorageHelper.pbDeleteItem(@items,MAXSIZE,item,qty)
end
end



#===============================================================================
# Implements methods that act on arrays of items. Each element in an item
# array is itself an array of [itemID, itemCount].
# Used by the Bag, PC item storage, and Triple Triad.
#===============================================================================
module ItemStorageHelper
# Returns the quantity of the given item in the items array, maximum size per slot, and item ID
def self.pbQuantity(items,maxsize,item)
ret = 0
for i in 0...maxsize
itemslot = items
ret += itemslot[1] if itemslot && itemslot[0]==item
end
return ret
end

# Deletes an item from items array, maximum size per slot, item, and number of items to delete
def self.pbDeleteItem(items,maxsize,item,qty)
raise "Invalid value for qty: #{qty}" if qty<0
return true if qty==0
ret = false
for i in 0...maxsize
itemslot=items
if itemslot && itemslot[0]==item
amount = [qty,itemslot[1]].min
itemslot[1] -= amount
qty -= amount
items = nil if itemslot[1]==0
if qty==0
ret = true
break
end
end
end
items.compact!
return ret
end

def self.pbCanStore?(items,maxsize,maxPerSlot,item,qty)
raise "Invalid value for qty: #{qty}" if qty<0
return true if qty==0
for i in 0...maxsize
itemslot = items
if !itemslot
qty -= [qty,maxPerSlot].min
return true if qty==0
elsif itemslot[0]==item && itemslot[1]<maxPerSlot
newamt = itemslot[1]
newamt = [newamt+qty,maxPerSlot].min
qty -= (newamt-itemslot[1])
return true if qty==0
end
end
return false
end

def self.pbStoreItem(items,maxsize,maxPerSlot,item,qty,sorting=false)
raise "Invalid value for qty: #{qty}" if qty<0
return true if qty==0
for i in 0...maxsize
itemslot = items
if !itemslot
items = [item,[qty,maxPerSlot].min]
qty -= items[1]
if sorting
items.sort! if POCKETAUTOSORT[$ItemData[item][ITEMPOCKET]]
end
return true if qty==0
elsif itemslot[0]==item && itemslot[1]<maxPerSlot
newamt = itemslot[1]
newamt = [newamt+qty,maxPerSlot].min
qty -= (newamt-itemslot[1])
itemslot[1] = newamt
return true if qty==0
end
end
return false
end
end

I have no clue too, I think about trainer type not being there in the game, but being in the editor.
Also I tried Marin's PBS Editor, but that didn't work either...
 
4
Posts
4
Years
  • Age 35
  • Seen Apr 25, 2021
I would post the files so you see what happened but i don't have 5 posts...
 
Back
Top